Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve InternationalizationTest #1705

Merged
merged 3 commits into from
Aug 7, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package com.google.gson.functional;

import com.google.gson.Gson;

import junit.framework.TestCase;

/**
Expand All @@ -34,32 +33,16 @@ protected void setUp() throws Exception {
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 {
String target = "\u597d\u597d\u597d";
String json = gson.toJson(target);
String expected = "\"\u597d\u597d\u597d\"";
String expected = '"' + target + '"';
assertEquals(expected, json);
}

public void testStringsWithUnicodeChineseCharactersDeserialization() throws Exception {
String expected = "\u597d\u597d\u597d";
String json = "\"" + expected + "\"";
String json = '"' + expected + '"';
String actual = gson.fromJson(json, String.class);
assertEquals(expected, actual);
}
Expand All @@ -68,4 +51,25 @@ public void testStringsWithUnicodeChineseCharactersEscapedDeserialization() thro
String actual = gson.fromJson("'\\u597d\\u597d\\u597d'", String.class);
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);
}
}