示例#1
0
        public void CharStream_BasicTest() {
            string text = "abcd\"foo\"\r\n<a href=";
            HtmlCharStream cs = new HtmlCharStream(text);

            Assert.Equal('a', cs.CurrentChar);

            cs.Advance(2);
            Assert.False(cs.IsEndOfStream());
            Assert.Equal('c', cs.CurrentChar);

            cs.Advance(-1);
            Assert.False(cs.IsEndOfStream());
            Assert.Equal('b', cs.CurrentChar);

            cs.Advance(text.Length);
            Assert.True(cs.IsEndOfStream());
            Assert.Equal(0, cs.CurrentChar);

            cs.Advance(-text.Length);
            Assert.False(cs.IsEndOfStream());
            Assert.Equal('a', cs.CurrentChar);

            Assert.Equal('d', cs.LookAhead(3));
            Assert.Equal('\"', cs.LookAhead(4));

            Assert.Equal(0, cs.LookAhead(text.Length));
            Assert.Equal(0, cs.LookAhead(-1));

            Assert.Equal(text.Length, cs.DistanceFromEnd);
            cs.Advance(1);
            Assert.Equal(text.Length - 1, cs.DistanceFromEnd);

            cs.Position = 4;
            Assert.True(cs.IsAtString());
            cs.Position = 5;
            Assert.False(cs.IsAtString());

            cs.Position = 9;
            Assert.True(cs.IsWhiteSpace());
            cs.MoveToNextChar();
            Assert.True(cs.IsWhiteSpace());

            cs.MoveToNextChar();
            Assert.True(cs.IsAtTagDelimiter());
        }
示例#2
0
        public void HtmlCharStream_IsNameCharTest() {
            var stream = new HtmlCharStream(new TextStream(""));
            Assert.True(stream.IsEndOfStream());
            Assert.Equal(0, stream.Length);

            stream = new HtmlCharStream(new TextStream("<h123"));
            Assert.Equal(0, stream.Position);
            Assert.False(stream.IsEndOfStream());
            stream.Position = 5;
            Assert.True(stream.IsEndOfStream());
            stream.Position = 0;
            Assert.False(stream.IsEndOfStream());

            stream.MoveToNextChar();
            Assert.Equal(1, stream.Position);

            stream.Advance(2);
            Assert.Equal(3, stream.Position);

            stream.Advance(-2);
            Assert.Equal(1, stream.Position);

            stream.Advance(1000);
            Assert.True(stream.IsEndOfStream());

            stream.Position = 0;
            Assert.True(stream.IsAtTagDelimiter());
            Assert.Equal('<', stream.CurrentChar);
            Assert.Equal('h', stream.NextChar);

            stream.Position = 1;
            Assert.False(stream.IsAtTagDelimiter());
            Assert.True(stream.IsNameChar());
            Assert.True(HtmlCharStream.IsNameStartChar(stream.CurrentChar));

            stream.Position = 2;
            Assert.False(stream.IsAtTagDelimiter());
            Assert.True(stream.IsNameChar());
            Assert.False(HtmlCharStream.IsNameStartChar(stream.CurrentChar));
        }
示例#3
0
        public void HtmlTokenizer_SkipWhitespaceTest() {
            var cs = new HtmlCharStream("   abc\t\tdef\r\n gh");
            HtmlTokenizer target = new HtmlTokenizer(cs);
            target.SkipWhitespace();
            Assert.Equal(3, cs.Position);

            target.SkipWhitespace();
            Assert.Equal(3, cs.Position);

            cs.Advance(3);
            target.SkipWhitespace();
            Assert.Equal(8, cs.Position);

            cs.Advance(3);
            target.SkipWhitespace();
            Assert.Equal(14, cs.Position);
        }