Skip to content

Commit 9eb0441

Browse files
authored
Improve InternationalizationTest (#1705)
* Improve InternationalizationTest - Remove "raw" tests since after compiling they are the same as the one with escape sequences - Add tests for supplementary code points (> \uFFFF) * Improve variable names, fix incorrect escape sequences
1 parent 76c78f5 commit 9eb0441

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

gson/src/test/java/com/google/gson/functional/InternationalizationTest.java

+23-19
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package com.google.gson.functional;
1818

1919
import com.google.gson.Gson;
20-
2120
import junit.framework.TestCase;
2221

2322
/**
@@ -34,32 +33,16 @@ protected void setUp() throws Exception {
3433
gson = new Gson();
3534
}
3635

37-
/*
38-
public void testStringsWithRawChineseCharactersSerialization() throws Exception {
39-
String target = "好好好";
40-
String json = gson.toJson(target);
41-
String expected = "\"\\u597d\\u597d\\u597d\"";
42-
assertEquals(expected, json);
43-
}
44-
*/
45-
46-
public void testStringsWithRawChineseCharactersDeserialization() throws Exception {
47-
String expected = "好好好";
48-
String json = "\"" + expected + "\"";
49-
String actual = gson.fromJson(json, String.class);
50-
assertEquals(expected, actual);
51-
}
52-
5336
public void testStringsWithUnicodeChineseCharactersSerialization() throws Exception {
5437
String target = "\u597d\u597d\u597d";
5538
String json = gson.toJson(target);
56-
String expected = "\"\u597d\u597d\u597d\"";
39+
String expected = '"' + target + '"';
5740
assertEquals(expected, json);
5841
}
5942

6043
public void testStringsWithUnicodeChineseCharactersDeserialization() throws Exception {
6144
String expected = "\u597d\u597d\u597d";
62-
String json = "\"" + expected + "\"";
45+
String json = '"' + expected + '"';
6346
String actual = gson.fromJson(json, String.class);
6447
assertEquals(expected, actual);
6548
}
@@ -68,4 +51,25 @@ public void testStringsWithUnicodeChineseCharactersEscapedDeserialization() thro
6851
String actual = gson.fromJson("'\\u597d\\u597d\\u597d'", String.class);
6952
assertEquals("\u597d\u597d\u597d", actual);
7053
}
54+
55+
public void testSupplementaryUnicodeSerialization() throws Exception {
56+
// Supplementary code point U+1F60A
57+
String supplementaryCodePoint = new String(new int[] {0x1F60A}, 0, 1);
58+
String json = gson.toJson(supplementaryCodePoint);
59+
assertEquals('"' + supplementaryCodePoint + '"', json);
60+
}
61+
62+
public void testSupplementaryUnicodeDeserialization() throws Exception {
63+
// Supplementary code point U+1F60A
64+
String supplementaryCodePoint = new String(new int[] {0x1F60A}, 0, 1);
65+
String actual = gson.fromJson('"' + supplementaryCodePoint + '"', String.class);
66+
assertEquals(supplementaryCodePoint, actual);
67+
}
68+
69+
public void testSupplementaryUnicodeEscapedDeserialization() throws Exception {
70+
// Supplementary code point U+1F60A
71+
String supplementaryCodePoint = new String(new int[] {0x1F60A}, 0, 1);
72+
String actual = gson.fromJson("\"\\uD83D\\uDE0A\"", String.class);
73+
assertEquals(supplementaryCodePoint, actual);
74+
}
7175
}

0 commit comments

Comments
 (0)