예제 #1
0
        public void CanCheckHasNextLine()
        {
            string input =
                @"First line
4453
Last line";

            using (var s = new TextScanner(input))
            {
                // verified the following with a java sample.
                Assert.That(s.HasNextLine(), Is.True);

                Assert.That(s.NextLine(), Is.EqualTo("First line"));
                Assert.That(s.ToString(), Contains.Substring("position=12"));

                Assert.That(s.HasNextLine(), Is.True);
                Assert.That(s.NextDouble(), Is.EqualTo(4453.0));
                Assert.That(s.ToString(), Contains.Substring("position=16"));

                Assert.That(s.HasNextLine(), Is.True);
                Assert.That(s.NextLine(), Is.EqualTo(""));
                Assert.That(s.ToString(), Contains.Substring("position=18"));

                Assert.That(s.HasNextLine(), Is.True);
                Assert.That(s.NextLine(), Is.EqualTo("Last line"));
                Assert.That(s.HasNextLine(), Is.False);
                Assert.Catch(() => s.NextLine());
            }
        }
예제 #2
0
        public void CallingNextAtEndOfLineThrowsException()
        {
            string input = @"First line, second statement, third statement";

            using (var s = new TextScanner(input)
                           .UseDelimiter(@",\s*"))
            {
                Assert.That(s.Next(), Is.EqualTo("First line"));
                Assert.That(s.NextLine(), Is.EqualTo(", second statement, third statement"));
                Assert.Catch <InvalidOperationException>(() => s.Next());
            }
        }
예제 #3
0
        public void CanSkipLines()
        {
            string input =
                @"First Line, second statement,
Second Line, fourth statement
";

            using (var s = new TextScanner(input)
                           .UseDelimiter(@",\s*"))
            {
                Assert.That(s.Next(), Is.EqualTo("First Line"));
                Assert.That(s.NextLine(), Is.EqualTo(", second statement,"));
                Assert.That(s.Next(), Is.EqualTo("Second Line"));

                Assert.That(s.FindInLine(@"^[a-z, ]+$"), Is.EqualTo(", fourth statement"));

                Assert.That(s.HasNextLine(), Is.False);

                // there are no more line endings, so the following should throw
                Assert.Catch <InvalidOperationException>(() => s.NextLine());
            }
        }
예제 #4
0
        public void CanSkipLineAfterTokenCheck()
        {
            string input =
                @"First Line, second statement,
Second Line, fourth statement
";

            using (var s = new TextScanner(input)
                           .UseDelimiter(@",\s*"))
            {
                // verified the following with a java sample.
                Assert.That(s.HasNextUInt32(), Is.False);
                Assert.That(s.Next(), Is.EqualTo("First Line"));
                Assert.That(s.HasNextUInt32(), Is.False);
                Assert.That(s.NextLine(), Is.EqualTo(", second statement,"));
                Assert.That(s.Next(), Is.EqualTo("Second Line"));

                Assert.That(s.NextLine(), Is.EqualTo(", fourth statement"));

                // there are no more line endings, so the following should throw
                Assert.Catch <InvalidOperationException>(() => s.NextLine());
            }
        }