コード例 #1
0
        public void GetNext_Test()
        {
            var target = new StringCharacterSequence("abc");

            target.GetNext().Should().Be('a');
            target.GetNext().Should().Be('b');
            target.GetNext().Should().Be('c');
            target.GetNext().Should().Be('\0');
        }
コード例 #2
0
        public void GetRemainder_End()
        {
            var target = new StringCharacterSequence("abc");

            target.GetNext();
            target.GetNext();
            target.GetNext();
            target.GetRemainder().Should().Be("");
        }
コード例 #3
0
        public void GetNext_OldMacNewlines()
        {
            var target = new StringCharacterSequence("\ra\r");

            target.GetNext().Should().Be('\n');
            target.GetNext().Should().Be('a');
            target.GetNext().Should().Be('\n');
            target.GetNext().Should().Be('\0');
        }
コード例 #4
0
        public void GetNext_UnixNewlines()
        {
            var target = new StringCharacterSequence("\na\n");

            target.GetNext().Should().Be('\n');
            target.GetNext().Should().Be('a');
            target.GetNext().Should().Be('\n');
            target.GetNext().Should().Be('\0');
        }
コード例 #5
0
        public void GetNext_Empty()
        {
            var target = new StringCharacterSequence("");

            // Every get attempt past the end of the string will return '\0'
            target.GetNext().Should().Be('\0');
            target.GetNext().Should().Be('\0');
            target.GetNext().Should().Be('\0');
            target.GetNext().Should().Be('\0');
        }
コード例 #6
0
        public void IsAtEnd_Test()
        {
            var target = new StringCharacterSequence("abc");

            target.IsAtEnd.Should().BeFalse();
            target.GetNext();
            target.IsAtEnd.Should().BeFalse();
            target.GetNext();
            target.IsAtEnd.Should().BeFalse();
            target.GetNext();
            target.IsAtEnd.Should().BeTrue();
        }
コード例 #7
0
        public void Peek_WindowsNewlines()
        {
            var target = new StringCharacterSequence("\r\na\r\n");

            target.Peek().Should().Be('\n');
            target.GetNext();
            target.Peek().Should().Be('a');
            target.GetNext();
            target.Peek().Should().Be('\n');
            target.GetNext();
            target.Peek().Should().Be('\0');
        }
コード例 #8
0
        public void GetNext_OldMacNewlines_NonNormalized()
        {
            var target = new StringCharacterSequence("\ra\r", new StringCharacterSequence.Options
            {
                NormalizeLineEndings = false
            });

            target.GetNext().Should().Be('\r');
            target.GetNext().Should().Be('a');
            target.GetNext().Should().Be('\r');
            target.GetNext().Should().Be('\0');
        }
コード例 #9
0
        public void GetNext_Empty_CustomEndSentinel()
        {
            var target = new StringCharacterSequence("", new StringCharacterSequence.Options
            {
                EndSentinel = 'X'
            });

            // Every get attempt past the end of the string will return '\0'
            target.GetNext().Should().Be('X');
            target.GetNext().Should().Be('X');
            target.GetNext().Should().Be('X');
            target.GetNext().Should().Be('X');
        }
コード例 #10
0
        public void ReadNewlineIncrementsConsumed()
        {
            var target = new StringCharacterSequence("\r\n");
            var next   = target.GetNext();

            next.Should().Be('\n');
            target.Consumed.Should().Be(1);
        }
コード例 #11
0
        public void Output_Callback_Throw()
        {
            var    parser = Any().Chain <char, char, object>(c => throw new System.Exception());
            var    input  = new StringCharacterSequence("abc");
            Action act    = () => parser.Parse(input);

            act.Should().Throw <Exception>();
            input.GetNext().Should().Be('a');
        }
コード例 #12
0
        public void Location_Rewind()
        {
            var target = new StringCharacterSequence("abc\nde");

            target.GetNext();
            target.GetNext();
            target.GetNext();
            target.CurrentLocation.Line.Should().Be(1);
            target.CurrentLocation.Column.Should().Be(3);
            var checkpoint = target.Checkpoint();

            target.GetNext().Should().Be('\n');
            target.CurrentLocation.Line.Should().Be(2);
            target.CurrentLocation.Column.Should().Be(0);

            checkpoint.Rewind();
            target.CurrentLocation.Line.Should().Be(1);
            target.CurrentLocation.Column.Should().Be(3);
        }
コード例 #13
0
        public void Location_Test()
        {
            var target = new StringCharacterSequence("a\nbc");

            target.GetNext().Should().Be('a');
            target.CurrentLocation.Line.Should().Be(1);
            target.CurrentLocation.Column.Should().Be(1);

            target.GetNext().Should().Be('\n');

            target.GetNext().Should().Be('b');
            target.CurrentLocation.Line.Should().Be(2);
            target.CurrentLocation.Column.Should().Be(1);

            target.GetNext().Should().Be('c');
            target.CurrentLocation.Line.Should().Be(2);
            target.CurrentLocation.Column.Should().Be(2);

            target.GetNext().Should().Be('\0');
        }
コード例 #14
0
        public void SingleNumber_Remainder()
        {
            var target = Pratt <string>(c => c
                                        .Add(DigitString())
                                        );
            var input  = new StringCharacterSequence("1a");
            var result = target.Parse(input);

            result.Success.Should().BeTrue();
            result.Value.Should().Be("1");
            result.Consumed.Should().Be(1);
            input.GetNext().Should().Be('a');
        }
コード例 #15
0
        public void Checkpoint_Test()
        {
            var target = new StringCharacterSequence("abc");
            var cp     = target.Checkpoint();

            target.GetNext().Should().Be('a');
            target.GetNext().Should().Be('b');
            target.GetNext().Should().Be('c');
            target.GetNext().Should().Be('\0');
            cp.Rewind();
            target.GetNext().Should().Be('a');
            target.GetNext().Should().Be('b');
            target.GetNext().Should().Be('c');
            target.GetNext().Should().Be('\0');
        }