未验证 提交 931fdf92 编写于 作者: F filipw

applied review feedback

上级 5fbe48ba
......@@ -178,7 +178,7 @@ private int RunScript(ScriptOptions options, string code, ErrorLogger errorLogge
var globals = new CommandLineScriptGlobals(_console.Out, _objectFormatter);
globals.Args.AddRange(_compiler.Arguments.ScriptArguments);
var script = Script.CreateInitialScript<int>(_scriptCompiler, SourceText.From(code ?? string.Empty), options, globals.GetType(), assemblyLoaderOpt: null);
var script = Script.CreateInitialScript<int>(_scriptCompiler, SourceText.From(code), options, globals.GetType(), assemblyLoaderOpt: null);
try
{
return script.RunAsync(globals, cancellationToken).Result.ReturnValue;
......@@ -199,7 +199,7 @@ private void RunInteractiveLoop(ScriptOptions options, string initialScriptCodeO
if (initialScriptCodeOpt != null)
{
var script = Script.CreateInitialScript<object>(_scriptCompiler, SourceText.From(initialScriptCodeOpt ?? string.Empty), options, globals.GetType(), assemblyLoaderOpt: null);
var script = Script.CreateInitialScript<object>(_scriptCompiler, SourceText.From(initialScriptCodeOpt), options, globals.GetType(), assemblyLoaderOpt: null);
BuildAndRun(script, globals, ref state, ref options, displayResult: false, cancellationToken: cancellationToken);
}
......
......@@ -105,16 +105,23 @@ internal static Script<T> CreateInitialScript<T>(ScriptCompiler compiler, Source
/// <summary>
/// Continues the script with given code snippet.
/// </summary>
public Script<TResult> ContinueWith<TResult>(string code, ScriptOptions options = null) =>
new Script<TResult>(Compiler, Builder, SourceText.From(code ?? "", options?.FileEncoding ?? Options.FileEncoding), options ?? InheritOptions(Options), GlobalsType, this);
public Script<TResult> ContinueWith<TResult>(string code, ScriptOptions options = null)
{
options = options ?? InheritOptions(Options);
return new Script<TResult>(Compiler, Builder, SourceText.From(code ?? "", options.FileEncoding), options, GlobalsType, this);
}
/// <summary>
/// Continues the script with given <see cref="Stream"/> representing code.
/// </summary>
/// <exception cref="ArgumentNullException">Stream is null.</exception>
/// <exception cref="ArgumentException">Stream is not readable or seekable.</exception>
public Script<TResult> ContinueWith<TResult>(Stream code, ScriptOptions options = null) =>
new Script<TResult>(Compiler, Builder, SourceText.From(code, options?.FileEncoding ?? Options.FileEncoding), options ?? InheritOptions(Options), GlobalsType, this);
public Script<TResult> ContinueWith<TResult>(Stream code, ScriptOptions options = null)
{
if (code == null) throw new ArgumentNullException(nameof(code));
options = options ?? InheritOptions(Options);
return new Script<TResult>(Compiler, Builder, SourceText.From(code, options.FileEncoding), options, GlobalsType, this);
}
private static ScriptOptions InheritOptions(ScriptOptions previous)
{
......
......@@ -100,7 +100,8 @@ private static ImmutableArray<MetadataReference> GetDefaultMetadataReferences()
public bool EmitDebugInformation { get; private set; } = false;
/// <summary>
/// Specifies the encoding to be used when debugging scripts loaded from a file, or that will be saved to a file for debugging purposes.
/// Specifies the encoding to be used when debugging scripts loaded from a file, or saved to a file for debugging purposes.
/// If it's null, the compiler will attempt to detect the necessary encoding for debugging
/// </summary>
public Encoding FileEncoding { get; private set; }
......
......@@ -151,13 +151,12 @@ public void WithImports_Errors()
options.WithImports(".blah");
}
[Theory]
[InlineData(true)]
[InlineData(false)]
public void WithEmitDebugInformation_SetsEmitDebugInformation(bool emitDebugInformation)
[Fact]
public void WithEmitDebugInformation_SetsEmitDebugInformation()
{
var options = ScriptOptions.Default.WithEmitDebugInformation(emitDebugInformation);
Assert.Equal(emitDebugInformation, options.EmitDebugInformation);
Assert.True(ScriptOptions.Default.WithEmitDebugInformation(true).EmitDebugInformation);
Assert.False(ScriptOptions.Default.WithEmitDebugInformation(false).EmitDebugInformation);
Assert.False(ScriptOptions.Default.EmitDebugInformation);
}
[Fact]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册