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 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_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"); }
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 Load_Same_Version_File() { var rs = new RiveScript(true); var result = rs.stream("! version = 2.0"); Assert.IsTrue(result); }
public void Load_Newer_Version_File() { var rs = new RiveScript(true); var result = rs.stream("! version = 2.1"); Assert.IsFalse(result); }
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 static RiveScript getEmptyStreamed(string[] code) { var rs = new RiveScript(debug: false); rs.setDebug(true); rs.stream(code); rs.sortReplies(); return(rs); }
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_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 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"); }
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 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 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 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_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.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 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 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 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 Execute_Full_Object_Call_Custom_References() { var rs = new RiveScript(); 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 static void streamForTest(this RiveScript rs, string[] code) { rs.setDebug(true); rs.stream(code); rs.sortReplies(); }
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 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); }