Esempio 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());
 }
Esempio 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());
 }
Esempio 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;
 }
Esempio 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;
 }
Esempio 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'));
    }
Esempio 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;
 }
Esempio 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;
 }
Esempio 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());
 }
Esempio 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());
        }
Esempio 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"));
 }
Esempio n. 11
0
 public void NextIndexOfUnmatched()
 {
     CharacterReader r = new CharacterReader("<[[one]]");
     Assert.AreEqual(-1, r.NextIndexOf("]]>"));
 }
Esempio 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"));
    }
Esempio 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
 }
Esempio 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"));
 }
Esempio 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());
 }
Esempio 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));
 }
Esempio 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"));
 }
Esempio 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"));
 }
Esempio 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());
 }
Esempio 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());
 }
Esempio 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('&', ';'));
 }