Skip to content

Commit cae800b

Browse files
committed
Added support of identifier names compliant with ECMAScript 5
1 parent 9cec6c5 commit cae800b

File tree

6 files changed

+93
-8
lines changed

6 files changed

+93
-8
lines changed

NuGet/JavaScriptEngineSwitcher.Core/JavaScriptEngineSwitcher.Core.nuspec

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
<requireLicenseAcceptance>false</requireLicenseAcceptance>
1313
<description>JavaScript Engine Switcher determines unified interface for access to the basic features of popular JavaScript engines (MSIE JavaScript Engine for .Net, Microsoft ClearScript.V8, Jurassic, Jint and ChakraCore). This library allows you to quickly and easily switch to using of another JavaScript engine.</description>
1414
<summary>JavaScript Engine Switcher determines unified interface for access to the basic features of popular JavaScript engines (MSIE JavaScript Engine for .Net, Microsoft ClearScript.V8, Jurassic, Jint and ChakraCore).</summary>
15-
<releaseNotes>1. Added support of .NET Core 1.0.4;
16-
2. In `IJsEngine` interface was added overloaded versions of the `Evaluate`, `Evaluate&lt;T&gt;` and `Execute` methods, which take the document name as second parameter.</releaseNotes>
15+
<releaseNotes>Added support of identifier names compliant with ECMAScript 5.</releaseNotes>
1716
<copyright>Copyright (c) 2013-2017 Andrey Taritsyn - http://www.taritsyn.ru</copyright>
1817
<language>en-US</language>
1918
<tags>JavaScriptEngineSwitcher JavaScript ECMAScript</tags>

NuGet/JavaScriptEngineSwitcher.Core/readme.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@
1919
=============
2020
RELEASE NOTES
2121
=============
22-
1. Added support of .NET Core 1.0.4;
23-
2. In `IJsEngine` interface was added overloaded versions of the `Evaluate`,
24-
`Evaluate<T>` and `Execute` methods, which take the document name as second
25-
parameter.
22+
Added support of identifier names compliant with ECMAScript 5.
2623

2724
=============
2825
DOCUMENTATION

src/JavaScriptEngineSwitcher.Core/Helpers/ValidationHelpers.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@ public static class ValidationHelpers
3232
};
3333

3434
/// <summary>
35-
/// Regular expression for working with JS-names
35+
/// Regular expression for working with JS names
3636
/// </summary>
37-
private static readonly Regex _jsNameRegex = new Regex(@"^[A-Za-z_\$][0-9A-Za-z_\$]*$");
37+
private static readonly Regex _jsNameRegex = new Regex(@"^[$_\p{Lu}\p{Ll}\p{Lt}\p{Lm}\p{Lo}\p{Nl}]" +
38+
@"[$_\p{Lu}\p{Ll}\p{Lt}\p{Lm}\p{Lo}\p{Nl}\u200C\u200D\p{Mn}\p{Mc}\p{Nd}\p{Pc}]*$");
3839

3940

4041
/// <summary>

test/JavaScriptEngineSwitcher.Tests.Net4/JavaScriptEngineSwitcher.Tests.Net40.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,9 @@
192192
<Compile Include="..\JavaScriptEngineSwitcher.Tests\V8\InteropTests.cs">
193193
<Link>V8\InteropTests.cs</Link>
194194
</Compile>
195+
<Compile Include="..\JavaScriptEngineSwitcher.Tests\ValidationTests.cs">
196+
<Link>ValidationTests.cs</Link>
197+
</Compile>
195198
<Compile Include="..\JavaScriptEngineSwitcher.Tests\Vroom\CommonTests.cs">
196199
<Link>Vroom\CommonTests.cs</Link>
197200
</Compile>

test/JavaScriptEngineSwitcher.Tests/CommonTestsBase.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,40 @@ public virtual void SettingAndGettingVariableWithUnicodeStringValueIsCorrect()
846846
Assert.Equal(input2, output2);
847847
}
848848

849+
[Fact]
850+
public virtual void SettingAndGettingVariableWithNameContainingUnicodeCharactersIsCorrect()
851+
{
852+
// Arrange
853+
const string variableName = "слово";
854+
855+
const string input1 = "Hip-hip Hooray";
856+
const string targetOutput1 = "Hip-hip Hooray!";
857+
858+
const string input2 = "Hip-hip Hurrah";
859+
860+
// Act
861+
bool variableExists;
862+
string output1;
863+
string output2;
864+
865+
using (var jsEngine = CreateJsEngine())
866+
{
867+
jsEngine.SetVariableValue(variableName, input1);
868+
variableExists = jsEngine.HasVariable(variableName);
869+
jsEngine.Execute(string.Format("{0} += '!';", variableName));
870+
output1 = jsEngine.GetVariableValue<string>(variableName);
871+
872+
jsEngine.SetVariableValue(variableName, input2);
873+
output2 = jsEngine.GetVariableValue<string>(variableName);
874+
}
875+
876+
// Assert
877+
Assert.True(variableExists);
878+
Assert.Equal(targetOutput1, output1);
879+
880+
Assert.Equal(input2, output2);
881+
}
882+
849883
[Fact]
850884
public virtual void RemovingVariableIsCorrect()
851885
{
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using Xunit;
2+
3+
using JavaScriptEngineSwitcher.Core.Helpers;
4+
5+
namespace JavaScriptEngineSwitcher.Tests
6+
{
7+
public class ValidationTests
8+
{
9+
[Fact]
10+
public void NameFormatIsCorrect()
11+
{
12+
// Arrange
13+
14+
// Act
15+
bool name1FormatIsCorrect = ValidationHelpers.CheckNameFormat("good_parts");
16+
bool name2FormatIsCorrect = ValidationHelpers.CheckNameFormat("i18n");
17+
bool name3FormatIsCorrect = ValidationHelpers.CheckNameFormat("fooBar");
18+
bool name4FormatIsCorrect = ValidationHelpers.CheckNameFormat("$grid");
19+
bool name5FormatIsCorrect = ValidationHelpers.CheckNameFormat("a");
20+
bool name6FormatIsCorrect = ValidationHelpers.CheckNameFormat("À_la_maison");
21+
22+
// Assert
23+
Assert.True(name1FormatIsCorrect);
24+
Assert.True(name2FormatIsCorrect);
25+
Assert.True(name3FormatIsCorrect);
26+
Assert.True(name4FormatIsCorrect);
27+
Assert.True(name5FormatIsCorrect);
28+
Assert.True(name6FormatIsCorrect);
29+
}
30+
31+
[Fact]
32+
public void NameFormatIsWrong()
33+
{
34+
// Arrange
35+
36+
// Act
37+
bool name1FormatIsCorrect = ValidationHelpers.CheckNameFormat("good-parts");
38+
bool name2FormatIsCorrect = ValidationHelpers.CheckNameFormat("1sale");
39+
bool name3FormatIsCorrect = ValidationHelpers.CheckNameFormat("Foo Bar");
40+
bool name4FormatIsCorrect = ValidationHelpers.CheckNameFormat("@grid");
41+
bool name5FormatIsCorrect = ValidationHelpers.CheckNameFormat("2");
42+
43+
// Assert
44+
Assert.False(name1FormatIsCorrect);
45+
Assert.False(name2FormatIsCorrect);
46+
Assert.False(name3FormatIsCorrect);
47+
Assert.False(name4FormatIsCorrect);
48+
Assert.False(name5FormatIsCorrect);
49+
}
50+
}
51+
}

0 commit comments

Comments
 (0)