Esempio n. 1
0
        public virtual void ConsumeToString()
        {
            CharacterReader r = new CharacterReader("One Two Two Four");

            NUnit.Framework.Assert.AreEqual("One ", r.ConsumeTo("Two"));
            NUnit.Framework.Assert.AreEqual('T', r.Consume());
            NUnit.Framework.Assert.AreEqual("wo ", r.ConsumeTo("Two"));
            NUnit.Framework.Assert.AreEqual('T', r.Consume());
            NUnit.Framework.Assert.AreEqual("wo Four", r.ConsumeTo("Qux"));
        }
Esempio n. 2
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
 // start tag to process
 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 List <iText.StyledXmlParser.Jsoup.Nodes.Element>(32);
     this.baseUri = baseUri;
 }
Esempio n. 3
0
        public virtual void MatchesAny()
        {
            char[]          scan = new char[] { ' ', '\n', '\t' };
            CharacterReader r    = new CharacterReader("One\nTwo\tThree");

            NUnit.Framework.Assert.IsFalse(r.MatchesAny(scan));
            NUnit.Framework.Assert.AreEqual("One", r.ConsumeToAny(scan));
            NUnit.Framework.Assert.IsTrue(r.MatchesAny(scan));
            NUnit.Framework.Assert.AreEqual('\n', r.Consume());
            NUnit.Framework.Assert.IsFalse(r.MatchesAny(scan));
        }
Esempio n. 4
0
        public virtual void Mark()
        {
            CharacterReader r = new CharacterReader("one");

            r.Consume();
            r.Mark();
            NUnit.Framework.Assert.AreEqual('n', r.Consume());
            NUnit.Framework.Assert.AreEqual('e', r.Consume());
            NUnit.Framework.Assert.IsTrue(r.IsEmpty());
            r.RewindToMark();
            NUnit.Framework.Assert.AreEqual('n', r.Consume());
        }
Esempio n. 5
0
        public virtual void ConsumeToAny()
        {
            CharacterReader r = new CharacterReader("One &bar; qux");

            NUnit.Framework.Assert.AreEqual("One ", r.ConsumeToAny('&', ';'));
            NUnit.Framework.Assert.IsTrue(r.Matches('&'));
            NUnit.Framework.Assert.IsTrue(r.Matches("&bar;"));
            NUnit.Framework.Assert.AreEqual('&', r.Consume());
            NUnit.Framework.Assert.AreEqual("bar", r.ConsumeToAny('&', ';'));
            NUnit.Framework.Assert.AreEqual(';', r.Consume());
            NUnit.Framework.Assert.AreEqual(" qux", r.ConsumeToAny('&', ';'));
        }
Esempio n. 6
0
        public virtual void ConsumeToChar()
        {
            CharacterReader r = new CharacterReader("One Two Three");

            NUnit.Framework.Assert.AreEqual("One ", r.ConsumeTo('T'));
            NUnit.Framework.Assert.AreEqual("", r.ConsumeTo('T'));
            // on Two
            NUnit.Framework.Assert.AreEqual('T', r.Consume());
            NUnit.Framework.Assert.AreEqual("wo ", r.ConsumeTo('T'));
            NUnit.Framework.Assert.AreEqual('T', r.Consume());
            NUnit.Framework.Assert.AreEqual("hree", r.ConsumeTo('T'));
        }
Esempio n. 7
0
        public virtual void NextIndexOfString()
        {
            String          @in = "One Two something Two Three Four";
            CharacterReader r   = new CharacterReader(@in);

            NUnit.Framework.Assert.AreEqual(-1, r.NextIndexOf("Foo"));
            NUnit.Framework.Assert.AreEqual(4, r.NextIndexOf("Two"));
            NUnit.Framework.Assert.AreEqual("One Two ", r.ConsumeTo("something"));
            NUnit.Framework.Assert.AreEqual(10, r.NextIndexOf("Two"));
            NUnit.Framework.Assert.AreEqual("something Two Three Four", r.ConsumeToEnd());
            NUnit.Framework.Assert.AreEqual(-1, r.NextIndexOf("Two"));
        }
Esempio n. 8
0
        public virtual void RangeEquals()
        {
            CharacterReader r = new CharacterReader("Check\tCheck\tCheck\tCHOKE");

            NUnit.Framework.Assert.IsTrue(r.RangeEquals(0, 5, "Check"));
            NUnit.Framework.Assert.IsFalse(r.RangeEquals(0, 5, "CHOKE"));
            NUnit.Framework.Assert.IsFalse(r.RangeEquals(0, 5, "Chec"));
            NUnit.Framework.Assert.IsTrue(r.RangeEquals(6, 5, "Check"));
            NUnit.Framework.Assert.IsFalse(r.RangeEquals(6, 5, "Chuck"));
            NUnit.Framework.Assert.IsTrue(r.RangeEquals(12, 5, "Check"));
            NUnit.Framework.Assert.IsFalse(r.RangeEquals(12, 5, "Cheeky"));
            NUnit.Framework.Assert.IsTrue(r.RangeEquals(18, 5, "CHOKE"));
            NUnit.Framework.Assert.IsFalse(r.RangeEquals(18, 5, "CHIKE"));
        }
Esempio n. 9
0
        public virtual void Matches()
        {
            CharacterReader r = new CharacterReader("One Two Three");

            NUnit.Framework.Assert.IsTrue(r.Matches('O'));
            NUnit.Framework.Assert.IsTrue(r.Matches("One Two Three"));
            NUnit.Framework.Assert.IsTrue(r.Matches("One"));
            NUnit.Framework.Assert.IsFalse(r.Matches("one"));
            NUnit.Framework.Assert.AreEqual('O', r.Consume());
            NUnit.Framework.Assert.IsFalse(r.Matches("One"));
            NUnit.Framework.Assert.IsTrue(r.Matches("ne Two Three"));
            NUnit.Framework.Assert.IsFalse(r.Matches("ne Two Three Four"));
            NUnit.Framework.Assert.AreEqual("ne Two Three", r.ConsumeToEnd());
            NUnit.Framework.Assert.IsFalse(r.Matches("ne"));
        }
Esempio n. 10
0
        public virtual void NextIndexOfChar()
        {
            String          @in = "blah blah";
            CharacterReader r   = new CharacterReader(@in);

            NUnit.Framework.Assert.AreEqual(-1, r.NextIndexOf('x'));
            NUnit.Framework.Assert.AreEqual(3, r.NextIndexOf('h'));
            String pull = r.ConsumeTo('h');

            NUnit.Framework.Assert.AreEqual("bla", pull);
            r.Consume();
            NUnit.Framework.Assert.AreEqual(2, r.NextIndexOf('l'));
            NUnit.Framework.Assert.AreEqual(" blah", r.ConsumeToEnd());
            NUnit.Framework.Assert.AreEqual(-1, r.NextIndexOf('x'));
        }
Esempio n. 11
0
 internal Tokeniser(CharacterReader reader, ParseErrorList errors)
 {
     // html input
     // errors found while tokenising
     // current tokenisation state
     // the token we are about to emit on next read
     // characters pending an emit. Will fall to charsBuilder if more than one
     // buffers characters to output as one token, if more than one emit per read
     // 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. 12
0
        public virtual void Consume()
        {
            CharacterReader r = new CharacterReader("one");

            NUnit.Framework.Assert.AreEqual(0, r.Pos());
            NUnit.Framework.Assert.AreEqual('o', r.Current());
            NUnit.Framework.Assert.AreEqual('o', r.Consume());
            NUnit.Framework.Assert.AreEqual(1, r.Pos());
            NUnit.Framework.Assert.AreEqual('n', r.Current());
            NUnit.Framework.Assert.AreEqual(1, r.Pos());
            NUnit.Framework.Assert.AreEqual('n', r.Consume());
            NUnit.Framework.Assert.AreEqual('e', r.Consume());
            NUnit.Framework.Assert.IsTrue(r.IsEmpty());
            NUnit.Framework.Assert.AreEqual(CharacterReader.EOF, r.Consume());
            NUnit.Framework.Assert.IsTrue(r.IsEmpty());
            NUnit.Framework.Assert.AreEqual(CharacterReader.EOF, r.Consume());
        }
Esempio n. 13
0
        public virtual void NextIndexOfUnmatched()
        {
            CharacterReader r = new CharacterReader("<[[one]]");

            NUnit.Framework.Assert.AreEqual(-1, r.NextIndexOf("]]>"));
        }
Esempio n. 14
0
 internal Tokeniser(CharacterReader reader, ParseErrorList errors)
 {
     this.reader = reader;
     this.errors = errors;
 }