Beispiel #1
0
        public void Reconhece_ListaInvalida_AoAvaliar(string text)
        {
            var list = new[]
            {
                new CharGrammarElement('1'),
                new CharGrammarElement('2'),
                new CharGrammarElement('3')
            };

            var grammar   = new OrListGrammarElement(list);
            var extractor = TokenExtractor.FromString(text);
            var token     = grammar.Eval(extractor);

            Assert.Null(token);
        }
Beispiel #2
0
        public void Reconhece_ListaValida_AoAvaliar(string text)
        {
            var list = new[]
            {
                new CharGrammarElement('a'),
                new CharGrammarElement('b'),
                new CharGrammarElement('c')
            };

            var grammar   = new OrListGrammarElement(list);
            var extractor = TokenExtractor.FromString(text);
            var token     = grammar.Eval(extractor);

            Assert.NotNull(token);
            Assert.IsType <char>(token.Content);
            Assert.Contains((char)token.Content, new char[] { 'a', 'b', 'c' });
        }
Beispiel #3
0
        public void Reconhece_QualquerDosTokensNaLista()
        {
            var list = new[]
            {
                new CharGrammarElement('a'),
                new CharGrammarElement('b'),
                new CharGrammarElement('c')
            };

            var grammar = new OrListGrammarElement(list);

            var extractorOk = TokenExtractor.FromString("cba");
            var tk1Ok       = grammar.Eval(extractorOk);
            var tk2Ok       = grammar.Eval(extractorOk);
            var tk3Ok       = grammar.Eval(extractorOk);

            var extractorErr = TokenExtractor.FromString("acx");
            var tk1Err       = grammar.Eval(extractorErr);
            var tk2Err       = grammar.Eval(extractorErr);
            var tk3Err       = grammar.Eval(extractorErr);

            // Ok
            Assert.NotNull(tk1Ok);
            Assert.NotNull(tk2Ok);
            Assert.NotNull(tk3Ok);
            Assert.Equal('c', (char)tk1Ok.Content);
            Assert.Equal('b', (char)tk2Ok.Content);
            Assert.Equal('a', (char)tk3Ok.Content);

            // Erro
            Assert.NotNull(tk1Err);
            Assert.NotNull(tk2Err);
            Assert.Null(tk3Err);
            Assert.Equal('a', (char)tk1Err.Content);
            Assert.Equal('c', (char)tk2Err.Content);
        }