Exemplo n.º 1
0
        public void FindAllHard4()
        {
            var lines = new string[] {
                "CHAT c0",
                "FIND {dev=1,!!day=fri}",
                "CHAT c1 {day=fri}",
                "CHAT c2 {dev=2,day=fri}",
                "CHAT c3 {}"
            };

            var chats = ChatParser.ParseText(String.Join("\n", lines), NO_VALIDATORS);

            chats.ForEach(c => c.Resolve(null));

            //chats.ForEach((ch) => Console.WriteLine(ch.ToTree()));
            var finder = chats[0].commands[0]; finder.Resolve(null);

            Assert.That(chats[0].commands[0].GetType(), Is.EqualTo(typeof(Find)));

            var mday = finder.GetMeta("day");

            Assert.That(mday is Constraint, Is.True);
            var cons = (Constraint)mday;

            Assert.That(cons.type, Is.EqualTo(ConstraintType.Absolute));
            Assert.That(cons.IsStrict(), Is.True);

            chats = new ChatRuntime(chats).DoFindAll((Find)finder, null);
            //chats.ForEach((obj) => Console.WriteLine(obj.text));
            Assert.That(chats, Is.Not.Null);
            Assert.That(chats.Count, Is.EqualTo(1));
            Assert.That(chats[0], Is.Not.Null);
            Assert.That(chats[0].text, Is.EqualTo("c1"));
        }
Exemplo n.º 2
0
        public void FindChatByLabel()
        {
            string[] lines =
            {
                "CHAT c1 {day=fri}",
                "CHAT c2 {dev=2,day=fri}",
                "CHAT c3"
            };
            string      contents = String.Join("\n", lines);
            List <Chat> chats    = ChatParser.ParseText(contents, NO_VALIDATORS);
            Chat        result   = new ChatRuntime(chats).FindChatByLabel("c1");

            //chats.ForEach(c=>Console.WriteLine(c));
            Assert.That(result, Is.Not.Null);
            Assert.That(result.text, Is.EqualTo("c1"));

            Chat c;

            chats       = new List <Chat>();
            chats.Add(c = Chat.Create("c1"));
            chats.Add(c = Chat.Create("c2"));
            chats.Add(c = Chat.Create("c3"));
            ChatRuntime cr  = new ChatRuntime(chats);
            Chat        res = new ChatRuntime(chats).FindChatByLabel("c2");

            Assert.That(res.text, Is.EqualTo("c2"));
        }
Exemplo n.º 3
0
        public void FindAll2()
        {
            string[] lines =
            {
                "CHAT c0",
                "FIND {dev=1,day=fri}",
                "CHAT c1 {day=fri}",
                "CHAT c2 {dev=2,day=fri}",
                "CHAT c3 {}"
            };

            string contents = String.Join("\n", lines);


            List <Chat> chats = ChatParser.ParseText(contents, NO_VALIDATORS);
            //chats.ForEach((ch) => Console.WriteLine(ch.ToTree()));
            Command finder = chats[0].commands[0]; finder.Resolve(null);

            Assert.That(chats[0].commands[0].GetType(), Is.EqualTo(typeof(Find)));

            chats = new ChatRuntime(chats).DoFindAll((Find)finder, null);

            Assert.That(chats, Is.Not.Null);
            Assert.That(chats.Count, Is.EqualTo(2));

            Assert.That(chats[0], Is.Not.Null);
            Assert.That(chats[0].text, Is.EqualTo("c1"));

            lines = new[] {
                "CHAT c0",
                "FIND {!dev=1,day=fri}",
                "CHAT c1 {day=fri}",
                "CHAT c2 {dev=2,day=fri}",
                "CHAT c3 {}"
            };

            contents = String.Join("\n", lines);

            chats = ChatParser.ParseText(contents, NO_VALIDATORS);
            //chats.ForEach((ch) => Console.WriteLine(ch.ToTree()));
            finder = chats[0].commands[0]; finder.Resolve(null);
            var mdev = finder.GetMeta("dev");

            Assert.That(mdev is Constraint, Is.True);
            Constraint cons = (Constraint)mdev;

            Assert.That(cons.type, Is.EqualTo(ConstraintType.Hard));
            Assert.That(cons.IsStrict(), Is.True);
            Assert.That(finder.GetType(), Is.EqualTo(typeof(Find)));

            var rt = new ChatRuntime(chats);

            rt.Chats().ForEach(c => c.Resolve(null));
            chats = rt.DoFindAll((Find)finder, null);

            //chats.ForEach((obj) => Console.WriteLine(obj.text));

            Assert.That(chats, Is.Not.Null);
            Assert.That(chats.Count, Is.EqualTo(0));
        }
Exemplo n.º 4
0
        public void FindAllMultiHard2()
        {
            string[] lines =
            {
                "CHAT c0",
                "FIND {emotion*=(hot|cool), !day =fri}",
                "CHAT c1",
                "CHAT c2 {emotion=hot,day=fri}",
                "CHAT c3 {emotion=dry}",
                "CHAT c4 {emotion=dry,day=fri}",
            };

            string contents = String.Join("\n", lines);

            List <Chat> chats = ChatParser.ParseText(contents, NO_VALIDATORS);
            //chats.ForEach((ch) => Console.WriteLine(ch.ToTree()));
            Command finder = chats[0].commands[0]; finder.Resolve(null);

            Assert.That(chats[0].commands[0].GetType(), Is.EqualTo(typeof(Find)));

            chats = new ChatRuntime(chats).DoFindAll((Find)finder, null);
            //chats.ForEach((obj) => Console.WriteLine(obj.text));

            Assert.That(chats, Is.Not.Null);
            Assert.That(chats.Count, Is.EqualTo(1));

            Assert.That(chats[0], Is.Not.Null);
            Assert.That(chats[0].text, Is.EqualTo("c2"));

            lines = new string[] {
                "CHAT c0 {day=sunday}",
                "FIND {emotion *= (hot|cool|blah), !day*=(fri|wed)}",
                "CHAT c1 {emotion=wet, day = wed }",
                "CHAT c2 {emotion=hot,day=fri}",
                "CHAT c3 {emotion=dry}",
                "CHAT c4 {emotion=cool,day=tues}",
            };

            contents = String.Join("\n", lines);

            chats = ChatParser.ParseText(contents, NO_VALIDATORS);
            //chats.ForEach((ch) => Console.WriteLine(ch.ToTree()));
            finder = chats[0].commands[0]; finder.Resolve(null);
            Assert.That(chats[0].commands[0].GetType(), Is.EqualTo(typeof(Find)));


            chats = new ChatRuntime(chats).DoFindAll((Find)finder, null);
            //chats.ForEach((obj) => Console.WriteLine(obj.text));

            Assert.That(chats, Is.Not.Null);
            Assert.That(chats.Count, Is.EqualTo(1));

            Assert.That(chats[0], Is.Not.Null);
            Assert.That(chats[0].text, Is.EqualTo("c2"));
        }
Exemplo n.º 5
0
        public void FindAllOpsHard()
        {
            string[] lines =
            {
                "CHAT c0",
                "FIND {!dev>1,day=fri}",
                "CHAT c1 {dev=2,day=fri}",
                "CHAT c2 {dev=1,day=fri}",
                "CHAT c3 {}"
            };

            string contents = String.Join("\n", lines);

            List <Chat> chats = ChatParser.ParseText(contents, NO_VALIDATORS);
            //chats.ForEach((ch) => Console.WriteLine(ch.ToTree()));
            Command finder = chats[0].commands[0]; finder.Resolve(null);

            Assert.That(chats[0].commands[0].GetType(), Is.EqualTo(typeof(Find)));
            ChatRuntime cr = new ChatRuntime(chats);

            chats = cr.DoFindAll((Find)finder, null);
            //chats.ForEach((obj) => Console.WriteLine(obj.text));

            Assert.That(chats, Is.Not.Null);
            Assert.That(chats.Count, Is.EqualTo(1));

            Assert.That(chats[0], Is.Not.Null);
            Assert.That(chats[0].text, Is.EqualTo("c1"));

            lines = new[] {
                "CHAT c0",
                "FIND {dev<2,!day=fri}",
                "CHAT c1 {dev=2,day=fri}",
                "CHAT c2 {dev=1,day=fri}",
                "CHAT c3 {}"
            };

            contents = String.Join("\n", lines);

            chats = ChatParser.ParseText(contents, NO_VALIDATORS);
            //chats.ForEach((ch) => Console.WriteLine(ch.ToTree()));
            finder = chats[0].commands[0]; finder.Resolve(null);
            Assert.That(chats[0].commands[0].GetType(), Is.EqualTo(typeof(Find)));
            cr = new ChatRuntime(chats);

            chats = cr.DoFindAll((Find)finder, null);
            //chats.ForEach((obj) => Console.WriteLine(obj.text));

            Assert.That(chats, Is.Not.Null);
            Assert.That(chats.Count, Is.EqualTo(1));

            Assert.That(chats[0], Is.Not.Null);
            Assert.That(chats[0].text, Is.EqualTo("c2"));
        }
Exemplo n.º 6
0
        public void ParsedVar()
        {
            Chat chat = ChatParser.ParseText("SAY Thank $count")[0];

            Assert.That(chat.commands[0].GetType(), Is.EqualTo(typeof(Say)));
            Command say = chat.commands[0];

            Assert.That(say.GetType(), Is.EqualTo(typeof(Say)));
            say.Resolve(globals);
            Assert.That(say.Text(), Is.EqualTo("Thank 4"));
            Assert.That(say.Resolved(Meta.TYPE), Is.EqualTo("Say"));
        }
Exemplo n.º 7
0
        public void TextGroup()
        {
            var  ok   = new string[] { "The boy was sad", "The boy was happy", "The boy was dead" };
            Chat chat = ChatParser.ParseText("SAY The boy was (sad | happy | dead)")[0];

            Assert.That(chat.commands[0].GetType(), Is.EqualTo(typeof(Say)));
            Command c = (Say)chat.commands[0];

            Assert.That(c.GetType(), Is.EqualTo(typeof(Say)));
            c.Resolve(globals);
            Assert.That(c.Resolved(Meta.TYPE), Is.EqualTo("Say"));
            CollectionAssert.Contains(ok, c.Text());
        }
Exemplo n.º 8
0
        public void ReplacePrompt()
        {
            List <Chat> chats = ChatParser.ParseText("ASK Want a $animal?\nOPT $group #Game\n\nOPT $count #End");

            Assert.That(chats.Count, Is.EqualTo(1));
            Assert.That(chats[0].Count, Is.EqualTo(1));
            Assert.That(chats[0].GetType(), Is.EqualTo(typeof(Chat)));
            Assert.That(chats[0].commands[0].GetType(), Is.EqualTo(typeof(Ask)));

            Ask ask = (Ask)chats[0].commands[0];

            Assert.That(ask.text, Is.EqualTo("Want a $animal?"));
            ask.Resolve(globals);

            Assert.That(ask.text, Is.EqualTo("Want a $animal?"));
            Assert.That(ask.Text(), Is.EqualTo("Want a dog?"));
            Assert.That(ask.Options().Count, Is.EqualTo(2));

            var options = ask.Options();

            Assert.That(options[0].GetType(), Is.EqualTo(typeof(Opt)));
            //Assert.That(options[0].Text, Is.EqualTo("Y").Or.);
            CollectionAssert.Contains(new string[] { "a", "b" }, options[0].Text());
            Assert.That(options[0].action.GetType(), Is.EqualTo(typeof(Go)));
            Assert.That(options[1].GetType(), Is.EqualTo(typeof(Opt)));
            Assert.That(options[1].Text(), Is.EqualTo("4"));
            Assert.That(options[1].action.GetType(), Is.EqualTo(typeof(Go)));


            chats = ChatParser.ParseText("ASK Want a $obj-prop?\nOPT $group #Game\n\nOPT $count #End");
            Assert.That(chats.Count, Is.EqualTo(1));
            Assert.That(chats[0].Count, Is.EqualTo(1));
            Assert.That(chats[0].GetType(), Is.EqualTo(typeof(Chat)));
            Assert.That(chats[0].commands[0].GetType(), Is.EqualTo(typeof(Ask)));

            ask = (Ask)chats[0].commands[0];
            ask.Resolve(globals);
            Assert.That(ask.text, Is.EqualTo("Want a $obj-prop?"));
            Assert.That(ask.Text(), Is.EqualTo("Want a dog?"));

            Assert.That(ask.Options().Count, Is.EqualTo(2));

            options = ask.Options();
            Assert.That(options[0].GetType(), Is.EqualTo(typeof(Opt)));
            //Assert.That(options[0].Text, Is.EqualTo("Y").Or.);
            CollectionAssert.Contains(new string[] { "a", "b" }, options[0].Text());
            Assert.That(options[0].action.GetType(), Is.EqualTo(typeof(Go)));
            Assert.That(options[1].GetType(), Is.EqualTo(typeof(Opt)));
            Assert.That(options[1].Text(), Is.EqualTo("4"));
            Assert.That(options[1].action.GetType(), Is.EqualTo(typeof(Go)));
        }
Exemplo n.º 9
0
        public void FindAll()
        {
            string[] lines =
            {
                "CHAT c1 {day=fri}",
                "CHAT c2 {dev=2,day=fri}",
                "CHAT c3 {}"
            };
            string      contents = String.Join("\n", lines);
            List <Chat> chats    = ChatParser.ParseText(contents, NO_VALIDATORS);
            List <Chat> result   = new ChatRuntime(chats).DoFindAll(null,
                                                                    new Constraint("dev", "1"),
                                                                    new Constraint("day", "fri")
                                                                    );

            Assert.That(result, Is.Not.Null);
            Assert.That(result.Count, Is.EqualTo(2));
            Assert.That(result[0].text, Is.EqualTo("c1"));

            Chat c;

            chats       = new List <Chat>();
            chats.Add(c = Chat.Create("c1"));
            chats.Add(c = Chat.Create("c2"));
            c.SetMeta("dev", "1");
            c.SetMeta("day", "hello");
            chats.Add(c = Chat.Create("c3"));
            ChatRuntime cr = new ChatRuntime(chats);

            chats = cr.DoFindAll(null, new Constraint("dev", "1"));
            //chats.ForEach((obj) => Console.WriteLine(obj.text));
            Assert.That(chats, Is.Not.Null);
            Assert.That(chats.Count, Is.EqualTo(3));
            Assert.That(chats[0].text, Is.EqualTo("c2"));

            chats       = new List <Chat>();
            chats.Add(c = Chat.Create("c1"));
            c.SetMeta("dev", "2");
            chats.Add(c = Chat.Create("c2"));
            c.SetMeta("dev", "1");
            c.SetMeta("day", "hello");
            chats.Add(c = Chat.Create("c3"));

            cr    = new ChatRuntime(chats);
            chats = cr.DoFindAll(null, new Constraint("dev", "1"));
            //chats.ForEach((obj) => Console.WriteLine(obj.text));
            Assert.That(chats, Is.Not.Null);
            Assert.That(chats.Count, Is.EqualTo(2));
            Assert.That(chats[0].text, Is.EqualTo("c2"));
            Assert.That(chats[1].text, Is.EqualTo("c3"));
        }
Exemplo n.º 10
0
        public void TimingTest()
        {
            Say fast = (Say)ChatParser.ParseText("SAY Thank you { speed=fast}")[0].commands[0];
            Say defa = (Say)ChatParser.ParseText("SAY Thank you")[0].commands[0];
            Say slow = (Say)ChatParser.ParseText("SAY Thank you{speed=slow }")[0].commands[0];

            Assert.That(defa.ComputeDuration(), Is.EqualTo(fast.ComputeDuration() * 2).Within(1));
            Assert.That(slow.ComputeDuration(), Is.EqualTo(defa.ComputeDuration() * 2).Within(1));
            Say longer = (Say)ChatParser.ParseText("SAY Thank you very much")[0].commands[0];

            Assert.That(longer.ComputeDuration(), Is.GreaterThan(defa.ComputeDuration()));
            Assert.That(fast.text, Is.EqualTo(defa.text));
            Assert.That(slow.text, Is.EqualTo(defa.text));
        }
Exemplo n.º 11
0
        public void Staleness()
        {
            Chat        c;
            List <Chat> chats = new List <Chat>();

            chats.Add(c = Chat.Create("c1"));
            c.SetMeta("dev", "hello");
            c.Staleness(2);
            chats.Add(c = Chat.Create("c2"));
            c.SetMeta("dev", "2");
            c.Staleness(3);
            chats.Add(c = Chat.Create("c3"));
            c.SetMeta("dev", "3");
            c.Staleness(4);
            var res = new ChatRuntime(chats).DoFindAll
                          (null, new Constraint(Operator.LT, "staleness", "3"));

            Assert.That(res.Count, Is.EqualTo(1));
            Assert.That(res[0].text, Is.EqualTo("c1"));

            string[] lines =
            {
                "CHAT c0",
                "FIND {dev=1,day=fri,staleness<5}",
                "CHAT c1 {day=fri}",
                "CHAT c2 {dev=2,day=fri}",
                "CHAT c3 {}"
            };

            string contents = String.Join("\n", lines);

            chats = ChatParser.ParseText(contents, NO_VALIDATORS);

            Command finder = chats[0].commands[0]; finder.Resolve(null);

            Assert.That(finder.GetType(), Is.EqualTo(typeof(Find)));

            var crt = new ChatRuntime(chats);

            c = crt.FindChatByLabel("#c1");
            c.Staleness(6);
            Assert.That(c, Is.Not.Null);
            Assert.That(c.text, Is.EqualTo("c1"));

            chats = crt.DoFindAll((Find)finder, null);
            Assert.That(chats, Is.Not.Null);
            Assert.That(chats.Count, Is.EqualTo(1));
            Assert.That(chats[0], Is.Not.Null);
            Assert.That(chats[0].text, Is.EqualTo("c3"));
        }
Exemplo n.º 12
0
        public void TextVar()
        {
            Chat chat = ChatParser.ParseText("SAY Thank $count { pace=$animal}")[0];

            Assert.That(chat.commands[0].GetType(), Is.EqualTo(typeof(Say)));
            Command say = chat.commands[0];

            Assert.That(say.GetType(), Is.EqualTo(typeof(Say)));
            say.Resolve(globals);
            Assert.That(say.Text(), Is.EqualTo("Thank 4"));
            say.text = "Thank you";
            Assert.That(say.text, Is.EqualTo("Thank you"));
            Assert.That(say.Resolved(Meta.TYPE), Is.EqualTo("Say"));
            Assert.That(say.Resolved("pace"), Is.EqualTo("dog"));
        }
Exemplo n.º 13
0
        public void GroupRecursionDepth()
        {
            var str = "CHAT c\n(I | (You | (doh | why | no) | ouY) | They)";

            str += "(want | hate | like | love)(coffee | bread | milk)";
            Chat chat = ChatParser.ParseText(str, NO_VALIDATORS)[0];

            Assert.That(chat.commands[0].GetType(), Is.EqualTo(typeof(Say)));
            Say say = (Dialogic.Say)chat.commands[0];

            say.Resolve(null);
            var s = say.Text();

            Assert.That(s, Is.Not.EqualTo(""));
        }
Exemplo n.º 14
0
        public void ComplexReplacement()
        {
            // "cmplx" -> "($group | $prep)"
            // "prep"  -> "then" },
            // "group" -> "(a|b)" },
            string[] ok   = { "letter a", "letter b", "letter then" };
            Chat     chat = ChatParser.ParseText("SAY letter $cmplx")[0];
            Command  c    = chat.commands[0];

            Assert.That(c.GetType(), Is.EqualTo(typeof(Say)));
            for (int i = 0; i < 10; i++)
            {
                c.Resolve(globals);
                var txt = c.Text();
                //Console.WriteLine(i+") "+txt);
                CollectionAssert.Contains(ok, txt);
            }
        }
Exemplo n.º 15
0
        public void ComplexPlusTransform()
        {
            // "cmplx" -> "($group | $prep)"
            // "prep"  -> "then" },
            // "group" -> "(a|b)" },
            string[] ok   = { "letter an a", "letter a b", "letter a then" };
            Chat     chat = ChatParser.ParseText("SAY letter $cmplx.articlize()")[0];
            Command  c    = chat.commands[0];

            Assert.That(c.GetType(), Is.EqualTo(typeof(Say)));
            Resolver.DBUG = false;
            for (int i = 0; i < 1; i++)
            {
                c.Resolve(globals);
                var txt = c.Text();
                Assert.That(txt.IsOneOf(ok));
            }
        }
Exemplo n.º 16
0
        //[Test]
        public void ResumeEventTest()
        {
            string[] lines =
            {
                "CHAT c1 {type=a}",
                "CHAT c2 {type=b,day=fri}",
                "CHAT c3 {type=c,day=thurs}",
            };

            string      contents = String.Join("\n", lines);
            List <Chat> chats    = ChatParser.ParseText(contents, NO_VALIDATORS);
            ChatRuntime rt       = new ChatRuntime(chats);

            for (int i = 0; i < 3; i++)
            {
                EventArgs icu = new ResumeEvent("{}");
                rt.Update(null, ref icu);
            }
        }
Exemplo n.º 17
0
        public void SayNonRepeatingRecomb()
        {
            List <Chat> chats = ChatParser.ParseText("SAY (a|b|c)");

            Assert.That(chats.Count, Is.EqualTo(1));
            Assert.That(chats[0].Count, Is.EqualTo(1));
            Assert.That(chats[0].GetType(), Is.EqualTo(typeof(Chat)));
            Assert.That(chats[0].commands[0].GetType(), Is.EqualTo(typeof(Say)));
            Say    say  = (Say)chats[0].commands[0];
            string last = "";

            for (int i = 0; i < 10; i++)
            {
                say.Resolve(globals);
                string said = say.Text();
                //System.Console.WriteLine(i+") "+said);
                Assert.That(said, Is.Not.EqualTo(last));
                last = said;
            }
        }
Exemplo n.º 18
0
        public void FindAllWithMetaVars()
        {
            string[] lines =
            {
                "CHAT c1 {day=fri}", // parent not returned
                "CHAT c2 {dev=4,day=fri}",
                "CHAT c3 {dev=3}",
                "CHAT c4"
            };
            string      contents = String.Join("\n", lines);
            List <Chat> chats    = ChatParser.ParseText(contents, NO_VALIDATORS);

            Assert.That(globals["count"], Is.EqualTo(4));
            List <Chat> result = new ChatRuntime(chats).DoFindAll
                                     (chats[0], globals, new Constraint("dev", "$count"));

            //chats.ForEach((obj) => Console.WriteLine(obj.text));
            Assert.That(result, Is.Not.Null);
            Assert.That(result.Count, Is.EqualTo(2));
            Assert.That(result[0].text, Is.EqualTo("c2"));
        }
Exemplo n.º 19
0
        public void SetGlobalsOnPath()
        {
            var  code = "CHAT c1\nSET $fish.name=Mary\nSAY Hi $fish.name";
            Chat chat = ChatParser.ParseText(code, null)[0];

            Assert.That(chat, Is.Not.Null);
            Assert.That(chat.commands[0].GetType(), Is.EqualTo(typeof(Set)));
            Assert.That(chat.commands[1].GetType(), Is.EqualTo(typeof(Say)));

            Set set = (Dialogic.Set)chat.commands[0];

            Assert.That(set.text, Is.EqualTo("fish.name"));
            Assert.That(set.value, Is.EqualTo("Mary"));

            Say say = (Dialogic.Say)chat.commands[1];

            Assert.That(say.text, Is.EqualTo("Hi $fish.name"));

            chat.Resolve(globals);
            Assert.That(say.Text(), Is.EqualTo("Hi Mary"));
        }
Exemplo n.º 20
0
        public void MetaReplaceGroups()
        {
            List <Chat> chats = ChatParser.ParseText("DO emote {type=(A|B)}");

            Assert.That(chats.Count, Is.EqualTo(1));
            Assert.That(chats[0].Count, Is.EqualTo(1));
            Assert.That(chats[0].GetType(), Is.EqualTo(typeof(Chat)));
            Assert.That(chats[0].commands[0].GetType(), Is.EqualTo(typeof(Do)));
            Do doo = (Do)chats[0].commands[0];

            Assert.That(doo.text, Is.EqualTo("emote"));
            Assert.That(doo.HasMeta("type"), Is.EqualTo(true));
            Assert.That(doo.GetMeta("type"), Is.EqualTo("(A|B)"));

            for (int i = 0; i < 10; i++)
            {
                doo.Resolve(globals);
                Assert.That(doo.Text(), Is.EqualTo("emote"));
                //Console.WriteLine(doo.GetResolved("type"));
                Assert.That(doo.Resolved("type"), Is.EqualTo("A").Or.EqualTo("B"));
            }
        }
Exemplo n.º 21
0
        public void MetaReplaceValue()
        {
            Chat chat = ChatParser.ParseText("SAY Thank you { pace = fast}")[0];

            Assert.That(chat.commands[0].GetType(), Is.EqualTo(typeof(Say)));
            Command c = (Say)chat.commands[0];

            Assert.That(c.GetType(), Is.EqualTo(typeof(Say)));
            c.Resolve(globals);
            c.SetMeta("pace", "slow");

            Assert.That(c.Text(), Is.EqualTo("Thank you"));
            Assert.That(c.Resolved(Meta.TYPE), Is.EqualTo("Say"));
            Assert.That(c.Resolved("pace"), Is.EqualTo("fast"));
            Assert.That(c.GetMeta("pace"), Is.EqualTo("slow"));

            chat = ChatParser.ParseText("SAY Thank you { pace=$animal}")[0];
            Assert.That(chat.commands[0].GetType(), Is.EqualTo(typeof(Say)));
            c = (Say)chat.commands[0];
            Assert.That(c.GetType(), Is.EqualTo(typeof(Say)));
            c.Resolve(globals);
            c.SetMeta("pace", "slow");
            Assert.That(c.Resolved(Meta.TEXT), Is.EqualTo("Thank you"));
            Assert.That(c.Resolved(Meta.TYPE), Is.EqualTo("Say"));
            Assert.That(c.Resolved("pace"), Is.EqualTo("dog"));
            Assert.That(c.GetMeta("pace"), Is.EqualTo("slow"));

            chat = ChatParser.ParseText("SAY Thank you { pace=$obj-prop}")[0];
            Assert.That(chat.commands[0].GetType(), Is.EqualTo(typeof(Say)));
            c = (Say)chat.commands[0];
            Assert.That(c.GetType(), Is.EqualTo(typeof(Say)));
            c.Resolve(globals);
            c.SetMeta("pace", "slow");
            Assert.That(c.Resolved(Meta.TEXT), Is.EqualTo("Thank you"));
            Assert.That(c.Resolved(Meta.TYPE), Is.EqualTo("Say"));
            Assert.That(c.Resolved("pace"), Is.EqualTo("dog"));
            Assert.That(c.GetMeta("pace"), Is.EqualTo("slow"));
        }
Exemplo n.º 22
0
        public void AskNonRepeatingRecomb()
        {
            List <Chat> chats = ChatParser.ParseText("ASK (a|b|c)?\nOPT (c|d|e) #f");

            Assert.That(chats.Count, Is.EqualTo(1));
            //Console.WriteLine(chats[0].ToTree());
            Assert.That(chats[0].GetType(), Is.EqualTo(typeof(Chat)));
            Assert.That(chats[0].commands[0].GetType(), Is.EqualTo(typeof(Ask)));
            Ask    ask = (Ask)chats[0].commands[0];
            string last = "", lastOpts = "";

            for (int i = 0; i < 10; i++)
            {
                ask.Resolve(globals);
                string asked = ask.Text();
                string opts  = ask.JoinOptions();
                //Console.WriteLine(i+") "+asked+" "+opts);
                Assert.That(asked, Is.Not.EqualTo(last));
                Assert.That(opts, Is.Not.EqualTo(lastOpts));
                lastOpts = opts;
                last     = asked;
            }
        }
Exemplo n.º 23
0
        public void StalenessEventTest()
        {
            string[] lines =
            {
                "CHAT c1 {type=a}",
                "CHAT c2 {type=a,day=fri}",
                "CHAT c3 {type=b,day=thurs}",
                "CHAT c4"
            };

            string      contents = String.Join("\n", lines);
            List <Chat> chats    = ChatParser.ParseText(contents, NO_VALIDATORS);
            ChatRuntime rt       = new ChatRuntime(chats);

            //chats.ForEach(Console.WriteLine);
            chats.ForEach(c => Assert.That(c.Staleness(), Is.EqualTo(Defaults.CHAT_STALENESS)));
            EventArgs icu = new StalenessUpdate(5);

            rt.Update(null, ref icu);
            chats.ForEach(c => Assert.That(c.Staleness(), Is.EqualTo(5)));

            icu = new StalenessUpdate(100, "#c4");
            rt.Update(null, ref icu);
            Assert.That(rt.FindChatByLabel("c1").Staleness(), Is.EqualTo(5));
            Assert.That(rt.FindChatByLabel("c4").Staleness(), Is.EqualTo(100));

            icu = new StalenessUpdate(10, "{!type=a}");
            rt.Update(null, ref icu);

            new AutoResetEvent(false).WaitOne(20);             // async hack for C# 4.0

            //chats.ForEach(Console.WriteLine);
            Assert.That(rt.FindChatByLabel("c1").Staleness(), Is.EqualTo(10));
            Assert.That(rt.FindChatByLabel("c2").Staleness(), Is.EqualTo(10));
            Assert.That(rt.FindChatByLabel("c3").Staleness(), Is.EqualTo(5));
            Assert.That(rt.FindChatByLabel("c4").Staleness(), Is.EqualTo(100));
        }
Exemplo n.º 24
0
        public void FindWithRelaxation()
        {
            string[] lines =
            {
                "CHAT c0",
                "FIND {dev>1,!day=fri}",
                "CHAT c1 {dev=2,day=wed}",
                "CHAT c2 {dev=3,day=wed}",
                "CHAT c3 {}"
            };

            string contents = String.Join("\n", lines);

            List <Chat> chats = ChatParser.ParseText(contents, NO_VALIDATORS);
            //chats.ForEach((ch) => Console.WriteLine(ch.ToTree()));
            Command finder = chats[0].commands[0]; finder.Resolve(null);

            Assert.That(chats[0].commands[0].GetType(), Is.EqualTo(typeof(Find)));

            ChatRuntime rt   = new ChatRuntime(chats);
            var         chat = rt.DoFind((Find)finder, null);

            Assert.That(chat, Is.Not.Null);
            Assert.That(chat.text, Is.EqualTo("c3"));

            lines = new[] {
                "CHAT c0 {dev=1}",
                "FIND {!dev>1,!day=fri}",
                "CHAT c1 {dev=0,day=wed}",
                "CHAT c2 {day=wed}",
                "CHAT c3 {}"
            };

            contents = String.Join("\n", lines);

            chats = ChatParser.ParseText(contents, NO_VALIDATORS);
            //chats.ForEach((ch) => Console.WriteLine(ch.ToTree()));
            finder = chats[0].commands[0]; finder.Resolve(null);
            Assert.That(chats[0].commands[0].GetType(), Is.EqualTo(typeof(Find)));

            rt   = new ChatRuntime(chats);
            chat = rt.DoFind((Find)finder, null);

            Assert.That(chat, Is.Not.Null);
            Assert.That(chat.text, Is.EqualTo("c3"));

            lines = new[] {
                "CHAT c0 {dev=1}",
                "FIND {!dev>1,!day=fri}",
                "CHAT c1 {dev=0,day=wed}",
                "CHAT c2 {day=wed}",
            };

            chats  = ChatParser.ParseText(String.Join("\n", lines), NO_VALIDATORS);
            finder = chats[0].commands[0]; finder.Resolve(null);

            rt   = new ChatRuntime(chats);
            chat = rt.DoFind((Find)finder, null);
            Assert.That(chat, Is.Null);

            Chat c;

            chats       = new List <Chat>();
            chats.Add(c = Chat.Create("c1"));
            c.SetMeta("dev", "hello");
            chats.Add(c = Chat.Create("c2"));
            c.SetMeta("dev", "2");
            chats.Add(c = Chat.Create("c3"));
            rt          = new ChatRuntime(chats);
            chat        = rt.DoFind(null, new Constraint("dev", "1", ConstraintType.Hard));
            Assert.That(chat.text, Is.EqualTo("c3")); // success
        }
Exemplo n.º 25
0
        public void FindAllOp3()
        {
            string[] lines =
            {
                "CHAT c1 {emotion=cold}",
                "FIND {emotion*=ho}",
                "CHAT c2 {emotion=hot}"
            };

            var contents = String.Join("\n", lines);

            var chats = ChatParser.ParseText(contents, NO_VALIDATORS);
            //chats.ForEach((ch) => Console.WriteLine(ch.ToTree()));
            var finder = chats[0].commands[0]; finder.Resolve(null);

            Assert.That(chats[0].commands[0].GetType(), Is.EqualTo(typeof(Find)));

            chats = new ChatRuntime(chats).DoFindAll((Find)finder, null);
            //chats.ForEach((obj) => Console.WriteLine(obj.text));

            Assert.That(chats, Is.Not.Null);
            Assert.That(chats.Count, Is.EqualTo(1));

            Assert.That(chats[0], Is.Not.Null);
            Assert.That(chats[0].text, Is.EqualTo("c2"));

            lines = new string[] {
                "CHAT c1 {emotion=cold}",
                "FIND {emotion^=h}",
                "CHAT c2 {emotion=hot}",
                "CHAT c3 {emotion=that}"
            };

            contents = String.Join("\n", lines);

            chats = ChatParser.ParseText(contents, NO_VALIDATORS);
            //chats.ForEach((ch) => Console.WriteLine(ch.ToTree()));
            finder = chats[0].commands[0]; finder.Resolve(null);
            Assert.That(chats[0].commands[0].GetType(), Is.EqualTo(typeof(Find)));

            chats = new ChatRuntime(chats).DoFindAll((Find)finder, null);
            //chats.ForEach((obj) => Console.WriteLine(obj.text));

            Assert.That(chats, Is.Not.Null);
            Assert.That(chats.Count, Is.EqualTo(1));

            Assert.That(chats[0], Is.Not.Null);
            Assert.That(chats[0].text, Is.EqualTo("c2"));

            lines = new string[] {
                "CHAT c1 {emotion=hot}",
                "FIND {emotion$=ld}",
                "CHAT c2 {emotion=hot}",
                "CHAT c3 {emotion=cold}"
            };

            contents = String.Join("\n", lines);

            chats = ChatParser.ParseText(contents, NO_VALIDATORS);
            //chats.ForEach((ch) => Console.WriteLine(ch.ToTree()));
            finder = chats[0].commands[0]; finder.Resolve(null);
            Assert.That(chats[0].commands[0].GetType(), Is.EqualTo(typeof(Find)));

            chats = new ChatRuntime(chats).DoFindAll((Find)finder, null);
            //chats.ForEach((obj) => Console.WriteLine(obj.text));

            Assert.That(chats, Is.Not.Null);
            Assert.That(chats.Count, Is.EqualTo(1));

            Assert.That(chats[0], Is.Not.Null);
            Assert.That(chats[0].text, Is.EqualTo("c3"));
        }