public void ConsumeToEnd() { string @in = "one two three"; CharacterReader r = new CharacterReader(@in); string toEnd = r.ConsumeToEnd(); Assert.AreEqual(@in, toEnd); Assert.IsTrue(r.IsEmpty()); }
public void Mark() { CharacterReader r = new CharacterReader("one"); r.Consume(); r.Mark(); Assert.AreEqual('n', r.Consume()); Assert.AreEqual('e', r.Consume()); Assert.IsTrue(r.IsEmpty()); r.RewindToMark(); Assert.AreEqual('n', r.Consume()); }
// current doc we are building into // the stack of open elements // current base uri, for creating new elements // currentToken is used only for error tracking. // null when not tracking errors internal virtual void InitialiseParse(string input, string baseUri, ParseErrorList errors) { Validate.NotNull(input, "String input must not be null"); Validate.NotNull(baseUri, "BaseURI must not be null"); doc = new Document(baseUri); reader = new CharacterReader(input); this.errors = errors; tokeniser = new Tokeniser(reader, errors); stack = new DescendableLinkedList<Element>(); this.baseUri = baseUri; }
// current doc we are building into // the stack of open elements // current base uri, for creating new elements // currentToken is used only for error tracking. // null when not tracking errors internal virtual void InitialiseParse(string input, string baseUri, ParseErrorList errors) { Validate.NotNull(input, "String input must not be null"); Validate.NotNull(baseUri, "BaseURI must not be null"); doc = new Document(baseUri); reader = new CharacterReader(input); this.errors = errors; tokeniser = new Tokeniser(reader, errors); stack = new DescendableLinkedList <Element>(); this.baseUri = baseUri; }
public void NextIndexOfChar() { string @in = "blah blah"; CharacterReader r = new CharacterReader(@in); Assert.AreEqual(-1, r.NextIndexOf('x')); Assert.AreEqual(3, r.NextIndexOf('h')); string pull = r.ConsumeTo('h'); Assert.AreEqual("bla", pull); r.Consume(); Assert.AreEqual(2, r.NextIndexOf('l')); Assert.AreEqual(" blah", r.ConsumeToEnd()); Assert.AreEqual(-1, r.NextIndexOf('x')); }
internal Tokeniser(CharacterReader reader, ParseErrorList errors) { // replaces null character // html input // errors found while tokenising // current tokenisation state // the token we are about to emit on next read // buffers characters to output as one token // buffers data looking for </script> // tag we are building up // doctype building up // comment building up // the last start tag emitted, to test appropriate end tag this.reader = reader; this.errors = errors; }
public void Consume() { CharacterReader r = new CharacterReader("one"); Assert.AreEqual(0, r.Pos()); Assert.AreEqual('o', r.Current()); Assert.AreEqual('o', r.Consume()); Assert.AreEqual(1, r.Pos()); Assert.AreEqual('n', r.Current()); Assert.AreEqual(1, r.Pos()); Assert.AreEqual('n', r.Consume()); Assert.AreEqual('e', r.Consume()); Assert.IsTrue(r.IsEmpty()); Assert.AreEqual(CharacterReader.EOF, r.Consume()); Assert.IsTrue(r.IsEmpty()); Assert.AreEqual(CharacterReader.EOF, r.Consume()); }
public void Unconsume() { CharacterReader r = new CharacterReader("one"); Assert.AreEqual('o', r.Consume()); Assert.AreEqual('n', r.Current()); r.Unconsume(); Assert.AreEqual('o', r.Current()); Assert.AreEqual('o', r.Consume()); Assert.AreEqual('n', r.Consume()); Assert.AreEqual('e', r.Consume()); Assert.IsTrue(r.IsEmpty()); r.Unconsume(); Assert.IsFalse(r.IsEmpty()); Assert.AreEqual('e', r.Current()); Assert.AreEqual('e', r.Consume()); Assert.IsTrue(r.IsEmpty()); Assert.AreEqual(CharacterReader.EOF, r.Consume()); r.Unconsume(); Assert.IsTrue(r.IsEmpty()); Assert.AreEqual(CharacterReader.EOF, r.Current()); }
public void MatchesIgnoreCase() { CharacterReader r = new CharacterReader("One Two Three"); Assert.IsTrue(r.MatchesIgnoreCase("O")); Assert.IsTrue(r.MatchesIgnoreCase("o")); Assert.IsTrue(r.Matches('O')); Assert.IsFalse(r.Matches('o')); Assert.IsTrue(r.MatchesIgnoreCase("One Two Three")); Assert.IsTrue(r.MatchesIgnoreCase("ONE two THREE")); Assert.IsTrue(r.MatchesIgnoreCase("One")); Assert.IsTrue(r.MatchesIgnoreCase("one")); Assert.AreEqual('O', r.Consume()); Assert.IsFalse(r.MatchesIgnoreCase("One")); Assert.IsTrue(r.MatchesIgnoreCase("NE Two Three")); Assert.IsFalse(r.MatchesIgnoreCase("ne Two Three Four")); Assert.AreEqual("ne Two Three", r.ConsumeToEnd()); Assert.IsFalse(r.MatchesIgnoreCase("ne")); }
public void NextIndexOfUnmatched() { CharacterReader r = new CharacterReader("<[[one]]"); Assert.AreEqual(-1, r.NextIndexOf("]]>")); }
public void NextIndexOfString() { string @in = "One Two something Two Three Four"; CharacterReader r = new CharacterReader(@in); Assert.AreEqual(-1, r.NextIndexOf("Foo")); Assert.AreEqual(4, r.NextIndexOf("Two")); Assert.AreEqual("One Two ", r.ConsumeTo("something")); Assert.AreEqual(10, r.NextIndexOf("Two")); Assert.AreEqual("something Two Three Four", r.ConsumeToEnd()); Assert.AreEqual(-1, r.NextIndexOf("Two")); }
public void ConsumeToChar() { CharacterReader r = new CharacterReader("One Two Three"); Assert.AreEqual("One ", r.ConsumeTo('T')); Assert.AreEqual("", r.ConsumeTo('T')); // on Two Assert.AreEqual('T', r.Consume()); Assert.AreEqual("wo ", r.ConsumeTo('T')); Assert.AreEqual('T', r.Consume()); Assert.AreEqual("hree", r.ConsumeTo('T')); // consume to end }
public void ConsumeToString() { CharacterReader r = new CharacterReader("One Two Two Four"); Assert.AreEqual("One ", r.ConsumeTo("Two")); Assert.AreEqual('T', r.Consume()); Assert.AreEqual("wo ", r.ConsumeTo("Two")); Assert.AreEqual('T', r.Consume()); Assert.AreEqual("wo Four", r.ConsumeTo("Qux")); }
public void Advance() { CharacterReader r = new CharacterReader("One Two Three"); Assert.AreEqual('O', r.Consume()); r.Advance(); Assert.AreEqual('e', r.Consume()); }
public void MatchesAny() { char[] scan = { ' ', '\n', '\t' }; CharacterReader r = new CharacterReader("One\nTwo\tThree"); Assert.IsFalse(r.MatchesAny(scan)); Assert.AreEqual("One", r.ConsumeToAny(scan)); Assert.IsTrue(r.MatchesAny(scan)); Assert.AreEqual('\n', r.Consume()); Assert.IsFalse(r.MatchesAny(scan)); }
public void ContainsIgnoreCase() { CharacterReader r = new CharacterReader("One TWO three"); Assert.IsTrue(r.ContainsIgnoreCase("two")); Assert.IsTrue(r.ContainsIgnoreCase("three")); // weird one: does not find one, because it scans for consistent case only Assert.IsFalse(r.ContainsIgnoreCase("one")); }
public void Matches() { CharacterReader r = new CharacterReader("One Two Three"); Assert.IsTrue(r.Matches('O')); Assert.IsTrue(r.Matches("One Two Three")); Assert.IsTrue(r.Matches("One")); Assert.IsFalse(r.Matches("one")); Assert.AreEqual('O', r.Consume()); Assert.IsFalse(r.Matches("One")); Assert.IsTrue(r.Matches("ne Two Three")); Assert.IsFalse(r.Matches("ne Two Three Four")); Assert.AreEqual("ne Two Three", r.ConsumeToEnd()); Assert.IsFalse(r.Matches("ne")); }
public void ConsumeLetterThenDigitSequence() { CharacterReader r = new CharacterReader("One12 Two &bar; qux"); Assert.AreEqual("One12", r.ConsumeLetterThenDigitSequence()); Assert.AreEqual(' ', r.Consume()); Assert.AreEqual("Two", r.ConsumeLetterThenDigitSequence()); Assert.AreEqual(" &bar; qux", r.ConsumeToEnd()); }
public void ConsumeLetterSequence() { CharacterReader r = new CharacterReader("One &bar; qux"); Assert.AreEqual("One", r.ConsumeLetterSequence()); Assert.AreEqual(" &", r.ConsumeTo("bar;")); Assert.AreEqual("bar", r.ConsumeLetterSequence()); Assert.AreEqual("; qux", r.ConsumeToEnd()); }
public void ConsumeToAny() { CharacterReader r = new CharacterReader("One &bar; qux"); Assert.AreEqual("One ", r.ConsumeToAny('&', ';')); Assert.IsTrue(r.Matches('&')); Assert.IsTrue(r.Matches("&bar;")); Assert.AreEqual('&', r.Consume()); Assert.AreEqual("bar", r.ConsumeToAny('&', ';')); Assert.AreEqual(';', r.Consume()); Assert.AreEqual(" qux", r.ConsumeToAny('&', ';')); }