Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some unicode tests #1033

Merged
merged 11 commits into from
Jan 2, 2022
82 changes: 75 additions & 7 deletions Jint.Tests.Test262/Test262Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,10 @@ public static IEnumerable<object[]> SourceFiles(string pathPrefix, bool skipped)
skip = true;
reason = "not in spec yet";
break;
case "u180e":
skip = true;
reason = "unicode/regexp not implemented";
break;
//case "u180e":
// skip = true;
// reason = "unicode/regexp not implemented";
// break;
case "regexp-match-indices":
skip = true;
reason = "regexp-match-indices not implemented";
Expand Down Expand Up @@ -323,18 +323,86 @@ public static IEnumerable<object[]> SourceFiles(string pathPrefix, bool skipped)
reason = "Esprima problem, Unexpected token *";
}

if (name.StartsWith("language/white-space/mongolian-vowel-separator-eval.js"))
sebastienros marked this conversation as resolved.
Show resolved Hide resolved
{
skip = true;
reason = "Esprima problem";
}

// Unicode regular expressions

if (name.StartsWith("built-ins/RegExp/property-escapes/generated/"))
{
skip = true;
reason = "Esprima problem, Invalid regular expression";
reason = "Esprima problem";
}

if (name.StartsWith("built-ins/RegExp/dotall/with-dotall-unicode.js"))
{
skip = true;
reason = "Esprima problem";
}

if (name.StartsWith("built-ins/RegExp/dotall/without-dotall.js"))
{
skip = true;
reason = "Esprima problem";
}

if (name.StartsWith("built-ins/RegExp/dotall/without-dotall-unicode.js"))
{
skip = true;
reason = "Esprima problem";
}

if (name.StartsWith("built-ins/RegExp/unicode_restricted_brackets.js"))
{
skip = true;
reason = "Esprima problem";
}

if (name.StartsWith("built-ins/RegExp/unicode_"))
if (name.StartsWith("built-ins/RegExp/unicode_restricted_character_class_escape.js"))
{
skip = true;
reason = "Unicode support and its special cases need more work";
reason = "Esprima problem";
}

if (name.StartsWith("built-ins/RegExp/unicode_restricted_identity_escape.js"))
{
skip = true;
reason = "Esprima problem";
}

if (name.StartsWith("built-ins/RegExp/unicode_restricted_identity_escape_alpha.js"))
{
skip = true;
reason = "Esprima problem";
}

if (name.StartsWith("built-ins/RegExp/unicode_restricted_identity_escape_c.js"))
{
skip = true;
reason = "Esprima problem";
}

if (name.StartsWith("built-ins/RegExp/unicode_restricted_identity_escape_u.js"))
{
skip = true;
reason = "Esprima problem";
}

if (name.StartsWith("built-ins/RegExp/unicode_restricted_incomple_quantifier.js"))
{
skip = true;
reason = "Esprima problem";
}

if (name.StartsWith("built-ins/RegExp/unicode_restricted_quantifiable_assertion.js"))
{
skip = true;
reason = "Esprima problem";
}

// Promises
if (name.StartsWith("built-ins/Promise/allSettled") ||
name.StartsWith("built-ins/Promise/any"))
Expand Down
59 changes: 59 additions & 0 deletions Jint.Tests/Runtime/UnicodeTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using System;
using Jint.Runtime;
using Xunit;

namespace Jint.Tests.Runtime
{
public class UnicodeTests
{
private readonly Engine _engine;

public UnicodeTests()
{
_engine = new Engine()
.SetValue("log", new Action<object>(Console.WriteLine))
.SetValue("assert", new Action<bool>(Assert.True))
.SetValue("equal", new Action<object, object>(Assert.Equal));
}

private void RunTest(string source)
{
_engine.Execute(source);
}

[Fact]
public void EscapeUnicodeUnits()
{
var value = _engine.Evaluate(@"var a = '\uD83D\uDE80'; return a;").AsString();
Assert.Equal("🚀", value);
}

[Fact]
public void EscapeUnicodeEscaped()
{
var value = _engine.Evaluate(@"var a = '\u{1F680}'; return a;").AsString();
Assert.Equal("🚀", value);
}

[Fact]
public void UnicodeIdentifiers()
{
var value = _engine.Evaluate(@"const hello = 123; return hell\u{6F}").AsNumber();
Assert.Equal(123, value);
}

[Fact]
public void RegexDontParseUnicodeEscapesWithoutFlag()
{
var value = _engine.Evaluate(@"return /^\u{3}$/.test('uuu')").AsBoolean();
Assert.True(value);
}

[Fact]
public void RegexParseUnicodeEscapesWithFlag()
{
var value = _engine.Evaluate(@"return /^\u{3}$/u.test('uuu')").AsBoolean();
Assert.False(value);
}
}
}
2 changes: 1 addition & 1 deletion Jint/Native/RegExp/RegExpConstructor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private ObjectInstance RegExpInitialize(RegExpInstance r, JsValue pattern, JsVal
var scanner = new Scanner("/" + p + "/" + flags , new ParserOptions { AdaptRegexp = true });

// seems valid
r.Value = scanner.TestRegExp(p, f);
r.Value = scanner.ParseRegex(p, f);

var timeout = _engine.Options.Constraints.RegexTimeout;
if (timeout.Ticks > 0)
Expand Down