@@ -41,22 +41,37 @@ fn test_index_and_rindex() {
4141
4242#[ test]
4343fn test_split ( ) {
44- fn t ( s : str , c : char , i : int , k : str ) {
45- log "splitting: " + s;
46- log i;
44+ fn t ( s : str , c : char , u : [ str ] ) {
45+ log "split: " + s;
4746 let v = str:: split ( s, c as u8 ) ;
4847 log "split to: " ;
49- for z: str in v { log z; }
50- log "comparing: " + v[ i] + " vs. " + k;
51- assert ( str:: eq ( v[ i] , k) ) ;
48+ log v;
49+ assert ( vec:: all2 ( v, u, { |a, b| a == b } ) ) ;
5250 }
53- t ( "abc.hello.there" , '.' , 0 , "abc" ) ;
54- t ( "abc.hello.there" , '.' , 1 , "hello" ) ;
55- t ( "abc.hello.there" , '.' , 2 , "there" ) ;
56- t ( ".hello.there" , '.' , 0 , "" ) ;
57- t ( ".hello.there" , '.' , 1 , "hello" ) ;
58- t ( "...hello.there." , '.' , 3 , "hello" ) ;
59- t ( "...hello.there." , '.' , 5 , "" ) ;
51+ t ( "abc.hello.there" , '.' , [ "abc" , "hello" , "there" ] ) ;
52+ t ( ".hello.there" , '.' , [ "" , "hello" , "there" ] ) ;
53+ t ( "...hello.there." , '.' , [ "" , "" , "" , "hello" , "there" , "" ] ) ;
54+ }
55+
56+ #[ test]
57+ fn test_splitn ( ) {
58+ fn t ( s : str , c : char , n : uint , u : [ str ] ) {
59+ log "splitn: " + s;
60+ let v = str:: splitn ( s, c as u8 , n) ;
61+ log "split to: " ;
62+ log v;
63+ log "comparing vs. " ;
64+ log u;
65+ assert ( vec:: all2 ( v, u, { |a, b| a == b } ) ) ;
66+ }
67+ t ( "abc.hello.there" , '.' , 0 u, [ "abc.hello.there" ] ) ;
68+ t ( "abc.hello.there" , '.' , 1 u, [ "abc" , "hello.there" ] ) ;
69+ t ( "abc.hello.there" , '.' , 2 u, [ "abc" , "hello" , "there" ] ) ;
70+ t ( "abc.hello.there" , '.' , 3 u, [ "abc" , "hello" , "there" ] ) ;
71+ t ( ".hello.there" , '.' , 0 u, [ ".hello.there" ] ) ;
72+ t ( ".hello.there" , '.' , 1 u, [ "" , "hello.there" ] ) ;
73+ t ( "...hello.there." , '.' , 3 u, [ "" , "" , "" , "hello.there." ] ) ;
74+ t ( "...hello.there." , '.' , 5 u, [ "" , "" , "" , "hello" , "there" , "" ] ) ;
6075}
6176
6277#[ test]
0 commit comments