public void CommentEofTest(string src) { var lexer = new Lexer(src); var token = lexer.Read(null); SigoAssert.Equal(Kind.Eof, token.Kind); }
public void NumberTest(string src, double value) { var lexer = new Lexer(src); var token = lexer.Read(null); SigoAssert.Equal(value, token.Value); }
public void ItCanPeekInMinMax() { for (var i = 0; i <= 5; i++) { // delta out of range SigoAssert.ThrowsAny <ArgumentOutOfRangeException>(() => lexer.Peek(-2)); SigoAssert.ThrowsAny <ArgumentOutOfRangeException>(() => lexer.Peek(3)); for (var d = lexer.Max; d >= lexer.Min; d--) { if (i + d < 0) { // negative position SigoAssert.ThrowsAny <Exception>(() => lexer.Peek(d)); } else if (i + d > 5) { // multiple eofs SigoAssert.Equal(Kind.Eof, lexer.Peek(d).Kind); } else { // return the token SigoAssert.Equal((i + d).ToString(), lexer.Peek(d).Raw); } } lexer.Move(1); } }
public void Associative() { var a = Sigo.Create(1, "a/x", "ax", "a/y", "ay", "b", "b" ); // add "/a/z": az var b = Sigo.Create(0, "a/z", "az"); // change "/b": "b+" var c = Sigo.Create(0, "b", "b+"); var abc1 = Sigo.Merge(Sigo.Merge(a, b), c); var abc2 = Sigo.Merge(a, Sigo.Merge(b, c)); var expect = Sigo.Create(3, "a/x", "ax", "a/y", "ay", "a/z", "az", "b", "b+" ); SigoAssert.Equal(abc1, abc2); SigoAssert.Equal(expect, abc2); }
public void SeparatorTest(string src, int start, int sep) { var lexer = new Lexer(src); var token = lexer.Read(null); SigoAssert.Equal(src, token.Src); SigoAssert.Equal(start, token.Start); SigoAssert.Equal(sep, token.Separator); }
public void CommentTest(string src) { var lexer = new Lexer(src + 1); var token = lexer.Read(null); SigoAssert.Equal(Kind.Number, token.Kind); SigoAssert.Equal(src.Length, token.Start); SigoAssert.Equal("1", token.Raw); }
public void Object_separatorTests(string src) { string Clean(string src) { src = src .Replace(' ', ',') .Replace(';', ',') .Replace("}", ",}"); src = src.Replace(",,", ",").Replace(",,", ","); return(src); } SigoAssert.Equal(Sigo.Parse(Clean(src)), Sigo.Parse(src)); }
public void Try_to_return_part_of_a() { var a = Sigo.Create(7, "x/name", "Phat" ).Freeze(); var b = Sigo.Create(7, "x/name", "Phat", "y", "y" ).Freeze(); var r = ImplMergeSpec.Merge(a, b); // r equal b... SigoAssert.Equal(r, b); // ...but not same b... SigoAssert.NotSame(r, b); // ...because there is r[x] == a[x] SigoAssert.Equal(r["x"], a["x"]); SigoAssert.Same(r["x"], a["x"]); }
public void PropertiesTest() { SigoAssert.Equal(-1, lexer.Min); SigoAssert.Equal(2, lexer.Max); SigoAssert.Equal(0, lexer.Cursor); lexer.Move(2); SigoAssert.Equal(2, lexer.Cursor); SigoAssert.Equal("2", lexer.Peek(0).Raw); lexer.Move(2); SigoAssert.Equal(4, lexer.Cursor); SigoAssert.Equal("4", lexer.Peek(0).Raw); lexer.Peek(lexer.Max); // after peek max, you can Move min, but not min-1 lexer.Move(-1); SigoAssert.Equal(3, lexer.Cursor); SigoAssert.Equal("3", lexer.Peek(0).Raw); SigoAssert.ThrowsAny <Exception>(() => lexer.Peek(-1)); // after move(-1) you have limitation SigoAssert.ThrowsAny <Exception>(() => lexer.Move(-1)); }
public void TokenTest(Kind kind, string src, int start, int end) { var lexer = new Lexer(src); var token = lexer.Read(null); SigoAssert.Equal(kind, token.Kind); SigoAssert.Equal(start, token.Start); SigoAssert.Equal(end, token.End); switch (kind) { case Kind.Number: SigoAssert.Equal(double.Parse(src.Substring(start, end - start)), token.Value); break; case Kind.String: SigoAssert.Equal(src.Substring(start + 1, end - start - 2), token.Value); break; default: SigoAssert.Null(token.Value); break; } }
public void Object_emptyTests(SigoWraper wraper) { SigoAssert.Equal(wraper.Sigo, Sigo.Parse(wraper.ToString())); }
public void Leaf_stringQuoteTests(string src, string value) { SigoAssert.Equal(Sigo.From(value), Sigo.Parse(src)); }
public void Leaf_boolTests(string src, bool value) { SigoAssert.Equal(Sigo.From(value), Sigo.Parse(src)); }
public void TODO_PathAsString(string src, string expect) { SigoAssert.Equal(Sigo.Parse(expect), Sigo.Parse(src)); }
public void Leaf_numberTests(string src) { var num = double.Parse(src, CultureInfo.InvariantCulture); SigoAssert.Equal(Sigo.From(num), Sigo.Parse(src)); }
public void TODO_ContextTest(string a, string b) { SigoAssert.Equal(Sigo.Parse(a), Sigo.Parse(b)); }
public void TODO_ArrayTest(string src, string expect) { SigoAssert.Equal(Sigo.Parse(expect), Sigo.Parse(src)); }
public void Object_pathTest() { var expected = Sigo.Create(3, "name", Sigo.Create(3, "first", 1, "last", 2)); SigoAssert.Equal(expected, Sigo.Parse("{name/first:1, name/last:2}")); }
public void ItCanMove() { lexer.Move(5); SigoAssert.Equal("5", lexer.Peek(0).Raw); }