Exemplo n.º 1
0
     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());
 }
Exemplo n.º 2
0
 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());
 }
Exemplo n.º 3
0
 // 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;
 }
Exemplo n.º 4
0
 // 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;
 }
Exemplo n.º 5
0
        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'));
    }
Exemplo n.º 6
0
 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;
 }
Exemplo n.º 7
0
 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;
 }
Exemplo n.º 8
0
 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());
 }
Exemplo n.º 9
0
        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());
        }
Exemplo n.º 10
0
 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"));
 }
Exemplo n.º 11
0
 public void NextIndexOfUnmatched()
 {
     CharacterReader r = new CharacterReader("<[[one]]");
     Assert.AreEqual(-1, r.NextIndexOf("]]>"));
 }
Exemplo n.º 12
0
        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"));
    }
Exemplo n.º 13
0
 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
 }
Exemplo n.º 14
0
 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"));
 }
Exemplo n.º 15
0
 public void Advance()
 {
     CharacterReader r = new CharacterReader("One Two Three");
     Assert.AreEqual('O', r.Consume());
     r.Advance();
     Assert.AreEqual('e', r.Consume());
 }
Exemplo n.º 16
0
 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));
 }
Exemplo n.º 17
0
 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"));
 }
Exemplo n.º 18
0
 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"));
 }
Exemplo n.º 19
0
 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());
 }
Exemplo n.º 20
0
 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());
 }
Exemplo n.º 21
0
 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('&', ';'));
 }