コード例 #1
0
        public void NonCapturingGroupIsIgnored()
        {
            const string text = "2019/07/07 ERR some error message";
            var          sut  = new RegexTokenizer(@"\d{4}\/\d{2}\/\d{2} (?:ERR)*\s*(.+)", new Color(ConsoleColor.Red));

            Assert.Collection(sut.Parse(text),
                              x => Assert.Equal("2019/07/07 ERR ", x.Text),
                              x => Assert.Equal("some error message", x.Text)
                              );
        }
コード例 #2
0
        public void EndingMatchTest()
        {
            const string text = "Error in machine ID 123";
            var          sut  = new RegexTokenizer(@"Machine id (\d+)", new Color(ConsoleColor.Blue), RegexOptions.IgnoreCase);

            Assert.Collection(sut.Parse(text),
                              x => Assert.Equal("Error in machine ID ", x.Text),
                              x => Assert.Equal("123", x.Text)
                              );
        }
コード例 #3
0
        public void BeginningMatchTest()
        {
            const string text = "123 some text";
            var          sut  = new RegexTokenizer(@"\d+", new Color(ConsoleColor.Blue));

            Assert.Collection(sut.Parse(text),
                              x => Assert.Equal("123", x.Text),
                              x => Assert.Equal(" some text", x.Text)
                              );
        }
コード例 #4
0
        public void InMiddleMatchTest()
        {
            const string text = "2019/07/07 ERR error message";
            var          sut  = new RegexTokenizer("ERR", new Color(ConsoleColor.Yellow));

            Assert.Collection(sut.Parse(text),
                              x => Assert.Equal("2019/07/07 ", x.Text),
                              x => Assert.Equal("ERR", x.Text),
                              x => Assert.Equal(" error message", x.Text)
                              );
        }
コード例 #5
0
        public void MultipleMatchesTest()
        {
            const string text = "Traffic light has Red, Yellow and Green colors";
            var          sut  = new RegexTokenizer(@"(Red|Yellow|Green)", new Color(ConsoleColor.Blue), RegexOptions.IgnoreCase);

            Assert.Collection(sut.Parse(text),
                              x => Assert.Equal("Traffic light has ", x.Text),
                              x => Assert.Equal("Red", x.Text),
                              x => Assert.Equal(", ", x.Text),
                              x => Assert.Equal("Yellow", x.Text),
                              x => Assert.Equal(" and ", x.Text),
                              x => Assert.Equal("Green", x.Text),
                              x => Assert.Equal(" colors", x.Text)
                              );
        }