public void Load_Newer_Version_File()
        {
            var rs = new RiveScript(true);

            var result = rs.stream("! version = 2.1");
            Assert.IsFalse(result);
        }
Ejemplo n.º 2
0
        public void Complex_Random_With_Conditionals_And_Arrays_Triggers_UTF8()
        {
            var rs = new RiveScript(utf8: true);

            rs.streamForTest(new[] { "! array oi = olá oi",
                                     "^ boa noite|bom dia",
                                     "",
                                     "+ meu nome é *",
                                     "- <set name=<formal>>Prazer em conhecer, <get name>",
                                     "",
                                     "+ @oi",
                                     "* <get name> != undefined => {random}",
                                     "^ Olá, <get name>.|",
                                     "^ Bom dia, <get name>.{/random}",
                                     "- Olá!",
                                     "- Como vai?",
                                    });

            //Without name

            rs.reply("olá")
              .AssertContains("Olá!", "Como vai?");

            //Set name
            rs.reply("meu nome é Fábio")
              .AssertAreEqual("Prazer em conhecer, Fábio");

            rs.reply("bom dia")
               .AssertContains("Olá, Fábio.", "Bom dia, Fábio.");
        }
        public void Complex_Random_With_Conditionals_And_Arrays_Triggers()
        {
            var rs = new RiveScript();

            rs.streamForTest(new[] { "! array hello = hi hello",
                                     "^ hi there | good day",
                                     "",
                                     "+ my name is *",
                                     "- <set name=<formal>>Nice to meet you, <get name>",
                                     "",
                                     "+ @hello",
                                     "* <get name> != undefined => {random}",
                                     "^ Hello there, <get name>.|",
                                     "^ Hey, <get name>.{/random}",
                                     "- Hello there!",
                                     "- Hi there",
                                    });

            //Without name

            rs.reply("hello")
              .AssertContains("Hello there!", "Hi there");

            //Set name
            rs.reply("my name is John")
              .AssertAreEqual("Nice to meet you, John");

            rs.reply("hi")
               .AssertContains("Hello there, John.", "Hey, John.");
        }
        public void Load_Same_Version_File()
        {
            var rs = new RiveScript(true);

            var result = rs.stream("! version = 2.0");
            Assert.IsTrue(result);
        }
        public void Optional_Start_End_Full_Middle_Alternation()
        {
            var rs = new RiveScript(true);

            rs.stream(new[] { "+ [*] (when were you born|what is your birthday|what is your bday) [*]",
                              "",
                              "- reply",
                              ""
            });

            rs.sortReplies();

            rs.reply("when were you born").AssertAreEqual("reply");
            rs.reply("tell when were you born").AssertAreEqual("reply");
            rs.reply("tell when were you born please").AssertAreEqual("reply");
            rs.reply("when were you born please").AssertAreEqual("reply");

            rs.reply("what is your birthday").AssertAreEqual("reply");
            rs.reply("tell what is your birthday").AssertAreEqual("reply");
            rs.reply("tell what is your birthday please").AssertAreEqual("reply");
            rs.reply("what is your birthday please").AssertAreEqual("reply");

            rs.reply("what is your bday").AssertAreEqual("reply");
            rs.reply("tell what is your bday").AssertAreEqual("reply");
            rs.reply("tell what is your bday please").AssertAreEqual("reply");
            rs.reply("what is your bday please").AssertAreEqual("reply");
        }
Ejemplo n.º 6
0
        public string onCall(string name, RiveScript rs, string[] args)
        {
            if (false == assemblies.ContainsKey(name) ||
                false == methods.ContainsKey(name))
                return "ERR: Could not find a object code for " + name + ".";

            var del = methods[name];

            return del(rs, args);
        }
Ejemplo n.º 7
0
        public void Load_Simple_File_Non_Common_Extension()
        {
            var rs = new RiveScript(true);

            var result = rs.loadFile("TestData/basic_reply_3.txt");
            Assert.IsTrue(result);

            rs.sortReplies();

            rs.reply("trigger3").AssertAreEqual("reply3");
        }
Ejemplo n.º 8
0
        public void Simple_Reply()
        {
            var rs = new RiveScript(utf8: true, debug: true);

            rs.streamForTest(new[] { "+ olá bot",
                                     "- Olá humano!" });

            var reply = rs.reply("default", "olá bot");

            Assert.AreEqual(reply, "Olá humano!");
        }
        public void Simple_Random_Reply()
        {
            var rs = new RiveScript();

            rs.streamForTest(new[] { "+ hello bot",
                                     "- Hello",
                                     "- Hi" });

            var reply = rs.reply("hello bot");

            Assert.IsTrue(new[] { "Hello",
                                  "Hi" }.Contains(reply));
        }
        public void Alternation_With_Optional_And_Space_Between()
        {
            var rs = new RiveScript(true);

            rs.stream(new[] { "+ (aa|bb|cc) [bogus]",
                              "- reply"
            });

            rs.sortReplies();

            rs.reply("aa bogus").AssertAreEqual("reply");
            rs.reply("aabogus").AssertAreNotEqual("reply");
        }
Ejemplo n.º 11
0
        public void Load_All_Directory_No_Extension_Specify()
        {
            var rs = new RiveScript(true);

            var result = rs.loadDirectory("TestData");
            Assert.IsTrue(result);

            rs.sortReplies();

            rs.reply("trigger1").AssertAreEqual("reply1");
            rs.reply("trigger2").AssertAreEqual("reply2");
            rs.reply("trigger4").AssertAreEqual("reply4");//Inner folder
            rs.reply("trigger3").AssertAreNotEqual("reply3"); //Non-common extension
        }
Ejemplo n.º 12
0
        public void Load_All_Directory_With_Extension_Specify()
        {
            var rs = new RiveScript(true);

            var result = rs.loadDirectory("TestData", new[] { ".rs" });
            Assert.IsTrue(result);

            rs.sortReplies();

            rs.reply("trigger1").AssertAreEqual("reply1");//.rs
            rs.reply("trigger2").AssertAreNotEqual("reply2"); //.rive
            rs.reply("trigger3").AssertAreNotEqual("reply3"); //.txt
            rs.reply("trigger4").AssertAreEqual("reply4");//.rs
        }
Ejemplo n.º 13
0
        public void Last_Reply_Repetition_UTF8()
        {
            var rs = new RiveScript(utf8: true);

            rs.streamForTest(new[] { "+ <reply>",
                                     "- Eu não acabei de falar isso?",
                                     "+ olá",
                                     "- Olá como vai"

            });

            var r1 = rs.reply("Olá");
            Assert.AreEqual("Olá como vai", r1);

            rs.reply("Olá como vai")
              .AssertAreEqual("Eu não acabei de falar isso?");
        }
Ejemplo n.º 14
0
        public void Last_Reply_Repetition()
        {
            var rs = new RiveScript(utf8: false);

            rs.streamForTest(new[] { "+ <reply>",
                                     "- I just say that",
                                     "+ hi",
                                     "- hello"

            });

            var r1 = rs.reply("hi");
            Assert.AreEqual("hello", r1);

            rs.reply("hello")
              .AssertAreEqual("I just say that");
        }
Ejemplo n.º 15
0
        public void Last_Input_Repetition_UTF8()
        {
            var rs = new RiveScript(utf8: true);

            rs.streamForTest(new[] { "+ <input>",
                                     "- Você não acabou de falar isso?",
                                     "+ olá",
                                     "- Oi"

            });

            rs.reply("Olá")
              .AssertAreEqual("Oi");

            rs.reply("Olá")
              .AssertAreEqual("Você não acabou de falar isso?");
        }
Ejemplo n.º 16
0
        public void Last_Input_Repetition()
        {
            var rs = new RiveScript(utf8: false);

            rs.streamForTest(new[] { "+ <input>",
                                     "- Didn't you just say that?",
                                     "+ hi",
                                     "- Hello"

            });

            rs.reply("Hi")
              .AssertAreEqual("Hello");

            rs.reply("Hi")
              .AssertAreEqual("Didn't you just say that?");
        }
        public void Execute_Full_Object_Call_Without_Parameter()
        {
            var rs = new RiveScript();
            rs.setHandler("csharp", new CSharp());
            rs.stream(new[] { "",
                              "+ who is current user",
                              "- current user is: <call>current</call>",
                              "",
                              "> object current csharp",
                              "    return rs.currentUser();",
                              "< object",
                              ""
            });

            rs.sortReplies();

            var result = rs.reply("who is current user");

            Assert.AreEqual("current user is: default", result);
        }
        public void Execute_Full_Object_Call_With_Parameter()
        {
            var rs = new RiveScript();
            rs.setHandler("csharp", new CSharp());
            rs.stream(new[] { "",
                              "+ sum # and #",
                              "- result is: <call>sum <star1> <star2></call>",
                              "",
                              "> object sum csharp",
                              "    return (int.Parse(args[0]) + int.Parse(args[1])).ToString();",
                              "< object",
                              ""
            });

            rs.sortReplies();

            var result = rs.reply("sum 10 and 15");

            Assert.AreEqual("result is: 25", result);
        }
        public void Execute_Full_Object_Call_Custom_References()
        {
            var rs = new RiveScript();
            rs.setHandler("csharp", new CSharp());
            rs.stream(new[] { "",
                              "+ show data enum",
                              "- enum is: <call>test</call>",
                              "",
                              "> object test csharp",
                              "    reference System.Data.dll;",
                              "    using System.Data;",
                              "",
                              "    return DataRowState.Added.ToString();",
                              "< object",
                              ""
            });

            rs.sortReplies();

            var result = rs.reply("show data enum");

            Assert.AreEqual("enum is: Added", result);
        }
        public void Hello_World_Simple_Code()
        {
            var rs = new RiveScript();
            var oh = new CSharp();

            oh.onLoad("test", new string[] { "return \"Hello world\"; " });

            var result = oh.onCall("test", rs, new string[] { "" });

            Assert.AreEqual("Hello world", result);
        }
        public void Simple_Random_Reply_Alternative_Syntax()
        {
            var rs = new RiveScript();

            rs.streamForTest(new[] { "+ hello bot",
                                     "- {random}Hello|Hi|Hello human{/random}"});

            var reply = rs.reply("hello bot");

            Assert.IsTrue(new[] { "Hello",
                                  "Hi",
                                  "Hello human" }.Contains(reply));
        }
        public void Reply_Concatenet_Args_Id()
        {
            var rs = new RiveScript();
            var oh = new CSharp();

            oh.onLoad("test", new string[] { "return String.Join(\",\", args); " });

            var result = oh.onCall("test", rs, new string[] { "1", "2", "3" });

            Assert.AreEqual("1,2,3", result);
        }
        public void Reply_CurrentUser_Not_Initialized()
        {
            var rs = new RiveScript();
            var oh = new CSharp();

            oh.onLoad("test", new string[] { "return rs.currentUser();" });

            var result = oh.onCall("test", rs, new string[] { "" });

            Assert.AreEqual(Constants.Undefined, result);
        }
        public void Simple_Random_Word_Start()
        {
            var rs = new RiveScript();

            rs.streamForTest(new[] { "+ hello bot",
                                     "- {random}Good|Best{/random} day"});

            var reply = rs.reply("hello bot");

            Assert.IsTrue(new[] { "Good day",
                                  "Best day" }.Contains(reply));
        }
        public void Simple_Random_Word_Middle()
        {
            var rs = new RiveScript();

            rs.streamForTest(new[] { "+ hello bot",
                                     "- Hello {random}good|best{/random} day"});

            var reply = rs.reply("hello bot");

            Assert.IsTrue(new[] { "Hello good day",
                                  "Hello best day" }.Contains(reply));
        }
        public void Simple_Random_Word_End()
        {
            var rs = new RiveScript();

            rs.streamForTest(new[] { "+ hello bot",
                                     "- Good {random}day|night{/random}"});

            var reply = rs.reply("hello bot");

            Assert.IsTrue(new[] { "Good day",
                                  "Good night" }.Contains(reply));
        }
        private RiveScript getWithGlobalTopic(string[] code)
        {
            var rs = new RiveScript(true);
            rs.stream(new[] { "+ go topic *",
                              "- {topic=<star>}ok",
                              "> topic global",
                              "	+ global trigger",
                              "	- global reply",
                              "< topic",
                              "",
                              "> topic global1",
                              "	+ *",
                              "	- global1 reply",
                              "< topic",
                              ""});

            rs.stream(code);
            rs.sortReplies();
            return rs;
        }
        public void Reply_RS_Instance()
        {
            var rs = new RiveScript();
            var oh = new CSharp();

            oh.onLoad("test", new string[] { "return rs.GetHashCode().ToString(); " });

            var result = oh.onCall("test", rs, new string[] { "" });

            Assert.AreEqual(rs.GetHashCode().ToString(), result);
        }
        public void Execute_Object_Call_Entry_Assembly_Without_Explicit_Reference()
        {
            //Mock entry assembly for test envirioment
            ContextHelper.SetEntryAssembly(typeof(CSharpObjectHandlerTest).Assembly);

            var rs = new RiveScript();
            rs.setHandler("csharp", new CSharp());
            rs.stream(new[] { "",
                              "",
                              "",
                              "+ show context data",
                              "- data is: <call>context</call>",
                              "",
                              "> object context csharp",
                              "",
                              "    using RiveScript.Tests.Helper;",
                              "",
                              "    return ContextHelper.Property;",
                              "< object",
                              ""
            });

            rs.sortReplies();

            rs.reply("show context data")
              .AssertAreEqual("data is: Context_Property");
        }
Ejemplo n.º 30
0
        public void Load_Stream_Single_String()
        {
            var rs = new RiveScript(true);

            var result = rs.stream("+ hello bot\n - Hello human!");
            Assert.IsTrue(result);

            rs.sortReplies();

            rs.reply("hello bot").AssertAreEqual("Hello human!");
        }
Ejemplo n.º 31
0
        public static RiveScript getStreamed(string[] code)
        {
            var rs = new RiveScript(debug: false);

            //Stram bais variables for teste suite
            rs.stream(new[] { "// Bot Variables",
                              "! var name     = RiveScript Test Bot",
                              "! var age      = 9000",
                              "! var gender   = androgynous",
                              "! var location = Cyberspace",
                              "! var phone    = 555-1234",
                              "! var email    = [email protected]",
                              "// Substitutions",
                              "! sub +         = plus",
                              "! sub -         = minus",
                              "! sub /         = divided",
                              "! sub *         = times",
                              "! sub i'm       = i am",
                              "! sub i'd       = i would",
                              "! sub i've      = i have",
                              "! sub i'll      = i will",
                              "! sub don't     = do not",
                              "! sub isn't     = is not",
                              "! sub you'd     = you would",
                              "! sub you're    = you are",
                              "! sub you've    = you have",
                              "! sub you'll    = you will",
                              "! sub he'd      = he would",
                              "! sub he's      = he is",
                              "! sub he'll     = he will",
                              "! sub she'd     = she would",
                              "! sub she's     = she is",
                              "! sub she'll    = she will",
                              "! sub they'd    = they would",
                              "! sub they're   = they are",
                              "! sub they've   = they have",
                              "! sub they'll   = they will",
                              "! sub we'd      = we would",
                              "! sub we're     = we are",
                              "! sub we've     = we have",
                              "! sub we'll     = we will",
                              "! sub whats     = what is",
                              "! sub what's    = what is",
                              "! sub what're   = what are",
                              "! sub what've   = what have",
                              "! sub what'll   = what will",
                              "! sub can't     = can not",
                              "! sub whos      = who is",
                              "! sub who's     = who is",
                              "! sub who'd     = who would",
                              "! sub who'll    = who will",
                              "! sub don't     = do not",
                              "! sub didn't    = did not",
                              "! sub it's      = it is",
                              "! sub could've  = could have",
                              "! sub couldn't  = could not",
                              "! sub should've = should have",
                              "! sub shouldn't = should not",
                              "! sub would've  = would have",
                              "! sub wouldn't  = would not",
                              "! sub when's    = when is",
                              "! sub when're   = when are",
                              "! sub when'd    = when did",
                              "! sub y         = why",
                              "! sub u         = you",
                              "! sub ur        = your",
                              "! sub r         = are",
                              "! sub im        = i am",
                              "! sub wat       = what",
                              "! sub wats      = what is",
                              "! sub ohh       = oh",
                              "! sub becuse    = because",
                              "! sub becasue   = because",
                              "! sub becuase   = because",
                              "! sub practise  = practice",
                              "! sub its a     = it is a",
                              "! sub fav       = favorite",
                              "! sub fave      = favorite",
                              "! sub iam       = i am",
                              "! sub realy     = really",
                              "! sub iamusing  = i am using",
                              "! sub amleaving = am leaving",
                              "! sub yuo       = you",
                              "! sub youre     = you are",
                              "! sub didnt     = did not",
                              "! sub ain't     = is not",
                              "! sub aint      = is not",
                              "! sub wanna     = want to",
                              "! sub brb       = be right back",
                              "! sub bbl       = be back later",
                              "! sub gtg       = got to go",
                              "! sub g2g       = got to go",
                              "",
                              "// Person substitutions",
                              "! person i am    = you are",
                              "! person you are = I am",
                              "! person i'm     = you're",
                              "! person you're  = I'm",
                              "! person my      = your",
                              "! person your    = my",
                              "! person you     = I",
                              "! person i       = you",
                              "",
                              "// Arrays",
                              "! array colors = red green blue cyan yellow magenta white orange brown black",
                              "  ^ gray grey fuchsia maroon burgundy lime navy aqua gold silver copper bronze",
                              "  ^ light red|light green|light blue|light cyan|light yellow|light magenta",
                              "! array be     = is are was were",
                              "" });



            rs.setDebug(true);
            rs.stream(code);
            rs.sortReplies();
            return(rs);
        }