Exemplo n.º 1
0
        public void FindMatches_RemoveRegex_Equals()
        {
            var td = new TokenDefinition <TokenTypeTest>(TokenTypeTest.MyToken2, "hello \\d\\.\\dworld", null, 1, true, "\\d\\.\\d", -1, true);

            var matches = td.FindMatches("testing hello 5.2world", 1);

            Assert.Equal("hello world", matches.First().Value);
        }
Exemplo n.º 2
0
        public void FindMatches_GroupCapture_Equals()
        {
            var td = new TokenDefinition <TokenTypeTest>(TokenTypeTest.MyToken2, "hello (\\d\\.\\d)world", null, 1, true, null, -1, true);

            var matches = td.FindMatches("testing hello 5.2world", 1);

            Assert.Equal("5.2", matches.First().Value);
        }
Exemplo n.º 3
0
        public void FindMatches_MatchCount_Equals(string data, int matchCount)
        {
            var td = new TokenDefinition <TokenTypeTest>(TokenTypeTest.MyToken2, "mb|gb", null, 1, true, null, -1, true);

            var matches = td.FindMatches(data, 1);

            Assert.Equal(matchCount, matches.Count());
        }
Exemplo n.º 4
0
        public void FindMatches_Template_Equals()
        {
            var td = new TokenDefinition <TokenTypeTest>(TokenTypeTest.MyToken2, "S(\\d\\d)E(\\d\\d)", "Movie {1}-{2}", 1, true, null, -1, true);

            var matches = td.FindMatches("testinghelloS21E32world", 1);
            var token   = matches.First();

            Assert.Equal("Movie 21-32", token.Value);
            Assert.Equal(12, token.StartIndex);
            Assert.Equal(18, token.EndIndex);
        }
Exemplo n.º 5
0
        public void FindMatches_RetargetGroup_Equals()
        {
            var td = new TokenDefinition <TokenTypeTest>(TokenTypeTest.MyToken2, "S(\\d\\d)E(\\d\\d)", null, 1, true, null, 2, true);

            var matches = td.FindMatches("VideoS01E05.mp4", 1);

            var token = matches.First();

            Assert.Equal("05", token.Value);
            Assert.Equal(9, token.StartIndex);
            Assert.Equal(11, token.EndIndex);
        }
Exemplo n.º 6
0
        public void CodeDetectionTest()
        {
            string            code    = @"ASSET Test '1234'
                MY_FUNCTION
                {
                    there is code in here
                }
            ";
            List <TokenMatch> matches = new List <TokenMatch>();
            TokenDefinition   td      = new TokenDefinition(TokenType.SUB, @"(\S+)\s*{([^}]*)}", 1);

            matches.AddRange(td.FindMatches(code));
            Assert.IsTrue(matches.Count == 1);
        }
Exemplo n.º 7
0
        public void FindMatches_TokenProperties_MatchDefinition(int precedence, bool hasVariableValue, string location)
        {
            var td = new TokenDefinition <TokenTypeTest>(TokenTypeTest.MyToken2, ".+", null, precedence, hasVariableValue, null, -1, true);

            var matches = td.FindMatches("hello_world", 5);

            foreach (Token <TokenTypeTest> match in matches)
            {
                Assert.Equal(TokenTypeTest.MyToken2, match.TokenType);
                Assert.Equal(precedence, match.Precedence);
                Assert.Equal(hasVariableValue, match.HasVariableValue);
                Assert.Equal(5, match.LineNumber);
                Assert.Equal(location, match.Location);
            }
        }
Exemplo n.º 8
0
        public void FindMatches_NullInput_ThrowsArgumentNullException()
        {
            var td = new TokenDefinition <TokenTypeTest>(TokenTypeTest.MyToken2, ".+", null, 1, true, null, -1, true);

            Assert.Throws <ArgumentNullException>(() => td.FindMatches(null, 1));
        }