本文整理汇总了C#中Interpreter.SetReader方法的典型用法代码示例。如果您正苦于以下问题:C# Interpreter.SetReader方法的具体用法?C# Interpreter.SetReader怎么用?C# Interpreter.SetReader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Interpreter
的用法示例。
在下文中一共展示了Interpreter.SetReader方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadIntWorks
public void ReadIntWorks()
{
var bytecode = new List<byte>();
bytecode.Add(Bytecode.READ_INT);
bytecode.AddRange(BitConverter.GetBytes(4));
bytecode.Add(Bytecode.READ_INT);
bytecode.AddRange(BitConverter.GetBytes(1));
bytecode.Add(Bytecode.READ_INT);
bytecode.AddRange(BitConverter.GetBytes(2));
var input = new List<string> { "4", "9", "12345" };
int pos = 0;
var interpreter = new Interpreter(bytecode.ToArray(), new List<string> {}, null, 5);
interpreter.SetReader(() => input[pos++]);
interpreter.Run();
Assert.AreEqual(0, interpreter.Stack.Count);
Assert.AreEqual(15, interpreter.PC);
Assert.AreEqual(4, interpreter.Variables[4]);
Assert.AreEqual(9, interpreter.Variables[1]);
Assert.AreEqual(12345, interpreter.Variables[2]);
}
示例2: ReadStringWorks
public void ReadStringWorks()
{
var bytecode = new List<byte>();
bytecode.Add(Bytecode.READ_STRING);
bytecode.AddRange(BitConverter.GetBytes(4));
bytecode.Add(Bytecode.READ_STRING);
bytecode.AddRange(BitConverter.GetBytes(1));
bytecode.Add(Bytecode.READ_STRING);
bytecode.AddRange(BitConverter.GetBytes(2));
var input = new List<string> { "abc112", "hello", "abababababa" };
int pos = 0;
var interpreter = new Interpreter(bytecode.ToArray(), new List<string> { "hello", "world" }, null, 5);
interpreter.SetReader(() => input[pos++]);
interpreter.Run();
Assert.AreEqual(0, interpreter.Stack.Count);
Assert.AreEqual(15, interpreter.PC);
Assert.AreEqual(2, interpreter.Variables[4]);
Assert.AreEqual(0, interpreter.Variables[1]);
Assert.AreEqual(3, interpreter.Variables[2]);
Assert.AreEqual("abc112", interpreter.Strings[2]);
Assert.AreEqual("abababababa", interpreter.Strings[3]);
}
示例3: ReadIntThrowsIfInputIsNotNumeric
public void ReadIntThrowsIfInputIsNotNumeric()
{
var bytecode = new List<byte>();
bytecode.Add(Bytecode.READ_INT);
bytecode.AddRange(BitConverter.GetBytes(4));
bytecode.Add(Bytecode.READ_INT);
bytecode.AddRange(BitConverter.GetBytes(1));
bytecode.Add(Bytecode.READ_INT);
bytecode.AddRange(BitConverter.GetBytes(2));
var input = new List<string> { "abcdef", };
int pos = 0;
var interpreter = new Interpreter(bytecode.ToArray(), new List<string> { }, null, 5);
interpreter.SetReader(() => input[pos++]);
interpreter.Stack.Push(4);
interpreter.Stack.Push(1);
interpreter.Stack.Push(2);
interpreter.Run();
}