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 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() { var rs = new RiveScript(); rs.streamForTest(new[] { "+ my name is *", "- <set name=<formal>>Nice to meet you, <get name>", "", "+ hello bot", "* <get name> != undefined => {random}", "^ Hello there, <get name>.|", "^ Hey, <get name>.{/random}", "- Hello there!", "- Hi there", }); //Without name rs.reply("hello bot") .AssertContains("Hello there!", "Hi there"); //Set name rs.reply("my name is John") .AssertAreEqual("Nice to meet you, John"); rs.reply("hello bot") .AssertContains("Hello there, John.", "Hey, John."); }
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"); }
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 }
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 }
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 }
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 }
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?"); }
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 CurrentUser_Is_ThreadSafe_On_Macro() { var rs = new RiveScript(debug: true); rs.stream(@"+ trigger - <call>currentuser</call> > object currentuser csharp return rs.currentUser(); < object"); rs.sortReplies(); Action action = () => { var threadid = Thread.CurrentThread.ManagedThreadId.ToString(); var reply = rs.reply(threadid, "trigger"); Assert.AreEqual(threadid, reply); }; Parallel.Invoke(action, action, action); }
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"); }
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?"); }
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"); }
public void RSTS_Unicode__unicode() { var rs = new RiveScript(debug: true, utf8: true); rs.stream(new[] { "! sub who's = who is", "+ äh", "- What's the matter?", "+ ブラッキー", "- エーフィ", "// Make sure %Previous continues working in UTF-8 mode.", "+ knock knock", "- Who's there?", "+ *", "% who is there", "- <sentence> who?", "+ *", "% * who", "- Haha! <sentence>!", "// And with UTF-8.", "+ tëll më ä pöëm", "- Thërë öncë wäs ä män nämëd Tïm", "+ more", "% thërë öncë wäs ä män nämëd tïm", "- Whö nëvër qüïtë lëärnëd höw tö swïm", "+ more", "% whö nëvër qüïtë lëärnëd höw tö swïm", "- Hë fëll öff ä döck, änd sänk lïkë ä röck", "+ more", "% hë fëll öff ä döck änd sänk lïkë ä röck", "- Änd thät wäs thë ënd öf hïm." }); rs.sortReplies(); rs.reply("äh").AssertAreEqual("What's the matter?"); rs.reply("ブラッキー").AssertAreEqual("エーフィ"); rs.reply("knock knock").AssertAreEqual("Who's there?"); rs.reply("orange").AssertAreEqual("Orange who?"); rs.reply("banana").AssertAreEqual("Haha! Banana!"); rs.reply("tëll më ä pöëm").AssertAreEqual("Thërë öncë wäs ä män nämëd Tïm"); rs.reply("more").AssertAreEqual("Whö nëvër qüïtë lëärnëd höw tö swïm"); rs.reply("more").AssertAreEqual("Hë fëll öff ä döck, änd sänk lïkë ä röck"); rs.reply("more").AssertAreEqual("Änd thät wäs thë ënd öf hïm."); }
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 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"); }
public void RSTS_Unicode__wildcard() { var rs = new RiveScript(debug: true, utf8: true); rs.stream(new[] { "+ my name is _", "- Nice to meet you, <star>.", "+ i am # years old", "- A lot of people are <star> years old.", "+ *", "- No match." }); rs.sortReplies(); rs.reply("My name is Aiden").AssertAreEqual("Nice to meet you, aiden."); rs.reply("My name is Bảo").AssertAreEqual("Nice to meet you, bảo."); rs.reply("My name is 5").AssertAreEqual("No match."); rs.reply("I am five years old").AssertAreEqual("No match."); rs.reply("I am 5 years old").AssertAreEqual("A lot of people are 5 years old."); }
public void RSTS_Substitutions__person_substitutions() { var rs = new RiveScript(debug: true); rs.stream(new[] { "+ say *", "- <person>" }); rs.sortReplies(); rs.reply("say I am cool").AssertAreEqual("i am cool"); rs.reply("say You are dumb").AssertAreEqual("you are dumb"); rs.stream(new[] { "! person i am = you are", "! person you are = I am" }); rs.sortReplies(); rs.reply("say I am cool").AssertAreEqual("you are cool"); rs.reply("say You are dumb").AssertAreEqual("I am dumb"); }
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!"); }
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)); }
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_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 RSTS_Substitutions__message_substitutions() { var rs = new RiveScript(debug: true); rs.stream(new[] { "+ whats up", "- nm.", "+ what is up", "- Not much." }); rs.sortReplies(); rs.reply("whats up").AssertAreEqual("nm."); rs.reply("what's up?").AssertAreEqual("nm."); rs.reply("what is up?").AssertAreEqual("Not much."); rs.stream(new[] { "! sub whats = what is", "! sub what's = what is" }); rs.sortReplies(); rs.reply("whats up").AssertAreEqual("Not much."); rs.reply("what's up?").AssertAreEqual("Not much."); rs.reply("what is up?").AssertAreEqual("Not much."); }
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 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 Previous_Replies() { var rs = new RiveScript(debug: true); rs.stream(@"!sub who's = who is ! sub it's = it is ! sub didn't = did not + knock knock - Who's there? + * % who is there - <sentence> who? + * % * who - Haha! <sentence>! + * - I don't know."); rs.sortReplies(); rs.reply(USER_1, "knock knock").AssertAreEqual("Who's there?"); rs.reply(USER_2, "Canoe").AssertAreEqual("I don't know."); rs.reply(USER_1, "Canoe").AssertAreEqual("Canoe who?"); rs.reply(USER_1, "Canoe reply").AssertAreEqual("Haha! Canoe reply!"); rs.reply(USER_2, "Canoe reply").AssertAreEqual("I don't know."); rs.reply(USER_2, "knock knock").AssertAreEqual("Who's there?"); rs.reply(USER_1, "Canoe").AssertAreEqual("I don't know."); rs.reply(USER_2, "Canoe").AssertAreEqual("Canoe who?"); rs.reply(USER_1, "Canoe reply").AssertAreEqual("I don't know."); }
public void ClientManager_Is_ThreadSafe() { var rs = new RiveScript(debug: true); rs.stream(@"+ trigger - <call>currentuser</call> > object currentuser csharp return rs.currentUser(); < object"); rs.sortReplies(); Action action = () => rs.reply(Thread.CurrentThread.ManagedThreadId.ToString(), "trigger"); Parallel.Invoke(action, action, action, action, action, action, action, action); }
public void RSTS_Options__concat() { //# The concat option is file scoped and doesn't persist across streams. var rs = new RiveScript(debug: true); rs.stream(new[] { "// Default concat mode = none", "+ test concat default", "- Hello", "^ world!", "! local concat = space", "+ test concat space", "- Hello", "^ world!", "! local concat = none", "+ test concat none", "- Hello", "^ world!", "! local concat = newline", "+ test concat newline", "- Hello", "^ world!", "// invalid concat setting is equivalent to 'none'", "! local concat = foobar", "+ test concat foobar", "- Hello", "^ world!", "// the option is file scoped so it can be left at", "// any setting and won't affect subsequent parses", "! local concat = newline" }); rs.stream(new[] { "// concat mode should be restored to the default in a", "// separate file/stream parse", "+ test concat second file", "- Hello", "^ world!" }); rs.sortReplies(); rs.reply("test concat default").AssertAreEqual("Helloworld!"); rs.reply("test concat space").AssertAreEqual("Hello world!"); rs.reply("test concat none").AssertAreEqual("Helloworld!"); rs.reply("test concat newline").AssertAreEqual("Hello\nworld!"); rs.reply("test concat foobar").AssertAreEqual("Helloworld!"); rs.reply("test concat second file").AssertAreEqual("Helloworld!"); }
public void Optional_Start_End_Partial_Middle_Alternation() { var rs = new RiveScript(true); rs.stream(new[] { "+ [*] when is your (birthday|bday) [*]", "", "- reply", "" }); rs.sortReplies(); rs.reply("when is your birthday").AssertAreEqual("reply"); rs.reply("tell when is your birthday").AssertAreEqual("reply"); rs.reply("when is your birthday please").AssertAreEqual("reply"); rs.reply("tell when is your birthday please").AssertAreEqual("reply"); rs.reply("when is your bday").AssertAreEqual("reply"); rs.reply("tell when is your bday").AssertAreEqual("reply"); rs.reply("when is your bday please").AssertAreEqual("reply"); rs.reply("tell when is your bday please").AssertAreEqual("reply"); }
public void Execute_Full_Object_Call_Without_Parameter() { var rs = new RiveScript(); 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.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_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_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 Substitutio_Rot13_Problem_Load_With_Duscott_Files() { var rs = new RiveScript(true); var loaded = false; loaded = rs.loadFile("issue-4-rot13/begin.rive"); Assert.IsTrue(loaded); loaded = rs.loadFile("issue-4-rot13/main.rive"); Assert.IsTrue(loaded); rs.setDebug(true); rs.sortReplies(); var reply = rs.reply(USER, "he's an idiot"); Assert.IsTrue(rs.IsErrReply(reply)); }
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 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)); }
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_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_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)); }