From 6ec585a57e073ae218fd1adb33d6c0aa9afecc86 Mon Sep 17 00:00:00 2001 From: Jonathon Manning Date: Sat, 20 Feb 2016 11:52:55 +1100 Subject: [PATCH 1/3] Convert unit tests to use nunitlite --- .travis.yml | 5 ++--- YarnSpinner.sln | 12 ++++++------ YarnSpinnerTests/Program.cs | 15 +++++++++++++++ YarnSpinnerTests/Test.cs | 14 ++++++++++++-- YarnSpinnerTests/YarnSpinnerTests.csproj | 14 ++++++++++++-- YarnSpinnerTests/packages.config | 1 + run-unit-tests.sh | 4 ++++ 7 files changed, 52 insertions(+), 13 deletions(-) create mode 100644 YarnSpinnerTests/Program.cs create mode 100755 run-unit-tests.sh diff --git a/.travis.yml b/.travis.yml index 5c1479b3a..84225e75e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,8 +2,7 @@ language: csharp solution: YarnSpinner.sln install: - nuget restore YarnSpinner.sln - - nuget install NUnit.Runners -Version 3.0.1 -OutputDirectory testrunner -script: +script: - xbuild /p:Configuration=Release YarnSpinner.sln - - mono ./testrunner/NUnit.Console.3.0.1/tools/nunit3-console.exe ./YarnSpinnerTests/bin/Release/YarnSpinnerTests.dll + - mono ./YarnSpinnerTests/bin/Release/YarnSpinnerTests.exe - ./run-tests.sh \ No newline at end of file diff --git a/YarnSpinner.sln b/YarnSpinner.sln index 3d1925181..61d846f66 100644 --- a/YarnSpinner.sln +++ b/YarnSpinner.sln @@ -1,7 +1,7 @@ - + Microsoft Visual Studio Solution File, Format Version 11.00 # Visual Studio 2010 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "YarnSpinnerConsole", "YarnSpinnerConsole\YarnSpinnerConsole.csproj", "{858816BE-870C-40A8-BC22-8EDA51E2F339}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "YarnSpinnerConsole", "YarnSpinnerConsole\YarnSpinnerConsole.csproj", "{20B32C04-790E-4A50-BF32-20EA5C3CB0E2}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{7A162B42-C144-4C15-9ABC-BE5898622C32}" EndProject @@ -15,6 +15,10 @@ Global Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution + {20B32C04-790E-4A50-BF32-20EA5C3CB0E2}.Debug|x86.ActiveCfg = Debug|x86 + {20B32C04-790E-4A50-BF32-20EA5C3CB0E2}.Debug|x86.Build.0 = Debug|x86 + {20B32C04-790E-4A50-BF32-20EA5C3CB0E2}.Release|x86.ActiveCfg = Release|x86 + {20B32C04-790E-4A50-BF32-20EA5C3CB0E2}.Release|x86.Build.0 = Release|x86 {24F90A1D-B1CA-4E0F-8BD2-A91D8B443855}.Debug|x86.ActiveCfg = Debug|Any CPU {24F90A1D-B1CA-4E0F-8BD2-A91D8B443855}.Debug|x86.Build.0 = Debug|Any CPU {24F90A1D-B1CA-4E0F-8BD2-A91D8B443855}.Release|x86.ActiveCfg = Release|Any CPU @@ -23,10 +27,6 @@ Global {6C3B03D2-2E89-4EC3-A022-E84053A7B17F}.Debug|x86.Build.0 = Debug|Any CPU {6C3B03D2-2E89-4EC3-A022-E84053A7B17F}.Release|x86.ActiveCfg = Release|Any CPU {6C3B03D2-2E89-4EC3-A022-E84053A7B17F}.Release|x86.Build.0 = Release|Any CPU - {858816BE-870C-40A8-BC22-8EDA51E2F339}.Debug|x86.ActiveCfg = Debug|x86 - {858816BE-870C-40A8-BC22-8EDA51E2F339}.Debug|x86.Build.0 = Debug|x86 - {858816BE-870C-40A8-BC22-8EDA51E2F339}.Release|x86.ActiveCfg = Release|x86 - {858816BE-870C-40A8-BC22-8EDA51E2F339}.Release|x86.Build.0 = Release|x86 EndGlobalSection GlobalSection(NestedProjects) = preSolution EndGlobalSection diff --git a/YarnSpinnerTests/Program.cs b/YarnSpinnerTests/Program.cs new file mode 100644 index 000000000..f5f17fa6b --- /dev/null +++ b/YarnSpinnerTests/Program.cs @@ -0,0 +1,15 @@ +using NUnitLite; +using System; + +namespace YarnSpinner.Tests +{ + public class Program + { + + public static void Main(string[] args) + { + + new AutoRun().Execute(args); + } + } +} \ No newline at end of file diff --git a/YarnSpinnerTests/Test.cs b/YarnSpinnerTests/Test.cs index 6cfca431d..7419445a4 100644 --- a/YarnSpinnerTests/Test.cs +++ b/YarnSpinnerTests/Test.cs @@ -1,8 +1,10 @@ using NUnit.Framework; using System; -namespace YarnSpinnerTests +namespace YarnSpinner.Tests { + + [TestFixture ()] public class Test { @@ -13,6 +15,13 @@ public class Test [SetUp()] public void Init() { + + if (TestContext.CurrentContext.TestDirectory == Environment.CurrentDirectory) { + // Hop up to the folder that contains the Tests folder + var topLevelPath = System.IO.Path.Combine(Environment.CurrentDirectory, "..", "..", ".."); + Environment.CurrentDirectory = topLevelPath; + } + var newWorkingDir = System.IO.Path.Combine (Environment.CurrentDirectory, "Tests"); Environment.CurrentDirectory = newWorkingDir; @@ -40,7 +49,8 @@ public void Init() [Test ()] public void TestNodeExists () { - + + dialogue.LoadFile ("Ship.json"); dialogue.Compile (); diff --git a/YarnSpinnerTests/YarnSpinnerTests.csproj b/YarnSpinnerTests/YarnSpinnerTests.csproj index 8f5e78f6c..020176e4c 100644 --- a/YarnSpinnerTests/YarnSpinnerTests.csproj +++ b/YarnSpinnerTests/YarnSpinnerTests.csproj @@ -6,11 +6,12 @@ 8.0.30703 2.0 {24F90A1D-B1CA-4E0F-8BD2-A91D8B443855} - Library + Exe YarnSpinnerTests YarnSpinnerTests v4.5 0.9 + YarnSpinner.Tests.Program true @@ -20,7 +21,12 @@ DEBUG; prompt 4 - false + true + + + + + full @@ -35,9 +41,13 @@ ..\packages\NUnit.3.0.1\lib\net45\nunit.framework.dll + + ..\packages\NUnitLite.3.0.1\lib\net45\nunitlite.dll + + diff --git a/YarnSpinnerTests/packages.config b/YarnSpinnerTests/packages.config index b183023e1..e90d09551 100644 --- a/YarnSpinnerTests/packages.config +++ b/YarnSpinnerTests/packages.config @@ -1,4 +1,5 @@  + \ No newline at end of file diff --git a/run-unit-tests.sh b/run-unit-tests.sh new file mode 100755 index 000000000..d63eb8bdf --- /dev/null +++ b/run-unit-tests.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +xbuild /verbosity:quiet /p:Configuration=Release YarnSpinner.sln +mono ./YarnSpinnerTests/bin/Release/YarnSpinnerTests.exe From 9777042357e073818d01e5f8fd7957cf9ea0005f Mon Sep 17 00:00:00 2001 From: Jonathon Manning Date: Sat, 20 Feb 2016 14:54:24 +1100 Subject: [PATCH 2/3] Limit the set of tokens that will be matched when scanning plain text. Fixes #17. --- YarnSpinner/Lexer.cs | 132 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 121 insertions(+), 11 deletions(-) diff --git a/YarnSpinner/Lexer.cs b/YarnSpinner/Lexer.cs index 24a50cd28..a0956f927 100644 --- a/YarnSpinner/Lexer.cs +++ b/YarnSpinner/Lexer.cs @@ -165,6 +165,26 @@ internal class Tokeniser { // A defined rule for matching a type of token public class TokenRule { + + public enum FreeTextMode { + Begins, + Ends, + DoNotMatch, + AllowMatch + } + + public delegate bool FreeTextModeException( TokenList tokens ); + + // If the tokenizer is in free text mode and this token would normally + // not be matched (ie FreeTextMode == .DoNotMatch), an exception is made + // if this function returns true. + // This exists to allow tokens to make context-sensitive choices, such as + // allowing OptionDelimit to be matched but only if we started an OptionStart + // two tokens ago. + // TODO: I can see this slowly turning into a headache. Is there a better way + // around this problem? + public FreeTextModeException freeTextModeException; + public TokenType type; // what token is this rule for? public Regex regex; // what should we look for? public bool discard; // should we throw away this token if we match it? @@ -182,6 +202,12 @@ public class TokenRule { // of the line - which means that tokens like "and" will not be interpreted. public bool resetsLine; + // Free text mode means that only certain tokens are matched. It's + // begun when a token is matched whose freeTextMode is Begins, and ends when + // a token is matched whose freeTextMode is Ends (typically '<<' and newlines) + // When in free text mode, token rules that are DoNotMatch are not used. + public FreeTextMode freeTextMode; + public override string ToString () { return string.Format ("TokenRule: {0}", type.ToString()); @@ -224,7 +250,12 @@ public Tokeniser() { } // Define a new token rule, with a name and an optional rule - public TokenRule AddTokenRule(TokenType type, string rule, bool canBeginLine = false, bool resetsLine = false, bool requiresFollowingWhitespace=false) { + public TokenRule AddTokenRule(TokenType type, string rule, + bool canBeginLine = false, + bool resetsLine = false, + bool requiresFollowingWhitespace=false, + TokenRule.FreeTextMode freeTextMode = TokenRule.FreeTextMode.DoNotMatch + ) { var newTokenRule = new TokenRule(); newTokenRule.type = type; @@ -242,12 +273,15 @@ public TokenRule AddTokenRule(TokenType type, string rule, bool canBeginLine = f } newTokenRule.resetsLine = resetsLine; newTokenRule.canBeginLine = canBeginLine; + + newTokenRule.freeTextMode = freeTextMode; // Store it in the list and return tokenRules.Add(newTokenRule); return newTokenRule; } + // Given an input string, parse it and return the list of tokens public TokenList Tokenise(string context, string input) { @@ -330,7 +364,9 @@ private TokenList TokeniseLine(string context, string input, out int lineIndenta // Replace tabs with four spaces input = input.Replace ("\t", " "); - + + bool freeTextMode = false; + // Find any whitespace at the start of a line var initialIndentRule = new Regex("^\\s+"); @@ -377,6 +413,29 @@ private TokenList TokeniseLine(string context, string input, out int lineIndenta continue; } + // Bail out if this match was zero-length + if (match.Length == 0) { + continue; + } + + switch (tokenRule.freeTextMode) { + case TokenRule.FreeTextMode.Begins: + freeTextMode = true; + break; + case TokenRule.FreeTextMode.Ends: + freeTextMode = false; + break; + case TokenRule.FreeTextMode.DoNotMatch: + if (freeTextMode == true) { + // Do not match, UNLESS we should make an exception + if (tokenRule.freeTextModeException == null || + tokenRule.freeTextModeException(tokens) == false) { + continue; + } + } + break; + } + // Record the token only if we care // about it (ie it's not whitespace) if (tokenRule.discard == false) { @@ -437,12 +496,40 @@ private TokenList TokeniseLine(string context, string input, out int lineIndenta if (matched == false) { // We've exhausted the list of possible token types, so we've // failed to interpret this string! Bail out! + throw new InvalidOperationException("Failed to interpret token " + input); } } - + + // Merge multiple runs of text on the same line + var tokensToReturn = new TokenList(); + + foreach (var token in tokens) { + + Token lastToken = null; + + // Did we previously add a token? + if (tokensToReturn.Count > 0) { + lastToken = tokensToReturn [tokensToReturn.Count - 1]; + } + + // Was the last token in tokensToReturn a Text, AND + // this token is a Text? + if (lastToken != null && + lastToken.type == TokenType.Text && + token.type == TokenType.Text) { + + // Merge the texts! + var str = (string)tokensToReturn[tokensToReturn.Count - 1].value; + str += (string)token.value; + lastToken.value = str; + } else { + tokensToReturn.Add (token); + } + } + // Return the list of tokens we found - return tokens; + return tokensToReturn; } // Prepare the regex rules for each possible token. @@ -466,15 +553,15 @@ private void PrepareTokenRules() { .discard = true; // Set up the end-of-file token - AddTokenRule(TokenType.EndOfInput, null); + AddTokenRule(TokenType.EndOfInput, null, freeTextMode:TokenRule.FreeTextMode.Ends); // Comments - AddTokenRule (TokenType.Comment, @"\/\/.*", canBeginLine: true) + AddTokenRule (TokenType.Comment, @"\/\/.*", canBeginLine: true, freeTextMode: TokenRule.FreeTextMode.AllowMatch) .discard = true; // Basic syntax AddTokenRule(TokenType.Number, @"((?\>"); AddTokenRule(TokenType.Variable, @"\$([A-z\d])+"); @@ -484,8 +571,31 @@ private void PrepareTokenRules() { // Options AddTokenRule(TokenType.ShortcutOption, @"-\>", canBeginLine:true, resetsLine:true); AddTokenRule(TokenType.OptionStart, @"\[\[", canBeginLine:true, resetsLine:true); - AddTokenRule(TokenType.OptionDelimit, @"\|"); - AddTokenRule(TokenType.OptionEnd, @"\]\]"); + AddTokenRule (TokenType.OptionDelimit, @"\|").freeTextModeException = delegate(TokenList tokens) { + if (tokens.Count < 2) + return false; + + // permitted in free text mode when we saw an OptionStart two tokens ago + switch (tokens [tokens.Count - 2].type) { + case TokenType.OptionStart: + return true; + default: + return false; + } + }; + AddTokenRule(TokenType.OptionEnd, @"\]\]").freeTextModeException = delegate(TokenList tokens) { + if (tokens.Count < 2) + return false; + + // permitted in free text mode when we saw either an OptionDelimit or an OptionStart two tokens ago + switch (tokens [tokens.Count - 2].type) { + case TokenType.OptionStart: + case TokenType.OptionDelimit: + return true; + default: + return false; + } + }; // Reserved words AddTokenRule(TokenType.If, "if"); @@ -541,10 +651,10 @@ private void PrepareTokenRules() { // Commas for separating function parameters AddTokenRule (TokenType.Comma, ","); - // Free text - match anything except command or option syntax + // Free text - match anything except BeginCommand, OptionsDelimit or OptionsEnd // This always goes last so that anything else will preferably // match it - AddTokenRule(TokenType.Text, @"[^\<\>\[\]\|]*", canBeginLine:true); + AddTokenRule(TokenType.Text, @"(\||\<\<|\]\])*(?:(?!\<\<|\||\]\]).)*", canBeginLine:true, freeTextMode: TokenRule.FreeTextMode.Begins); } } } From 62b522df8762e89aac20d3864e473ed9801f7a51 Mon Sep 17 00:00:00 2001 From: Jonathon Manning Date: Sat, 20 Feb 2016 14:55:42 +1100 Subject: [PATCH 3/3] Update test cases, and improve test framework. --- Tests/Ship.json | 42 ---------- Tests/Space.json | 52 ++++++++++++ Tests/TestCases/SingleLine.node | 2 + Tests/TestCases/Smileys.node | 79 +++++++++++++++++++ YarnSpinnerConsole/Main.cs | 16 ++++ .../YarnSpinnerConsole.csproj.orig | 58 ++++++++++++++ YarnSpinnerTests/Test.cs | 33 ++++++-- YarnSpinnerTests/YarnSpinnerTests.csproj | 2 +- run-tests.sh | 2 +- run-unit-tests.sh | 2 +- 10 files changed, 235 insertions(+), 53 deletions(-) delete mode 100644 Tests/Ship.json create mode 100644 Tests/Space.json create mode 100644 Tests/TestCases/Smileys.node create mode 100644 YarnSpinnerConsole/YarnSpinnerConsole.csproj.orig diff --git a/Tests/Ship.json b/Tests/Ship.json deleted file mode 100644 index 283df7295..000000000 --- a/Tests/Ship.json +++ /dev/null @@ -1,42 +0,0 @@ -[ - { - "title": "Sally", - "tags": "", - "body": "<>\nPlayer: Hey, Sally.\nSally: Oh! Hey.\nSally: You kind of snuck up on me.\nSally: Don't do that.\n<>\nPlayer: Hey.\nSally: Hi.\n<>\n\n<>\n[[Anything exciting happen on your watch?|Sally.Watch]]\n<>\n[[See you later.|Sally.Exit]]", - "position": { - "x": 271, - "y": 131 - }, - "colorID": 0 - }, - { - "title": "Sally.Watch", - "tags": "", - "body": "Sally: No, not really. \nSally: Same old nebula, doing the same old thing.\nSally: Oh, Ship did want to chat to you. Go say hi to it.\n<>\n<>\nPlayer: Already done!\nSally: Well, then.\n<>", - "position": { - "x": 359, - "y": 456 - }, - "colorID": 0 - }, - { - "title": "Sally.Exit", - "tags": "", - "body": "Sally: Bye.", - "position": { - "x": 58, - "y": 443 - }, - "colorID": 6 - }, - { - "title": "Ship", - "tags": "", - "body": "<>\n Ship: Hey, friend.\n Player: Hi, ship.\n Player: How's space?\n Ship: Oh, man.\n <>\n Ship: It's HUGE!\n <>\n<>\n <>\n Ship: Hey!!\n <>\n<>\n\n<>\nPlayer: Sally said you wanted to see me?\n<>\n", - "position": { - "x": 721, - "y": 135 - }, - "colorID": 0 - } -] \ No newline at end of file diff --git a/Tests/Space.json b/Tests/Space.json new file mode 100644 index 000000000..b5479902b --- /dev/null +++ b/Tests/Space.json @@ -0,0 +1,52 @@ +[ + { + "title": "Sally", + "tags": "", + "body": "<>\nPlayer: Hey, Sally.\nSally: Oh! Hi.\nSally: You snuck up on me.\nSally: Don't do that.\n<>\nPlayer: Hey.\nSally: Hi.\n<>\n\n<>\n[[Anything exciting happen on your watch?|Sally.Watch]]\n<>\n<>\n[[Sorry about the console.|Sally.Sorry]]\n<>\n[[See you later.|Sally.Exit]]", + "position": { + "x": 371, + "y": 137 + }, + "colorID": 0 + }, + { + "title": "Sally.Watch", + "tags": "", + "body": "Sally: Not really. \nSally: Same old nebula, doing the same old thing.\nSally: Oh, Ship wanted to see you. Go say hi to it.\n<>\n<>\nPlayer: Already done!\nSally: Go say hi again.\n<>", + "position": { + "x": 359, + "y": 456 + }, + "colorID": 0 + }, + { + "title": "Sally.Exit", + "tags": "", + "body": "Sally: Bye.", + "position": { + "x": 58, + "y": 443 + }, + "colorID": 6 + }, + { + "title": "Ship", + "tags": "", + "body": "<>\n Ship: Hey, friend.\n Player: Hi, Ship.\n Player: How's space?\n Ship: Oh, man.\n <>\n Ship: It's HUGE!\n <>\n<>\n <>\n Ship: Hey!!\n <>\n<>\n\n<>\nPlayer: Sally said you wanted to see me?\n<>\nShip: She totally did!!\n<>\nShip: She wanted me to tell you...\nShip: If you ever go off-watch without resetting the console again...\n<>\nShip: She'll flay you alive!\n<>\nPlayer: Uh.\n<>\n\n<>\n", + "position": { + "x": 721, + "y": 130 + }, + "colorID": 0 + }, + { + "title": "Sally.Sorry", + "tags": "", + "body": "Sally: Yeah. Don't do it again.", + "position": { + "x": 674, + "y": 465 + }, + "colorID": 0 + } +] \ No newline at end of file diff --git a/Tests/TestCases/SingleLine.node b/Tests/TestCases/SingleLine.node index 8c2127a5b..0fce8773b 100644 --- a/Tests/TestCases/SingleLine.node +++ b/Tests/TestCases/SingleLine.node @@ -1,5 +1,7 @@ // Tests a single line +<> + This is a single line of dialogue. <> \ No newline at end of file diff --git a/Tests/TestCases/Smileys.node b/Tests/TestCases/Smileys.node new file mode 100644 index 000000000..32aba2150 --- /dev/null +++ b/Tests/TestCases/Smileys.node @@ -0,0 +1,79 @@ +// Testing smileys + +Mae: ¯\_(ツ)_/¯ +Mae: +Mae: :| +Mae: :) +Mae: :( +Mae: :o +Mae: :\ +Mae: :< +Mae: D: +Mae: -_- +Mae: =_= +Mae: U_U +Mae: O_O +Mae: o_o +Mae: \o/ +Mae: /o\ +Mae: o/ +Mae: _o_ +Mae: o> +Mae: / \ +Mae: \ / +Mae: ~~ + +// Testing in an option group + + +<> + +-> Mae: ¯\_(ツ)_/¯ +-> Mae: +-> Mae: :| +-> Mae: :) +-> Mae: :( +-> Mae: :o +-> Mae: :\ +-> Mae: :< +-> Mae: D: +-> Mae: -_- +-> Mae: =_= +-> Mae: U_U +-> Mae: O_O +-> Mae: o_o +-> Mae: \o/ +-> Mae: /o\ +-> Mae: o/ +-> Mae: _o_ +-> Mae: o> +-> Mae: / \ +-> Mae: \ / +-> Mae: ~~ + +// Testing in an option group, with conditionals + +<> + +-> Mae: ¯\_(ツ)_/¯ <> +-> Mae: <> +-> Mae: :| <> +-> Mae: :) <> +-> Mae: :( <> +-> Mae: :o <> +-> Mae: :\ <> +-> Mae: :< <> +-> Mae: D: <> +-> Mae: -_- <> +-> Mae: =_= <> +-> Mae: U_U <> +-> Mae: O_O <> +-> Mae: o_o <> +-> Mae: \o/ <> +-> Mae: /o\ <> +-> Mae: o/ <> +-> Mae: _o_ <> +-> Mae: o> <> +-> Mae: / \ <> +-> Mae: \ / <> +-> Mae: ~~ <> diff --git a/YarnSpinnerConsole/Main.cs b/YarnSpinnerConsole/Main.cs index 98835491d..6245a3ff5 100644 --- a/YarnSpinnerConsole/Main.cs +++ b/YarnSpinnerConsole/Main.cs @@ -220,6 +220,10 @@ public static void Main (string[] args) impl.autoSelectOptionNumber = (int)parameters[1].AsNumber; }); + dialogue.library.RegisterFunction ("expect_line", 1, delegate(Value[] parameters) { + impl.expectedNextLine = parameters[0].AsString; + }); + // If debugging is enabled, log debug messages; otherwise, ignore them if (showDebugging) { dialogue.LogDebugMessage = delegate(string message) { @@ -289,6 +293,8 @@ private class ConsoleRunnerImplementation : Yarn.VariableStorage { // -1 means "do not automatically select an option". public int autoSelectOptionNumber = -1; + public string expectedNextLine = null; + public ConsoleRunnerImplementation(bool waitForLines = false) { this.variableStore = new MemoryVariableStore(); this.waitForLines = waitForLines; @@ -296,6 +302,16 @@ public ConsoleRunnerImplementation(bool waitForLines = false) { public void RunLine (Yarn.Line lineText) { + + if (expectedNextLine != null && expectedNextLine != lineText.text) { + // TODO: Output diagnostic info here + Console.WriteLine(string.Format("Unexpected line.\nExpected: {0}\nReceived: {1}", + expectedNextLine, lineText.text)); + Environment.Exit (1); + } + + expectedNextLine = null; + Console.WriteLine (lineText.text); if (waitForLines == true) { Console.Read(); diff --git a/YarnSpinnerConsole/YarnSpinnerConsole.csproj.orig b/YarnSpinnerConsole/YarnSpinnerConsole.csproj.orig new file mode 100644 index 000000000..c212e5889 --- /dev/null +++ b/YarnSpinnerConsole/YarnSpinnerConsole.csproj.orig @@ -0,0 +1,58 @@ + + + + Debug + x86 + 8.0.30703 + 2.0 + {20B32C04-790E-4A50-BF32-20EA5C3CB0E2} + Exe + Yarn + YarnSpinnerConsole + 0.9 + v4.5 + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + x86 +<<<<<<< HEAD + -c ../../../Tests/Compiler.node +======= + ../../../Tests/TestCases/SingleLine.node + false +>>>>>>> master + + + true + bin\Release + prompt + 4 + true + x86 + + + + + + + + + + + + + + + + + {6C3B03D2-2E89-4EC3-A022-E84053A7B17F} + YarnSpinner + + + \ No newline at end of file diff --git a/YarnSpinnerTests/Test.cs b/YarnSpinnerTests/Test.cs index 7419445a4..e7a92d90e 100644 --- a/YarnSpinnerTests/Test.cs +++ b/YarnSpinnerTests/Test.cs @@ -9,6 +9,8 @@ namespace YarnSpinner.Tests public class Test { + + Yarn.MemoryVariableStore storage = new Yarn.MemoryVariableStore(); Yarn.Dialogue dialogue; @@ -16,15 +18,18 @@ public class Test public void Init() { - if (TestContext.CurrentContext.TestDirectory == Environment.CurrentDirectory) { - // Hop up to the folder that contains the Tests folder - var topLevelPath = System.IO.Path.Combine(Environment.CurrentDirectory, "..", "..", ".."); - Environment.CurrentDirectory = topLevelPath; + if (System.IO.Path.GetFileName(Environment.CurrentDirectory) != "Tests") { + if (TestContext.CurrentContext.TestDirectory == Environment.CurrentDirectory) { + // Hop up to the folder that contains the Tests folder + var topLevelPath = System.IO.Path.Combine(Environment.CurrentDirectory, "..", "..", ".."); + Environment.CurrentDirectory = topLevelPath; + } + + var newWorkingDir = + System.IO.Path.Combine (Environment.CurrentDirectory, "Tests"); + Environment.CurrentDirectory = newWorkingDir; } - var newWorkingDir = - System.IO.Path.Combine (Environment.CurrentDirectory, "Tests"); - Environment.CurrentDirectory = newWorkingDir; dialogue = new Yarn.Dialogue (storage); @@ -44,6 +49,10 @@ public void Init() if (parameters[0].AsBool == false) Assert.Fail ("Assertion failed"); }); + + dialogue.library.RegisterFunction ("prepare_for_options", -1, delegate(Yarn.Value[] parameters) { + + }); } [Test ()] @@ -51,7 +60,7 @@ public void TestNodeExists () { - dialogue.LoadFile ("Ship.json"); + dialogue.LoadFile ("Space.json"); dialogue.Compile (); @@ -68,6 +77,14 @@ public void TestNodeExists () } + + [Test()] + public void TestParsingSmileys() + { + var path = System.IO.Path.Combine ("TestCases", "Smileys.node"); + dialogue.LoadFile (path); + dialogue.Compile (); + } } } diff --git a/YarnSpinnerTests/YarnSpinnerTests.csproj b/YarnSpinnerTests/YarnSpinnerTests.csproj index 020176e4c..872390b4f 100644 --- a/YarnSpinnerTests/YarnSpinnerTests.csproj +++ b/YarnSpinnerTests/YarnSpinnerTests.csproj @@ -34,7 +34,7 @@ bin\Release prompt 4 - false + true diff --git a/run-tests.sh b/run-tests.sh index 875873f90..f2244dd2f 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -10,7 +10,7 @@ for f in $TESTCASES_DIR/*.node; do ./parser.sh $f if [[ $? -ne 0 ]]; then - echo "*** ERROR ***" + echo "*** ERROR RUNNING $f ***" returncode=1 fi done diff --git a/run-unit-tests.sh b/run-unit-tests.sh index d63eb8bdf..a54dd369f 100755 --- a/run-unit-tests.sh +++ b/run-unit-tests.sh @@ -1,4 +1,4 @@ #!/usr/bin/env bash xbuild /verbosity:quiet /p:Configuration=Release YarnSpinner.sln -mono ./YarnSpinnerTests/bin/Release/YarnSpinnerTests.exe +mono ./YarnSpinnerTests/bin/Release/YarnSpinnerTests.exe $@