public void TestIndentationLevelVerification() { Mockery mockery = new Mockery(); IProjectNode pn = mockery.NewMock<IProjectNode>(); ProjectSerializer ps = new ProjectSerializer("\tged\r\n\t hest \r\n\tnejj\r\n", null, null); ps.SpacesIndent = 2; Token t = ps.ReadIndentationToken(pn); Assert.AreEqual(TokenType.Indentation, t.Type); Assert.AreEqual("\t", t.Text); t = ps.ReadTextToken(pn); Assert.AreEqual(TokenType.Text, t.Type); Assert.AreEqual("ged", t.Text); t = ps.ReadLineBreakToken(pn); t = ps.ReadIndentationToken(pn); Assert.AreEqual(TokenType.Indentation, t.Type); Assert.AreEqual("\t ", t.Text); Assert.AreEqual(2, ps.GetIndentationLevel(t.Text)); t = ps.ReadTextToken(pn); Assert.AreEqual(TokenType.Text, t.Type); Assert.AreEqual("hest", t.Text); t = ps.ReadLineBreakToken(pn); t = ps.ReadIndentationToken(pn); Assert.AreEqual(TokenType.Indentation, t.Type); Assert.AreEqual("\t", t.Text); Assert.AreEqual(1, ps.GetIndentationLevel(t.Text)); ps.RollBackToken(t); t = ps.ReadIndentationToken(pn); Assert.AreEqual(TokenType.Indentation, t.Type); Assert.AreEqual("\t", t.Text); Assert.AreEqual(1, ps.GetIndentationLevel(t.Text)); }
public void TestLineNumber() { Mockery mockery = new Mockery(); IProjectNode pn = mockery.NewMock<IProjectNode>(); ProjectSerializer ps = new ProjectSerializer("a\r\nb;\n\nc", null, null); Token t = ps.ReadTextToken(pn); Assert.AreEqual(1, t.LineNumber); Token newLine = ps.ReadLineBreakToken(pn); t = ps.ReadTextToken(pn); Assert.AreEqual(2, t.LineNumber); newLine = ps.ReadLineBreakToken(pn); t = ps.ReadTextToken(pn); Assert.AreEqual(4, t.LineNumber); }
public void TestReadTextToken() { Mockery mockery = new Mockery(); IProjectNode pn = mockery.NewMock<IProjectNode>(); ProjectSerializer ps = new ProjectSerializer("a \"b\" c\"d \"e\\\"f\" g \"h i\"", null, null); Token t = ps.ReadTextToken(pn); Assert.AreEqual(0, t.Offset); Assert.AreEqual(1, t.Length); Assert.AreEqual("a", t.Text); t = ps.ReadTextToken(pn); Assert.AreEqual(2, t.Offset); Assert.AreEqual(3, t.Length); Assert.AreEqual("b", t.Text); t = ps.ReadTextToken(pn); Assert.AreEqual(6, t.Offset); Assert.AreEqual(3, t.Length); Assert.AreEqual("c\"d", t.Text); t = ps.ReadTextToken(pn); Assert.AreEqual(10, t.Offset); Assert.AreEqual(6, t.Length); Assert.AreEqual("e\"f", t.Text); t = ps.ReadTextToken(pn); Assert.AreEqual(17, t.Offset); Assert.AreEqual(1, t.Length); Assert.AreEqual("g", t.Text); t = ps.ReadTextToken(pn); Assert.AreEqual(19, t.Offset); Assert.AreEqual(5, t.Length); Assert.AreEqual("h i", t.Text); }