public void ParseCommandParameterStrings() { var parser = new SimpleParser("\"asdf asdf\" 1 []"); parser.Skip(1); Assert.AreEqual("asdf asdf", parser.ReadUntil('"')); parser.Skip(1); Assert.AreEqual("1", parser.ReadUntil(' ')); Assert.AreEqual("[]", parser.ReadUntil(' ')); }
public void ReadUntil1() { var p = new SimpleParser("rubbish<h1>A headline</h1>"); p.SkipUntil("<h1>"); Assert.AreEqual("A headline", p.ReadUntil("</h1>")); p.Position = 0; Assert.AreEqual("rubbish", p.ReadUntil("<h1>")); p.Position = 0; Assert.AreEqual("rubbish<h1>A headline</h1>", p.ReadUntil("<h2>")); p.Position = 0; Assert.AreEqual("rubbish<h1", p.ReadUntil(">")); Assert.AreEqual("A headline</h1", p.ReadUntil(">")); }
public void ReadUntil() { Assert.AreEqual("", new SimpleParser("abcabc").ReadUntil('a')); Assert.AreEqual("a", new SimpleParser("abcabc").ReadUntil('b')); Assert.AreEqual("ab", new SimpleParser("abcabc").ReadUntil('c')); Assert.AreEqual("abcabc", new SimpleParser("abcabc").ReadUntil('d')); Assert.AreEqual("", new SimpleParser("").ReadUntil('d')); var p = new SimpleParser("abc.def ghi"); Assert.AreEqual('\0', p.LastChar); Assert.AreEqual('a', p.NextChar.Value); Assert.AreEqual("abc", p.ReadUntil('.', ' ')); Assert.AreEqual('.', p.LastChar); Assert.AreEqual('d', p.NextChar.Value); Assert.AreEqual("def", p.ReadUntil('.', ' ')); Assert.AreEqual(' ', p.LastChar); Assert.IsTrue(p.HasNext); Assert.AreEqual("ghi", p.ReadUntil()); Assert.AreEqual('i', p.LastChar); Assert.IsNull(p.NextChar); Assert.IsFalse(p.HasNext); }
public void NextIs() { var parser = new SimpleParser("<asdf/>"); Assert.IsFalse(parser.NextIs("asdf")); Assert.IsTrue(parser.NextIs('<')); Assert.AreEqual(0, parser.Position); Assert.IsTrue(parser.NextIs("<asdf/>")); Assert.AreEqual(0, parser.Position); Assert.IsTrue(parser.NextIs('<')); parser.ReadUntil('/'); parser.Unskip(1); Assert.IsTrue(parser.NextIs('/')); Assert.IsFalse(parser.NextIs("asdf")); Assert.IsTrue(parser.NextIs('/')); Assert.IsTrue(parser.NextIs("/>")); Assert.IsTrue(parser.NextIs('/')); }