mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
add test
This commit is contained in:
parent
5f34b941fa
commit
6a79844dec
@ -5,7 +5,7 @@ import org.junit.Test;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* UnicodeUtil 单元测试
|
* UnicodeUtil 单元测试
|
||||||
*
|
*
|
||||||
* @author looly
|
* @author looly
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@ -25,25 +25,31 @@ public class UnicodeUtilTest {
|
|||||||
String unicode = UnicodeUtil.toString(str);
|
String unicode = UnicodeUtil.toString(str);
|
||||||
Assert.assertEquals("aaaa&bbbb&cccc", unicode);
|
Assert.assertEquals("aaaa&bbbb&cccc", unicode);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void convertTest3() {
|
public void convertTest3() {
|
||||||
String str = "aaa\\u111";
|
String str = "aaa\\u111";
|
||||||
String res = UnicodeUtil.toString(str);
|
String res = UnicodeUtil.toString(str);
|
||||||
Assert.assertEquals("aaa\\u111", res);
|
Assert.assertEquals("aaa\\u111", res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void convertTest4() {
|
public void convertTest4() {
|
||||||
String str = "aaa\\U4e2d\\u6587\\u111\\urtyu\\u0026";
|
String str = "aaa\\U4e2d\\u6587\\u111\\urtyu\\u0026";
|
||||||
String res = UnicodeUtil.toString(str);
|
String res = UnicodeUtil.toString(str);
|
||||||
Assert.assertEquals("aaa中文\\u111\\urtyu&", res);
|
Assert.assertEquals("aaa中文\\u111\\urtyu&", res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void convertTest5() {
|
public void convertTest5() {
|
||||||
String str = "{\"code\":403,\"enmsg\":\"Product not found\",\"cnmsg\":\"\\u4ea7\\u54c1\\u4e0d\\u5b58\\u5728\\uff0c\\u6216\\u5df2\\u5220\\u9664\",\"data\":null}";
|
String str = "{\"code\":403,\"enmsg\":\"Product not found\",\"cnmsg\":\"\\u4ea7\\u54c1\\u4e0d\\u5b58\\u5728\\uff0c\\u6216\\u5df2\\u5220\\u9664\",\"data\":null}";
|
||||||
String res = UnicodeUtil.toString(str);
|
String res = UnicodeUtil.toString(str);
|
||||||
Assert.assertEquals("{\"code\":403,\"enmsg\":\"Product not found\",\"cnmsg\":\"产品不存在,或已删除\",\"data\":null}", res);
|
Assert.assertEquals("{\"code\":403,\"enmsg\":\"Product not found\",\"cnmsg\":\"产品不存在,或已删除\",\"data\":null}", res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void issueI50MI6Test(){
|
||||||
|
String s = UnicodeUtil.toUnicode("烟", true);
|
||||||
|
Assert.assertEquals("\\u70df", s);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,8 @@ package cn.hutool.core.util;
|
|||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HexUtil单元测试
|
* HexUtil单元测试
|
||||||
* @author Looly
|
* @author Looly
|
||||||
@ -20,6 +22,12 @@ public class HexUtilTest {
|
|||||||
Assert.assertEquals(str, decodedStr);
|
Assert.assertEquals(str, decodedStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void issueI50MI6Test(){
|
||||||
|
String s = HexUtil.encodeHexStr("烟".getBytes(StandardCharsets.UTF_16BE));
|
||||||
|
Assert.assertEquals("70df", s);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void toUnicodeHexTest() {
|
public void toUnicodeHexTest() {
|
||||||
String unicodeHex = HexUtil.toUnicodeHex('\u2001');
|
String unicodeHex = HexUtil.toUnicodeHex('\u2001');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user