示例#1
0
        public void SearchHardDashedConstraint()
        {
            string[] lines =
            {
                "CHAT CORE_Shake {type=sha-ke, stage=CO-RE}",
                "SAY Core shake!",

                "CHAT CORE_Tap {type=ta-p, stage=CO-RE}",
                "SAY Core tap!",

                "CHAT CORE_Stale_Fast {type=cri-tic, stage=CO-RE}",
                "SAY Core critic!",

                "CHAT NV_Shake {type=sha-ke, stage=N-V}",
                "SAY NV shake!",

                "CHAT NV_Tap {type=ta-p, stage=N-V}",
                "SAY NV tap!",

                "CHAT NV_Stale_Fast {type=cri-tic, stage=N-V}",
                "SAY NV critic!",
            };

            string      contents = String.Join("\n", lines);
            ChatRuntime rt       = new ChatRuntime(AppConfig.TAC);

            rt.ParseText(contents);
            var finder = new Find().Init("{!!type=ta-p,!stage=CO-RE}");

            var chat = rt.DoFind((Dialogic.Find)finder);

            Assert.That(chat.text, Is.EqualTo("CORE_Tap"));
        }
示例#2
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
        }