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
ce33b3d5cb
commit
6db6d70293
@ -416,11 +416,7 @@ public class StrSplitter {
|
||||
* @return 截取后的字符串数组
|
||||
*/
|
||||
public static String[] splitByLength(String text, int len) {
|
||||
SplitIter splitIter = new SplitIter(text,
|
||||
new LengthFinder(len),
|
||||
Integer.MAX_VALUE,
|
||||
false
|
||||
);
|
||||
SplitIter splitIter = new SplitIter(text, new LengthFinder(len), -1, false);
|
||||
return splitIter.toArray(false);
|
||||
}
|
||||
//---------------------------------------------------------------------------------------------------------- Private method start
|
||||
|
@ -25,6 +25,19 @@ public class SplitIterTest {
|
||||
Assert.assertEquals(6, splitIter.toList(false).size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void splitByCharIgnoreCaseTest(){
|
||||
String str1 = "a, ,,eAedsas, ddf,";
|
||||
|
||||
//不忽略""
|
||||
SplitIter splitIter = new SplitIter(str1,
|
||||
new CharFinder('a', true),
|
||||
Integer.MAX_VALUE,
|
||||
false
|
||||
);
|
||||
Assert.assertEquals(4, splitIter.toList(false).size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void splitByCharIgnoreEmptyTest(){
|
||||
String str1 = "a, ,,efedsfs, ddf,";
|
||||
@ -39,6 +52,23 @@ public class SplitIterTest {
|
||||
Assert.assertEquals(4, strings.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void splitByCharTrimTest(){
|
||||
String str1 = "a, ,,efedsfs, ddf,";
|
||||
|
||||
SplitIter splitIter = new SplitIter(str1,
|
||||
new CharFinder(',', false),
|
||||
Integer.MAX_VALUE,
|
||||
true
|
||||
);
|
||||
|
||||
final List<String> strings = splitIter.toList(true);
|
||||
Assert.assertEquals(3, strings.size());
|
||||
Assert.assertEquals("a", strings.get(0));
|
||||
Assert.assertEquals("efedsfs", strings.get(1));
|
||||
Assert.assertEquals("ddf", strings.get(2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void splitByStrTest(){
|
||||
String str1 = "a, ,,efedsfs, ddf,";
|
||||
|
Loading…
x
Reference in New Issue
Block a user