本文整理汇总了C#中Interpreter.SetPrinter方法的典型用法代码示例。如果您正苦于以下问题:C# Interpreter.SetPrinter方法的具体用法?C# Interpreter.SetPrinter怎么用?C# Interpreter.SetPrinter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Interpreter
的用法示例。
在下文中一共展示了Interpreter.SetPrinter方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AssertDoesNothingIfAssertSucceeds
public void AssertDoesNothingIfAssertSucceeds()
{
var bytecode = new List<byte>();
bytecode.Add(Bytecode.ASSERT);
bytecode.AddRange(BitConverter.GetBytes(1));
var interpreter = new Interpreter(
bytecode.ToArray(),
new List<string> { "hello", "world" },
new List<string> { "line 1", "line 2" },
0);
interpreter.Stack.Push(1);
var output = new List<string>();
interpreter.SetPrinter((string str) => output.Add(str));
interpreter.Run();
Assert.AreEqual(0, interpreter.Stack.Count);
Assert.AreEqual(5, interpreter.PC);
Assert.AreEqual(0, output.Count);
}
示例2: PrintIntWorks
public void PrintIntWorks()
{
var bytecode = new List<byte>();
bytecode.Add(Bytecode.PUSH_INT);
bytecode.AddRange(BitConverter.GetBytes(23L));
bytecode.Add(Bytecode.PRINT_INT);
var interpreter = new Interpreter(bytecode.ToArray(), new List<string> { "" }, null, 0);
var output = new List<string>();
interpreter.SetPrinter((string str) => output.Add(str));
interpreter.Run();
Assert.AreEqual(0, interpreter.Stack.Count);
Assert.AreEqual(10, interpreter.PC);
Assert.AreEqual(1, output.Count);
Assert.AreEqual("23", output[0]);
}
示例3: PrintStringWorks
public void PrintStringWorks()
{
var bytecode = new List<byte>();
bytecode.Add(Bytecode.PUSH_STRING);
bytecode.AddRange(BitConverter.GetBytes(1));
bytecode.Add(Bytecode.PRINT_STRING);
var interpreter = new Interpreter(bytecode.ToArray(), new List<string> { "hello", "world" }, null, 0);
var output = new List<string>();
interpreter.SetPrinter((string str) => output.Add(str));
interpreter.Run();
Assert.AreEqual(0, interpreter.Stack.Count);
Assert.AreEqual(6, interpreter.PC);
Assert.AreEqual(1, output.Count);
Assert.AreEqual("world", output[0]);
}
示例4: AssertPrintsDiagnosticMessageIfAssertFails
public void AssertPrintsDiagnosticMessageIfAssertFails()
{
var bytecode = new List<byte>();
bytecode.Add(Bytecode.ASSERT);
bytecode.AddRange(BitConverter.GetBytes(1));
var interpreter = new Interpreter(
bytecode.ToArray(),
new List<string> { "hello", "world" },
new List<string> { "line 1", "line 2" },
0);
interpreter.Stack.Push(0);
var output = new List<string>();
interpreter.SetPrinter((string str) => output.Add(str));
interpreter.Run();
Assert.AreEqual(0, interpreter.Stack.Count);
Assert.AreEqual(5, interpreter.PC);
Assert.AreEqual(2, output.Count);
Assert.AreEqual("Assert failed at line 2", output[0]);
Assert.AreEqual("\n\tline 2", output[1]);
}