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
This commit is contained in:
parent
76c78f5925
commit
9eb04414c0
@ -17,7 +17,6 @@
|
|||||||
package com.google.gson.functional;
|
package com.google.gson.functional;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -34,32 +33,16 @@ public class InternationalizationTest extends TestCase {
|
|||||||
gson = new Gson();
|
gson = new Gson();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
public void testStringsWithRawChineseCharactersSerialization() throws Exception {
|
|
||||||
String target = "好好好";
|
|
||||||
String json = gson.toJson(target);
|
|
||||||
String expected = "\"\\u597d\\u597d\\u597d\"";
|
|
||||||
assertEquals(expected, json);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
public void testStringsWithRawChineseCharactersDeserialization() throws Exception {
|
|
||||||
String expected = "好好好";
|
|
||||||
String json = "\"" + expected + "\"";
|
|
||||||
String actual = gson.fromJson(json, String.class);
|
|
||||||
assertEquals(expected, actual);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testStringsWithUnicodeChineseCharactersSerialization() throws Exception {
|
public void testStringsWithUnicodeChineseCharactersSerialization() throws Exception {
|
||||||
String target = "\u597d\u597d\u597d";
|
String target = "\u597d\u597d\u597d";
|
||||||
String json = gson.toJson(target);
|
String json = gson.toJson(target);
|
||||||
String expected = "\"\u597d\u597d\u597d\"";
|
String expected = '"' + target + '"';
|
||||||
assertEquals(expected, json);
|
assertEquals(expected, json);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testStringsWithUnicodeChineseCharactersDeserialization() throws Exception {
|
public void testStringsWithUnicodeChineseCharactersDeserialization() throws Exception {
|
||||||
String expected = "\u597d\u597d\u597d";
|
String expected = "\u597d\u597d\u597d";
|
||||||
String json = "\"" + expected + "\"";
|
String json = '"' + expected + '"';
|
||||||
String actual = gson.fromJson(json, String.class);
|
String actual = gson.fromJson(json, String.class);
|
||||||
assertEquals(expected, actual);
|
assertEquals(expected, actual);
|
||||||
}
|
}
|
||||||
@ -68,4 +51,25 @@ public class InternationalizationTest extends TestCase {
|
|||||||
String actual = gson.fromJson("'\\u597d\\u597d\\u597d'", String.class);
|
String actual = gson.fromJson("'\\u597d\\u597d\\u597d'", String.class);
|
||||||
assertEquals("\u597d\u597d\u597d", actual);
|
assertEquals("\u597d\u597d\u597d", actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testSupplementaryUnicodeSerialization() throws Exception {
|
||||||
|
// Supplementary code point U+1F60A
|
||||||
|
String supplementaryCodePoint = new String(new int[] {0x1F60A}, 0, 1);
|
||||||
|
String json = gson.toJson(supplementaryCodePoint);
|
||||||
|
assertEquals('"' + supplementaryCodePoint + '"', json);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testSupplementaryUnicodeDeserialization() throws Exception {
|
||||||
|
// Supplementary code point U+1F60A
|
||||||
|
String supplementaryCodePoint = new String(new int[] {0x1F60A}, 0, 1);
|
||||||
|
String actual = gson.fromJson('"' + supplementaryCodePoint + '"', String.class);
|
||||||
|
assertEquals(supplementaryCodePoint, actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testSupplementaryUnicodeEscapedDeserialization() throws Exception {
|
||||||
|
// Supplementary code point U+1F60A
|
||||||
|
String supplementaryCodePoint = new String(new int[] {0x1F60A}, 0, 1);
|
||||||
|
String actual = gson.fromJson("\"\\uD83D\\uDE0A\"", String.class);
|
||||||
|
assertEquals(supplementaryCodePoint, actual);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user