This commit is contained in:
Looly
2022-04-30 19:45:32 +08:00
parent d368fb1949
commit dea8344d91
25 changed files with 255 additions and 140 deletions

View File

@@ -0,0 +1,18 @@
package cn.hutool.core.codec;
import org.junit.Assert;
import org.junit.Test;
public class PercentCodecTest {
@Test
public void isSafeTest(){
PercentCodec codec = PercentCodec.Builder.of("=").build();
Assert.assertTrue(codec.isSafe('='));
codec = PercentCodec.Builder.of("=").or(PercentCodec.Builder.of("abc").build()).build();
Assert.assertTrue(codec.isSafe('a'));
Assert.assertTrue(codec.isSafe('b'));
Assert.assertTrue(codec.isSafe('c'));
}
}

View File

@@ -6,6 +6,12 @@ import org.junit.Test;
public class RFC3986Test {
@Test
public void pacharTest(){
final String encode = RFC3986.PCHAR.encode("=", CharsetUtil.UTF_8);
Assert.assertEquals("=", encode);
}
@Test
public void encodeQueryTest(){
String encode = RFC3986.QUERY_PARAM_VALUE.encode("a=b", CharsetUtil.UTF_8);

View File

@@ -21,4 +21,12 @@ public class URLEncoderTest {
String encode2 = URLEncoder.encodeQuery(body);
Assert.assertEquals("+", encode2);
}
@Test
public void encodeEmojiTest(){
String emoji = "🐶😊😂🤣";
String encode = URLEncoder.encodeAll(emoji);
Assert.assertEquals("%F0%9F%90%B6%F0%9F%98%8A%F0%9F%98%82%F0%9F%A4%A3", encode);
Assert.assertEquals(emoji, URLDecoder.decode(encode));
}
}