Skip to content

Commit

Permalink
added ScriptOptionsTests for C# lang version
Browse files Browse the repository at this point in the history
  • Loading branch information
filipw committed Mar 4, 2019
1 parent 4fb1288 commit bf068e1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Scripting/CSharp/ScriptOptionsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ public static class ScriptOptionsExtensions
{
public static ScriptOptions WithLanguageVersion(this ScriptOptions options, LanguageVersion languageVersion)
{
if (options.ParseOptions is CSharpParseOptions csharpParseOptions && csharpParseOptions.LanguageVersion == languageVersion)
return options;

return options.WithParseOptions(new CSharpParseOptions(kind: SourceCodeKind.Script, languageVersion: languageVersion));
}
}
Expand Down
26 changes: 26 additions & 0 deletions src/Scripting/CSharpTest/ScriptOptionsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Scripting;
using Roslyn.Test.Utilities;
using Xunit;

namespace Microsoft.CodeAnalysis.Scripting.Test
{
public class ScriptOptionsTests : TestBase
{
[Fact]
public void WithLanguageVersion()
{
var options = ScriptOptions.Default.WithLanguageVersion(LanguageVersion.CSharp8);
Assert.Equal(LanguageVersion.CSharp8, ((CSharpParseOptions)options.ParseOptions).LanguageVersion);
}

[Fact]
public void WithEmitDebugInformation_SameValueTwice_DoesNotCreateNewInstance()
{
var options = ScriptOptions.Default.WithLanguageVersion(LanguageVersion.CSharp8);
Assert.Same(options, options.WithLanguageVersion(LanguageVersion.CSharp8));
}
}
}

0 comments on commit bf068e1

Please sign in to comment.