public void TestLoadCommandBlockPythonStyle() { Mockery mockery = new Mockery(); IProjectSerializer mockSerializer = mockery.NewMock<IProjectSerializer>(); using (mockery.Ordered) { Expect.Once.On(mockSerializer).GetProperty("Position").Will(Return.Value(0)); Expect.Once.On(mockSerializer).Method("ReadLineBreakToken").Will(Return.Value(new Token(TokenType.LineBreak, "\r\n", 0, 2))); Expect.Once.On(mockSerializer).Method("ReadIndentationToken").Will(Return.Value(new Token(TokenType.LineBreak, "\t\t", 2, 2))); Expect.Once.On(mockSerializer).Method("GetIndentationLevel").Will(Return.Value(2)); Expect.Once.On(mockSerializer).Method("ReadBlockStarterToken").Will(Return.Value(null)); Expect.Once.On(mockSerializer).GetProperty("LastIndentationLevel").Will(Return.Value(0)); Expect.Once.On(mockSerializer).GetProperty("Done").Will(Return.Value(false)); Expect.Once.On(mockSerializer).Method("GetIndentationLevel").Will(Return.Value(2)); Expect.Once.On(mockSerializer).Method("ReadTextToken").Will(Return.Value(new Token(TokenType.Text, "token", 4, 5))); Expect.Once.On(mockSerializer).GetProperty("LineNumber").Will(Return.Value(3)); Expect.Once.On(mockSerializer).Method("ReadTextToken").Will(Return.Value(new Token(TokenType.Text, "consonants", 9, 10))); Expect.Once.On(mockSerializer).Method("ReadTextToken").Will(Return.Value(null)); Expect.Once.On(mockSerializer).Method("ReadLineBreakToken").Will(Return.Value(new Token(TokenType.LineBreak, "\r\n", 19, 2))); Expect.Once.On(mockSerializer).GetProperty("Done").Will(Return.Value(false)); Expect.Once.On(mockSerializer).Method("ReadIndentationToken").Will(Return.Value(new Token(TokenType.Indentation, "\t\t", 21, 2))); Expect.Once.On(mockSerializer).Method("GetIndentationLevel").Will(Return.Value(2)); Expect.Once.On(mockSerializer).Method("ReadTextToken").Will(Return.Value(new Token(TokenType.Command, "rule", 23, 4))); Expect.Once.On(mockSerializer).GetProperty("LineNumber").Will(Return.Value(3)); Expect.Once.On(mockSerializer).Method("ReadTextToken").Will(Return.Value(new Token(TokenType.Text, "second", 27, 6))); Expect.Once.On(mockSerializer).Method("ReadTextToken").Will(Return.Value(null)); Expect.Once.On(mockSerializer).Method("ReadLineBreakToken").Will(Return.Value(new Token(TokenType.LineBreak, "\r\n", 19, 2))); Expect.Once.On(mockSerializer).GetProperty("Done").Will(Return.Value(false)); Expect.Once.On(mockSerializer).Method("ReadIndentationToken").Will(Return.Value(new Token(TokenType.Indentation, "\t", 33, 1))); Expect.Once.On(mockSerializer).Method("GetIndentationLevel").Will(Return.Value(1)); Expect.Once.On(mockSerializer).Method("RollBackToken"); } CommandBlockNode cbn = new CommandBlockNode(mockSerializer); Assert.AreEqual(2, cbn.Commands.Count); mockery.VerifyAllExpectationsHaveBeenMet(); }
public void TestLoadCommandBlockWBStyle() { Mockery mockery = new Mockery(); IProjectSerializer mockSerializer = mockery.NewMock<IProjectSerializer>(); using (mockery.Ordered) { Expect.Once.On(mockSerializer).GetProperty("Position").Will(Return.Value(0)); Expect.Once.On(mockSerializer).Method("ReadLineBreakToken").Will(Return.Value(null)); Expect.Once.On(mockSerializer).Method("ReadBlockStarterToken").Will(Return.Value(new Token(TokenType.BlockStarter, "{", 3, 1))); Expect.Once.On(mockSerializer).Method("ReadLineBreakToken").Will(Return.Value(new Token(TokenType.LineBreak, "\r\n", 4, 2))); Expect.Once.On(mockSerializer).Method("ReadBlockEnderToken").Will(Return.Value(null)); Expect.Once.On(mockSerializer).GetProperty("Done").Will(Return.Value(false)); Expect.Once.On(mockSerializer).Method("ReadIndentationToken").Will(Return.Value(new Token(TokenType.Indentation, "\t", 6, 1))); Expect.Once.On(mockSerializer).Method("ReadBlockEnderToken").Will(Return.Value(null)); Expect.Once.On(mockSerializer).GetProperty("Done").Will(Return.Value(false)); Expect.Once.On(mockSerializer).Method("ReadTextToken").Will(Return.Value(new Token(TokenType.Text, "token", 7, 5))); Expect.Once.On(mockSerializer).GetProperty("LineNumber").Will(Return.Value(3)); Expect.Once.On(mockSerializer).Method("ReadTextToken").Will(Return.Value(new Token(TokenType.Text, "consonants", 12, 10))); Expect.Once.On(mockSerializer).Method("ReadTextToken").Will(Return.Value(null)); Expect.Once.On(mockSerializer).Method("ReadLineBreakToken").Will(Return.Value(new Token(TokenType.LineBreak, "\r\n", 22, 2))); Expect.Once.On(mockSerializer).Method("ReadBlockEnderToken").Will(Return.Value(null)); Expect.Once.On(mockSerializer).GetProperty("Done").Will(Return.Value(false)); Expect.Once.On(mockSerializer).Method("ReadIndentationToken").Will(Return.Value(new Token(TokenType.Indentation, "\t", 24, 1))); Expect.Once.On(mockSerializer).Method("ReadBlockEnderToken").Will(Return.Value(null)); Expect.Once.On(mockSerializer).GetProperty("Done").Will(Return.Value(false)); Expect.Once.On(mockSerializer).Method("ReadTextToken").Will(Return.Value(new Token(TokenType.Command, "rule", 25, 4))); Expect.Once.On(mockSerializer).GetProperty("LineNumber").Will(Return.Value(3)); Expect.Once.On(mockSerializer).Method("ReadTextToken").Will(Return.Value(new Token(TokenType.Text, "second", 29, 6))); Expect.Once.On(mockSerializer).Method("ReadTextToken").Will(Return.Value(null)); Expect.Once.On(mockSerializer).Method("ReadLineBreakToken").Will(Return.Value(new Token(TokenType.LineBreak, "\r\n", 35, 2))); Expect.Once.On(mockSerializer).Method("ReadBlockEnderToken").Will(Return.Value(null)); Expect.Once.On(mockSerializer).GetProperty("Done").Will(Return.Value(false)); Expect.Once.On(mockSerializer).Method("ReadIndentationToken").Will(Return.Value(new Token(TokenType.Indentation, "\t", 37, 1))); Expect.Once.On(mockSerializer).Method("ReadBlockEnderToken").Will(Return.Value(null)); Expect.Once.On(mockSerializer).GetProperty("Done").Will(Return.Value(false)); Expect.Once.On(mockSerializer).Method("ReadTextToken").Will(Return.Value(null)); Expect.Once.On(mockSerializer).Method("ReadLineBreakToken").Will(Return.Value(new Token(TokenType.LineBreak, "\r\n", 38, 2))); Expect.Once.On(mockSerializer).Method("ReadBlockEnderToken").Will(Return.Value(new Token(TokenType.BlockEnder, "}", 40, 1))); } CommandBlockNode cbn = new CommandBlockNode(mockSerializer); Assert.AreEqual(2, cbn.Commands.Count); mockery.VerifyAllExpectationsHaveBeenMet(); }
public override void LoadCommand(Whee.WordBuilder.ProjectV2.IProjectSerializer serializer) { double num = 0; bool found = true; Token amount = null; while (found) { amount = serializer.ReadNumericToken(this, ref num, out found); if (amount != null) { _Repetitions.Add((int)num); } if (amount == null && found) { int reps = 0; string data; amount = serializer.ReadRepeatingToken(this, out reps, out data); if (amount != null) { List<int> numbers = new List<int>(); foreach (string numstring in data.Split(' ')) { int number = 0; if (int.TryParse(numstring, out number)) { numbers.Add(number); } else { serializer.Warn("Expected numbers only", this); } } for (int i = 0; i < reps; i++) { _Repetitions.AddRange(numbers); } } else { found = false; } } } CommandBlockNode cbn = new CommandBlockNode(serializer); Children.Add(cbn); foreach (CommandBase cmd in cbn.Commands) { Commands.Add(cmd); } }