add methods

This commit is contained in:
Looly
2022-08-18 12:12:31 +08:00
parent f536f4f47a
commit 1079533d5b
4 changed files with 157 additions and 7 deletions

View File

@@ -6,7 +6,7 @@ import org.junit.Test;
public class PunyCodeTest {
@Test
public void encodeDecodeTest(){
public void encodeDecodeTest() {
final String text = "Hutool编码器";
final String strPunyCode = PunyCode.encode(text);
Assert.assertEquals("Hutool-ux9js33tgln", strPunyCode);
@@ -15,4 +15,37 @@ public class PunyCodeTest {
decode = PunyCode.decode("xn--Hutool-ux9js33tgln");
Assert.assertEquals(text, decode);
}
@Test
public void encodeDecodeDomainTest() {
// 全中文
final String text = "百度.中国";
final String strPunyCode = PunyCode.encodeDomain(text);
Assert.assertEquals("xn--wxtr44c.xn--fiqs8s", strPunyCode);
final String decode = PunyCode.decodeDomain(strPunyCode);
Assert.assertEquals(text, decode);
}
@Test
public void encodeDecodeDomainTest2() {
// 中英文分段
final String text = "hutool.中国";
final String strPunyCode = PunyCode.encodeDomain(text);
Assert.assertEquals("xn--hutool-.xn--fiqs8s", strPunyCode);
final String decode = PunyCode.decodeDomain(strPunyCode);
Assert.assertEquals(text, decode);
}
@Test
public void encodeDecodeDomainTest3() {
// 中英文混合
final String text = "hutool工具.中国";
final String strPunyCode = PunyCode.encodeDomain(text);
Assert.assertEquals("xn--hutool-up2j943f.xn--fiqs8s", strPunyCode);
final String decode = PunyCode.decodeDomain(strPunyCode);
Assert.assertEquals(text, decode);
}
}

View File

@@ -195,4 +195,18 @@ public class CharSequenceUtilTest {
(v) -> DateUtil.parse(v, DatePattern.NORM_DATETIME_PATTERN).toInstant(), Instant::now);
Assert.assertNotNull(result2);
}
@Test
public void replaceLastTest() {
final String str = "i am jack and jack";
final String result = StrUtil.replaceLast(str, "JACK", null, true);
Assert.assertEquals(result, "i am jack and ");
}
@Test
public void replaceFirstTest() {
final String str = "yes and yes i do";
final String result = StrUtil.replaceFirst(str, "YES", "", true);
Assert.assertEquals(result, " and yes i do");
}
}