17
17
package com .google .gson .functional ;
18
18
19
19
import com .google .gson .Gson ;
20
-
21
20
import junit .framework .TestCase ;
22
21
23
22
/**
@@ -34,32 +33,16 @@ protected void setUp() throws Exception {
34
33
gson = new Gson ();
35
34
}
36
35
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
-
53
36
public void testStringsWithUnicodeChineseCharactersSerialization () throws Exception {
54
37
String target = "\u597d \u597d \u597d " ;
55
38
String json = gson .toJson (target );
56
- String expected = " \" \u597d \u597d \u597d \" " ;
39
+ String expected = '"' + target + '"' ;
57
40
assertEquals (expected , json );
58
41
}
59
42
60
43
public void testStringsWithUnicodeChineseCharactersDeserialization () throws Exception {
61
44
String expected = "\u597d \u597d \u597d " ;
62
- String json = " \" " + expected + " \" " ;
45
+ String json = '"' + expected + '"' ;
63
46
String actual = gson .fromJson (json , String .class );
64
47
assertEquals (expected , actual );
65
48
}
@@ -68,4 +51,25 @@ public void testStringsWithUnicodeChineseCharactersEscapedDeserialization() thro
68
51
String actual = gson .fromJson ("'\\ u597d\\ u597d\\ u597d'" , String .class );
69
52
assertEquals ("\u597d \u597d \u597d " , actual );
70
53
}
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
+ }
71
75
}
0 commit comments