Skip to content

Commit 9ad53ea

Browse files
committed
Update testlib.cpp
1 parent a3eea2e commit 9ad53ea

File tree

1 file changed

+45
-1
lines changed
  • vnext/ReactCommon/TEMP_UntilReactCommonUpdate/jsi/jsi/test

1 file changed

+45
-1
lines changed

vnext/ReactCommon/TEMP_UntilReactCommonUpdate/jsi/jsi/test/testlib.cpp

+45-1
Original file line numberDiff line numberDiff line change
@@ -1551,7 +1551,7 @@ TEST_P(JSITest, UTF8ExceptionTest) {
15511551
}
15521552

15531553
/* [Windows #14185
1554-
TEST_P(JSITest, UTF16Test) {
1554+
TEST_P(JSITest, UTF16ConversionTest) {
15551555
// This Runtime Decorator is used to test the conversion from UTF-8 to UTF-16
15561556
// in the default utf16 method for runtimes that do not provide their own
15571557
// utf16 implementation.
@@ -1614,6 +1614,50 @@ TEST_P(JSITest, UTF16Test) {
16141614
rd.utf8Str = "\xea\x7a";
16151615
EXPECT_EQ(str.utf16(rd), u"\uFFFD\u007A");
16161616
}
1617+
1618+
TEST_P(JSITest, CreateFromUtf16Test) {
1619+
// This Runtime Decorator is used to test the default createStringFromUtf16
1620+
// and createPropNameIDFromUtf16 implementation for VMs that do not provide
1621+
// their own implementation
1622+
class RD : public RuntimeDecorator<Runtime, Runtime> {
1623+
public:
1624+
RD(Runtime& rt) : RuntimeDecorator(rt) {}
1625+
1626+
String createStringFromUtf16(const char16_t* utf16, size_t length)
1627+
override {
1628+
return Runtime::createStringFromUtf16(utf16, length);
1629+
}
1630+
1631+
PropNameID createPropNameIDFromUtf16(const char16_t* utf16, size_t length)
1632+
override {
1633+
return Runtime::createPropNameIDFromUtf16(utf16, length);
1634+
}
1635+
};
1636+
1637+
RD rd = RD(rt);
1638+
std::u16string utf16 = u"foobar";
1639+
1640+
auto jsString = String::createFromUtf16(rd, utf16);
1641+
EXPECT_EQ(jsString.utf16(rd), utf16);
1642+
auto prop = PropNameID::forUtf16(rd, utf16);
1643+
EXPECT_EQ(prop.utf16(rd), utf16);
1644+
1645+
// 👋 in UTF-16 encoding is 0xd83d 0xdc4b
1646+
utf16 = u"hello!\xd83d\xdc4b";
1647+
jsString = String::createFromUtf16(rd, utf16.data(), utf16.length());
1648+
EXPECT_EQ(jsString.utf16(rd), utf16);
1649+
prop = PropNameID::forUtf16(rd, utf16);
1650+
EXPECT_EQ(prop.utf16(rd), utf16);
1651+
1652+
utf16 = u"\xd83d";
1653+
jsString = String::createFromUtf16(rd, utf16.data(), utf16.length());
1654+
/// We need to use charCodeAt instead of UTF16 because the default
1655+
/// implementation of UTF16 converts to UTF8, then to UTF16, so we will lose
1656+
/// the lone surrogate value.
1657+
rd.global().setProperty(rd, "loneSurrogate", jsString);
1658+
auto cp = eval("loneSurrogate.charCodeAt(0)").getNumber();
1659+
EXPECT_EQ(cp, 55357); // 0xD83D in decimal
1660+
}
16171661
Windows] */
16181662

16191663
/*

0 commit comments

Comments
 (0)