Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Unified Diff: runtime/vm/dart_api_impl_test.cc

Issue 1309373005: Allow individual unicode surrogate strings (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Also fix unicode tests Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | runtime/vm/unicode.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/dart_api_impl_test.cc
diff --git a/runtime/vm/dart_api_impl_test.cc b/runtime/vm/dart_api_impl_test.cc
index f79106ef350f61bd64bddeba60cf73edbf78654f..bf4ec2add62afb18e9fc350f8097b5ce0683b49b 100644
--- a/runtime/vm/dart_api_impl_test.cc
+++ b/runtime/vm/dart_api_impl_test.cc
@@ -1107,13 +1107,22 @@ TEST_CASE(NewString) {
TEST_CASE(MalformedStringToUTF8) {
+ // 1D11E = treble clef
+ // [0] should be high surrogate D834
+ // [1] should be low surrogate DD1E
+ // Strings are allowed to have individual or out of order surrogates, even
+ // if that doesn't make sense as renderable characters.
const char* kScriptChars =
- "String testMain() {"
+ "String lowSurrogate() {"
" return '\\u{1D11E}'[1];"
- "}";
+ "}"
+ "String highSurrogate() {"
+ " return '\\u{1D11E}'[0];"
+ "}"
+ "String reversed() => lowSurrogate() + highSurrogate();";
Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
- Dart_Handle str1 = Dart_Invoke(lib, NewString("testMain"), 0, NULL);
+ Dart_Handle str1 = Dart_Invoke(lib, NewString("lowSurrogate"), 0, NULL);
EXPECT_VALID(str1);
uint8_t* utf8_encoded = NULL;
@@ -1126,7 +1135,20 @@ TEST_CASE(MalformedStringToUTF8) {
EXPECT_EQ(158, static_cast<intptr_t>(utf8_encoded[2]));
Dart_Handle str2 = Dart_NewStringFromUTF8(utf8_encoded, utf8_length);
- EXPECT(Dart_IsError(str2)); // Invalid UTF-8.
+ EXPECT_VALID(str2); // Standalone low surrogate, but still valid
+
+ Dart_Handle reversed = Dart_Invoke(lib, NewString("reversed"), 0, NULL);
+ EXPECT_VALID(reversed); // This is also allowed.
+ uint8_t* utf8_encoded_reversed = NULL;
+ intptr_t utf8_length_reversed = 0;
+ result = Dart_StringToUTF8(reversed,
+ &utf8_encoded_reversed, &utf8_length_reversed);
+ EXPECT_VALID(result);
+ EXPECT_EQ(6, utf8_length_reversed);
+ uint8_t expected[6] = {237, 180, 158, 237, 160, 180};
+ for (int i = 0; i < 6; i++) {
+ EXPECT_EQ(expected[i], utf8_encoded_reversed[i]);
+ }
}
« no previous file with comments | « no previous file | runtime/vm/unicode.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698