Skip to content

Commit

Permalink
Added String Interpolation tests
Browse files Browse the repository at this point in the history
Fixed issue nilproject#109 by including back-tick as a string delimiter
  • Loading branch information
jsobell committed Feb 26, 2018
1 parent a9390f6 commit f698692
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
1 change: 1 addition & 0 deletions FunctionalTests/FunctionalTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
</Compile>
<Compile Include="StringInterpolationTests.cs" />
<Compile Include="MemberAlias.cs" />
<Compile Include="JsFunfuzz.cs" />
<Compile Include="OverloadedMethods.cs" />
Expand Down
56 changes: 56 additions & 0 deletions FunctionalTests/StringInterpolationTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NiL.JS.Core;

namespace FunctionalTests
{
[TestClass]
public sealed class StringInterpolationTests
{
[TestMethod]
public void StringInterpolationAllowsStrings()
{
var context = new Context();
var code = @"`This is a string`";
var stringValue = context.Eval(code);

Assert.AreEqual("This is a string", stringValue.Value);
}

[TestMethod]
public void StringInterpolationAllowsSlashes()
{
var context = new Context();
var code = @"`This is a string such as http://www.google.com`";
var stringValue = context.Eval(code);
Assert.AreEqual("This is a string such as http://www.google.com", stringValue.Value);
}

[TestMethod]
public void StringAllowsSlashes()
{
var context = new Context();
var code = @"'This is a string such as http://www.google.com'";
var stringValue = context.Eval(code);
Assert.AreEqual("This is a string such as http://www.google.com", stringValue.Value);
}

[TestMethod]
public void StringAllowsSlashesDoubleQuoted()
{
var context = new Context();
var code = @"""This is a string such as http://www.google.com""";
var stringValue = context.Eval(code);
Assert.AreEqual("This is a string such as http://www.google.com", stringValue.Value);
}

[TestMethod]
public void StringInterpolationAllowsSubstititions()
{
var context = new Context();
var code = @"var a=1234; `This is a string such as ${a}`";
var stringValue = context.Eval(code);

Assert.AreEqual("This is a string such as 1234", stringValue.Value);
}
}
}
2 changes: 1 addition & 1 deletion NiL.JS/Core/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ public static bool ValidateRegex(string code, ref int index, bool throwError)
public static bool ValidateString(string code, ref int index, bool @throw)
{
int j = index;
if (j + 1 < code.Length && ((code[j] == '\'') || (code[j] == '"')))
if (j + 1 < code.Length && ((code[j] == '\'') || (code[j] == '"') || (code[j] == '`')))
{
char fchar = code[j];
j++;
Expand Down

0 comments on commit f698692

Please sign in to comment.