Inheritance: IContext
示例#1
0
 public void EscapeStateTokenizeNonWhitespace()
 {
     var lexer = new Lexer();
     var tokens = lexer.Tokenize("\\S");
     var expected = new NonWhitespaceToken();
     Assert.AreEqual(tokens.Last(), expected);
 }
示例#2
0
 public void EscapeStateTokenizeNumeric()
 {
     var lexer = new Lexer();
     var tokens = lexer.Tokenize("\\d");
     var expected = new NumericToken();
     Assert.AreEqual(tokens.Last(), expected);
 }
示例#3
0
 public void BeginSetStateTokenizeNot()
 {
     var lexer = new Lexer();
     var tokens = lexer.Tokenize("[^");
     var expected = new NotToken();
     Assert.AreEqual(tokens.Last(), expected);
 }
示例#4
0
 public void EscapeStateTokenizeLiteral()
 {
     var lexer = new Lexer();
     var tokens = lexer.Tokenize("\\z");
     var expected = new LiteralToken { Character = 'z' };
     Assert.AreEqual(tokens.Last(), expected);
 }
示例#5
0
 public void EscapeStateTokenizeWord()
 {
     var lexer = new Lexer();
     var tokens = lexer.Tokenize("\\w");
     var expected = new WordToken();
     Assert.AreEqual(tokens.Last(), expected);
 }
示例#6
0
 public void SetStateTokenizeRange()
 {
     var lexer = new Lexer();
     var tokens = lexer.Tokenize("[a-");
     var expected = new RangeToken();
     Assert.AreEqual(tokens.Last(), expected);
 }
示例#7
0
 public void SetStateTokenizeBracketRight()
 {
     var lexer = new Lexer();
     var tokens = lexer.Tokenize("[a]");
     var expected = new BracketRightToken();
     Assert.AreEqual(tokens.Last(), expected);
 }
示例#8
0
 public void RepetitionStateTokenizeToManyCommas()
 {
     var lexer = new Lexer();
     Assert.Throws<ArgumentException>(() => lexer.Tokenize("{1,,5}").ToList());
 }
示例#9
0
 public void LiteralStateTokenizeBracketLeft()
 {
     var lexer = new Lexer();
     var tokens = lexer.Tokenize("[");
     var expected = new BracketLeftToken();
     Assert.AreEqual(tokens.First(), expected);
 }
示例#10
0
 public void RepetitionStateTokenizeMissingValues()
 {
     var lexer = new Lexer();
     Assert.Throws<ArgumentException>(() => lexer.Tokenize("{}").ToList());
 }
示例#11
0
 public void RepetitionStateTokenizeInvalid()
 {
     var lexer = new Lexer();
     Assert.Throws<ArgumentException>(() => lexer.Tokenize("{1,a}").ToList());
 }
示例#12
0
 public void LiteralStateTokenizeZeroOrOne()
 {
     var lexer = new Lexer();
     var tokens = lexer.Tokenize("?");
     var expected = new RepetitionToken { MinOccurs = 0, MaxOccurs = 1 };
     Assert.AreEqual(tokens.First(), expected);
 }
示例#13
0
 public void LiteralStateTokenizeParenthesisRight()
 {
     var lexer = new Lexer();
     var tokens = lexer.Tokenize(")");
     var expected = new ParenthesisRightToken();
     Assert.AreEqual(tokens.First(), expected);
 }
示例#14
0
        public void LiteralStateTokenizeLiterals()
        {
            var lexer = new Lexer();
            var tokens = lexer.Tokenize("abc");
            var expected = new List<IToken>
                                     {
                                         new LiteralToken {Character = 'a'}
                                         , new LiteralToken {Character = 'b'}
                                         ,  new LiteralToken {Character = 'c'}
                                     };

            Assert.IsTrue(expected.SequenceEqual(tokens));
        }
示例#15
0
 public void RepetitionStateTokenizeShort()
 {
     var lexer = new Lexer();
     var tokens = lexer.Tokenize("{7}");
     var expected = new RepetitionToken { MinOccurs = 7, MaxOccurs = 7 };
     Assert.AreEqual(tokens.First(), expected);
 }
示例#16
0
 public void LiteralStateTokenizeAny()
 {
     var lexer = new Lexer();
     var tokens = lexer.Tokenize(".");
     var expected = new AnyToken();
     Assert.AreEqual(tokens.First(), expected);
 }
示例#17
0
        public INode Parse(string expression)
        {
            var tokens = new Lexer().Tokenize(expression);

            return Parse(tokens);
        }