public void Reconhece_ListaValida_AoAvaliar() { var list = new[] { new CharGrammarElement('a'), new CharGrammarElement('b'), new CharGrammarElement('c') }; var grammar = new AndListGrammarElement(list); var extractor = TokenExtractor.FromString("abc"); var token = grammar.Eval(extractor); Assert.NotNull(token); Assert.IsType <Token[]>(token.Content); Assert.Equal(3, (token.Content as Token[]).Length); Assert.Equal("a", (token.Content as Token[])[0].Content.ToString()); Assert.Equal("b", (token.Content as Token[])[1].Content.ToString()); Assert.Equal("c", (token.Content as Token[])[2].Content.ToString()); }
public void Consome_SoOsCaracteres_Necessarios() { var list = new[] { new CharGrammarElement('e'), new CharGrammarElement('f'), new CharGrammarElement('g') }; var grammar = new AndListGrammarElement(list); var extractor = TokenExtractor.FromString("efghhh"); var posBegin = extractor.SaveCursor(); var token = grammar.Eval(extractor); Assert.NotNull(token); Assert.Equal(0, posBegin.Position); Assert.Equal(3, extractor.SaveCursor().Position); Assert.IsType <Token[]>(token.Content); Assert.Equal(3, (token.Content as Token[]).Length); Assert.Equal("e", (token.Content as Token[])[0].Content.ToString()); Assert.Equal("f", (token.Content as Token[])[1].Content.ToString()); Assert.Equal("g", (token.Content as Token[])[2].Content.ToString()); }