Beispiel #1
0
        public void ParseNestedChoice()
        {
            Chat   c = CreateParentChat("c");
            Choice choice;

            string[] expected;
            string   text;

            text     = "((dog).Cap() | (then).Cap())";
            choice   = Choice.Parse(text, c, false)[0];
            expected = new[] { "(dog).Cap()", "(then).Cap()" };
            Assert.That(choice.text, Is.EqualTo("((dog).Cap() | (then).Cap())"));
            Assert.That(choice.options.Length, Is.EqualTo(expected.Length));
            Assert.That(choice.options, Is.EqualTo(expected));
        }
Beispiel #2
0
        public void ParseChoices()
        {
            Chat          c = CreateParentChat("c");
            List <Choice> choices;
            Choice        choice;

            choices = Choice.Parse("you (a | b | c) a", c, false);
            Assert.That(choices.Count, Is.EqualTo(1));
            choice = choices[0];
            Assert.That(choice.text, Is.EqualTo("(a | b | c)"));
            Assert.That(choice.options.Count, Is.EqualTo(3));
            Assert.That(choice.options, Is.EquivalentTo(new[] { "a", "b", "c" }));

            choices = Choice.Parse("you (a | a) a", c, false);
            Assert.That(choices.Count, Is.EqualTo(1));
            choice = choices[0];
            Assert.That(choice.text, Is.EqualTo("(a | a)"));
            Assert.That(choice.options.Count, Is.EqualTo(1));
            Assert.That(choice.options, Is.EquivalentTo(new[] { "a" }));

            choices = Choice.Parse("you (a | (b | c)) a", c, false);
            Assert.That(choices.Count, Is.EqualTo(1));
            choice = choices[0];
            Assert.That(choice.text, Is.EqualTo("(b | c)"));
            Assert.That(choice.options.Count, Is.EqualTo(2));
            Assert.That(choice.options, Is.EquivalentTo(new[] { "b", "c" }));

            choices = Choice.Parse("you (then | (a | b))", c, false);
            Assert.That(choices.Count, Is.EqualTo(1));
            choice = choices[0];
            Assert.That(choice.text, Is.EqualTo("(a | b)"));
            Assert.That(choice.options.Count, Is.EqualTo(2));
            Assert.That(choice.options, Is.EquivalentTo(new[] { "a", "b" }));

            choices = Choice.Parse("you ((a | b) | then) a", c, false);
            Assert.That(choices.Count, Is.EqualTo(1));
            choice = choices[0];
            Assert.That(choice.text, Is.EqualTo("(a | b)"));
            Assert.That(choice.options.Count, Is.EqualTo(2));
            Assert.That(choice.options, Is.EquivalentTo(new[] { "a", "b" }));
        }
Beispiel #3
0
        public void ParseChoicesWithTransform()
        {
            Chat          c = CreateParentChat("c");
            List <Choice> choices;
            Choice        choice;

            choices = Choice.Parse("(a | a).Cap()", c, false);
            Assert.That(choices.Count, Is.EqualTo(1));
            choice = choices[0];
            Assert.That(choice.text, Is.EqualTo("(a | a).Cap()"));
            Assert.That(choice.options.Count, Is.EqualTo(1));
            Assert.That(choice.options[0], Is.EqualTo("a"));
            Assert.That(choice._TransArray(), Is.EquivalentTo(new[] { "Cap" }));

            choices = Choice.Parse("((a).Cap() | (a).Cap()).Cap()", c, false);
            Assert.That(choices.Count, Is.EqualTo(1));
            choice = choices[0];
            Assert.That(choice.text, Is.EqualTo("((a).Cap() | (a).Cap()).Cap()"));
            Assert.That(choice.options.Count, Is.EqualTo(1));
            Assert.That(choice.options[0], Is.EqualTo("(a).Cap()"));
            Assert.That(choice._TransArray(), Is.EquivalentTo(new[] { "Cap" }));

            choices = Choice.Parse("(ok (a).Cap() | ok (a).Cap()).Cap()", c, false);
            Assert.That(choices.Count, Is.EqualTo(1));
            choice = choices[0];
            Assert.That(choice.text, Is.EqualTo("(ok (a).Cap() | ok (a).Cap()).Cap()"));
            Assert.That(choice.options.Count, Is.EqualTo(1));
            Assert.That(choice.options[0], Is.EqualTo("ok (a).Cap()"));
            Assert.That(choice._TransArray(), Is.EquivalentTo(new[] { "Cap" }));

            choices = Choice.Parse("(a | b).Cap()", c, false);
            Assert.That(choices.Count, Is.EqualTo(1));
            choice = choices[0];
            Assert.That(choice.text, Is.EqualTo("(a | b).Cap()"));
            Assert.That(choice.options.Count, Is.EqualTo(2));
            Assert.That(choice.options, Is.EquivalentTo(new[] { "a", "b" }));
        }
Beispiel #4
0
 private void ParseChoices(string text, Chat context)
 {
     choices.Clear();
     Choice.Parse(choices, text, context);
 }
Beispiel #5
0
        public void ChoiceParseTests()
        {
            Chat   c = CreateParentChat("c");
            Choice choice;

            string[] expected;
            string   text;

            text     = "you ($miss1 | $miss2.Cap() | ok) blah";
            choice   = Choice.Parse(text, c, false)[0];
            expected = new[] { "$miss1", "$miss2.Cap()", "ok" };
            Assert.That(choice.text, Is.EqualTo("($miss1 | $miss2.Cap() | ok)"));
            Assert.That(choice.options.Length, Is.EqualTo(expected.Length));
            Assert.That(choice.options, Is.EqualTo(expected));

            text     = "you (a |) blah";
            choice   = Choice.Parse(text, c, false)[0];
            expected = new[] { "a", "" };
            Assert.That(choice.text, Is.EqualTo("(a |)"));
            Assert.That(choice.options.Length, Is.EqualTo(expected.Length));
            Assert.That(choice.options, Is.EqualTo(expected));

            text     = "you (hello|) blah";
            choice   = Choice.Parse(text, c, false)[0];
            expected = new[] { "hello", "" };
            Assert.That(choice.text, Is.EqualTo("(hello|)"));
            Assert.That(choice.options.Length, Is.EqualTo(expected.Length));
            Assert.That(choice.options, Is.EqualTo(expected));

            text     = "you (hello|hello) blah";
            choice   = Choice.Parse(text, c, false)[0];
            expected = new[] { "hello", };
            Assert.That(choice.text, Is.EqualTo("(hello|hello)"));
            Assert.That(choice.options.Length, Is.EqualTo(expected.Length));
            Assert.That(choice.options, Is.EqualTo(expected));

            text     = "you (hello|hello|) blah";
            choice   = Choice.Parse(text, c, false)[0];
            expected = new[] { "hello", "" };
            Assert.That(choice.text, Is.EqualTo("(hello|hello|)"));
            Assert.That(choice.options.Length, Is.EqualTo(expected.Length));
            Assert.That(choice.options, Is.EqualTo(expected));

            text     = "you ($miss1 | $miss2) blah";
            choice   = Choice.Parse(text, c, false)[0];
            expected = new[] { "$miss1", "$miss2" };
            Assert.That(choice.text, Is.EqualTo("($miss1 | $miss2)"));
            Assert.That(choice.options.Length, Is.EqualTo(expected.Length));
            Assert.That(choice.options, Is.EqualTo(expected));

            text     = "you(a | b) a ";
            choice   = Choice.Parse(text, c, false)[0];
            expected = new[] { "a", "b" };
            Assert.That(choice.text, Is.EqualTo("(a | b)"));
            Assert.That(choice.options.Length, Is.EqualTo(expected.Length));
            Assert.That(choice.options, Is.EqualTo(expected));

            text     = "you (a | b).ToUpper() and ...";
            choice   = Choice.Parse(text, c, false)[0];
            expected = new[] { "a", "b" };
            Assert.That(choice.text, Is.EqualTo("(a | b).ToUpper()"));
            Assert.That(choice.options.Length, Is.EqualTo(expected.Length));
            Assert.That(choice.options, Is.EqualTo(expected));

            text     = "you (a|b) are";
            choice   = Choice.Parse(text, c, false)[0];
            expected = new[] { "a", "b" };
            Assert.That(choice.text, Is.EqualTo("(a|b)"));
            Assert.That(choice.options.Length, Is.EqualTo(expected.Length));
            Assert.That(choice.options, Is.EqualTo(expected));

            text     = "you (a|b).ToUpper() are";
            choice   = Choice.Parse(text, c, false)[0];
            expected = new[] { "a", "b" };
            Assert.That(choice.text, Is.EqualTo("(a|b).ToUpper()"));
            Assert.That(choice.options.Length, Is.EqualTo(expected.Length));
            Assert.That(choice.options, Is.EqualTo(expected));
            Assert.That(choice._TransArray(), Is.EquivalentTo(new[] { "ToUpper" }));

            //Resolver.DBUG = true;
            choice   = Choice.Parse("you (a|b).ToUpper().Articlize() are", c)[0];
            expected = new[] { "a", "b" };
            Assert.That(choice.text, Is.EqualTo("(a|b).ToUpper().Articlize()"));
            Assert.That(choice.options.Length, Is.EqualTo(expected.Length));
            Assert.That(choice.options, Is.EqualTo(expected));
            Assert.That(choice._TransArray(), Is.EquivalentTo(new[] { "ToUpper", "Articlize" }));

            choice   = Choice.Parse("you (a | b |c). are", c)[0];
            expected = new[] { "a", "b", "c" };
            Assert.That(choice.text, Is.EqualTo("(a | b |c)"));
            Assert.That(choice.options.Length, Is.EqualTo(expected.Length));
            Assert.That(choice.options, Is.EqualTo(expected));

            //Resolver.DBUG = true;
            choice   = Choice.Parse("you (a | b |c).ToUpper(). are", c)[0];
            expected = new[] { "a", "b", "c" };
            Assert.That(choice.text, Is.EqualTo("(a | b |c).ToUpper()"));
            Assert.That(choice.options.Length, Is.EqualTo(expected.Length));
            Assert.That(choice.options, Is.EqualTo(expected));

            choice   = Choice.Parse("you (a | b |c).ToUpper().Articlize(). are", c)[0];
            expected = new[] { "a", "b", "c" };
            Assert.That(choice.text, Is.EqualTo("(a | b |c).ToUpper().Articlize()"));
            Assert.That(choice.options.Length, Is.EqualTo(expected.Length));
            Assert.That(choice.options, Is.EqualTo(expected));

            choice   = Choice.Parse("you [d=(a | b | c)]. The", c)[0];
            expected = new[] { "a", "b", "c" };
            Assert.That(choice.text, Is.EqualTo("[d=(a | b | c)]"));
            Assert.That(choice.options.Length, Is.EqualTo(expected.Length));
            Assert.That(choice.alias, Is.EqualTo("d"));
            Assert.That(choice.options, Is.EqualTo(expected));


            //Resolver.DBUG = true;
            choice   = Choice.Parse("you [d=(a | b | c).ToUpper()]. The", c)[0];
            expected = new[] { "a", "b", "c" };
            Assert.That(choice.text, Is.EqualTo("[d=(a | b | c).ToUpper()]"));
            Assert.That(choice.options.Length, Is.EqualTo(expected.Length));
            Assert.That(choice.alias, Is.EqualTo("d"));
            Assert.That(choice.options, Is.EqualTo(expected));

            choice   = Choice.Parse("you [d=(a | b | c).ToUpper().Articlize()]. The", c)[0];
            expected = new[] { "a", "b", "c" };
            Assert.That(choice.text, Is.EqualTo("[d=(a | b | c).ToUpper().Articlize()]"));
            Assert.That(choice.options.Length, Is.EqualTo(expected.Length));
            Assert.That(choice.alias, Is.EqualTo("d"));
            Assert.That(choice.options, Is.EqualTo(expected));


            choice   = Choice.Parse("you [d=(a | b | c)].ToUpper(). The", c)[0];
            expected = new[] { "a", "b", "c" };
            Assert.That(choice.text, Is.EqualTo("[d=(a | b | c)].ToUpper()"));
            Assert.That(choice.options.Length, Is.EqualTo(expected.Length));
            Assert.That(choice.options, Is.EqualTo(expected));
            Assert.That(choice.alias, Is.EqualTo("d"));

            choice   = Choice.Parse("you [d=(a | b | c)].ToUpper().Articlize(). The", c)[0];
            expected = new[] { "a", "b", "c" };
            Assert.That(choice.text, Is.EqualTo("[d=(a | b | c)].ToUpper().Articlize()"));
            Assert.That(choice.options.Length, Is.EqualTo(expected.Length));
            Assert.That(choice.options, Is.EqualTo(expected));
            Assert.That(choice.alias, Is.EqualTo("d"));


            choice   = Choice.Parse("you [selected=(a | b | c)]. The", c)[0];
            expected = new[] { "a", "b", "c" };
            Assert.That(choice.text, Is.EqualTo("[selected=(a | b | c)]"));
            Assert.That(choice.options.Length, Is.EqualTo(expected.Length));
            Assert.That(choice.alias, Is.EqualTo("selected"));
            Assert.That(choice.options, Is.EqualTo(expected));


            //Resolver.DBUG = true;
            choice   = Choice.Parse("you [selected=(a | b | c).ToUpper()]. The", c)[0];
            expected = new[] { "a", "b", "c" };
            Assert.That(choice.text, Is.EqualTo("[selected=(a | b | c).ToUpper()]"));
            Assert.That(choice.options.Length, Is.EqualTo(expected.Length));
            Assert.That(choice.alias, Is.EqualTo("selected"));
            Assert.That(choice.options, Is.EqualTo(expected));


            choice   = Choice.Parse("you [selected=(a | b | c).ToUpper().Articlize()]. The", c)[0];
            expected = new[] { "a", "b", "c" };
            Assert.That(choice.text, Is.EqualTo("[selected=(a | b | c).ToUpper().Articlize()]"));
            Assert.That(choice.options.Length, Is.EqualTo(expected.Length));
            Assert.That(choice.alias, Is.EqualTo("selected"));
            Assert.That(choice.options, Is.EqualTo(expected));
        }