#QUALITY by cg
class: RegressionTests::StringTests
added:
#test42_includesAny
#test52_indexOfSeparator
#test54_occurrencesOf
--- a/RegressionTests__StringTests.st Sat May 07 13:45:45 2016 +0200
+++ b/RegressionTests__StringTests.st Sun May 08 02:17:40 2016 +0200
@@ -3,10 +3,10 @@
"{ NameSpace: RegressionTests }"
TestCase subclass:#StringTests
- instanceVariableNames:''
- classVariableNames:''
- poolDictionaries:''
- category:'tests-Regression-Collections'
+ instanceVariableNames:''
+ classVariableNames:''
+ poolDictionaries:''
+ category:'tests-Regression-Collections'
!
@@ -134,17 +134,17 @@
test01_access
0 to:33 do:[:l |
- |str|
+ |str|
- str := String new:l.
- str atAllPut:(Character space).
- self assert:( str isBlank ).
+ str := String new:l.
+ str atAllPut:(Character space).
+ self assert:( str isBlank ).
- 1 to:l do:[:pos |
- str at:pos put:$a.
- self assert:( str isBlank not ).
- str at:pos put:(Character space).
- ].
+ 1 to:l do:[:pos |
+ str at:pos put:$a.
+ self assert:( str isBlank not ).
+ str at:pos put:(Character space).
+ ].
].
self runAccessTestsOnInstancesOf:String
@@ -157,13 +157,13 @@
|myStringClass s1|
Class withoutUpdatingChangesDo:[
- myStringClass := String
- subclass:#'MyString'
- instanceVariableNames:'foo'
- classVariableNames:''
- poolDictionaries:nil.
- myStringClass compile:'foo ^foo'.
- myStringClass compile:'foo:arg foo := arg'.
+ myStringClass := String
+ subclass:#'MyString'
+ instanceVariableNames:'foo'
+ classVariableNames:''
+ poolDictionaries:nil.
+ myStringClass compile:'foo ^foo'.
+ myStringClass compile:'foo:arg foo := arg'.
].
s1 := (myStringClass new:5) replaceFrom:1 with:'hello'.
@@ -187,17 +187,17 @@
test10_Contains8BitCharacters
0 to:65 do:[:l |
- |str|
+ |str|
- str := String new:l.
- str atAllPut:(Character value:16r7F).
- self assert:( str contains8BitCharacters not ).
+ str := String new:l.
+ str atAllPut:(Character value:16r7F).
+ self assert:( str contains8BitCharacters not ).
- 1 to:l do:[:pos |
- str at:pos put:(Character value:16r80).
- self assert:( str contains8BitCharacters ).
- str at:pos put:(Character value:16r7F).
- ].
+ 1 to:l do:[:pos |
+ str at:pos put:(Character value:16r80).
+ self assert:( str contains8BitCharacters ).
+ str at:pos put:(Character value:16r7F).
+ ].
].
"
@@ -213,19 +213,19 @@
parserFlags arraysAreImmutable:true.
Class withoutUpdatingChangesDo:[
- myClass := Object
- subclass:#'MyClass'
- instanceVariableNames:''
- classVariableNames:''
- poolDictionaries:nil.
+ myClass := Object
+ subclass:#'MyClass'
+ instanceVariableNames:''
+ classVariableNames:''
+ poolDictionaries:nil.
- compiler := myClass compilerClass new.
- compiler parserFlags:parserFlags.
- compiler compile:'lit1 ^''hello''' forClass:myClass install:true.
+ compiler := myClass compilerClass new.
+ compiler parserFlags:parserFlags.
+ compiler compile:'lit1 ^''hello''' forClass:myClass install:true.
- compiler := myClass compilerClass new.
- compiler parserFlags:parserFlags.
- compiler compile:'lit2 ^#(''foo'' ''bar'' ''baz'')' forClass:myClass install:true.
+ compiler := myClass compilerClass new.
+ compiler parserFlags:parserFlags.
+ compiler compile:'lit2 ^#(''foo'' ''bar'' ''baz'')' forClass:myClass install:true.
].
s1 := myClass new perform:#lit1.
@@ -322,6 +322,24 @@
"
!
+test42_includesAny
+ |s|
+
+ 1 to:20 do:[:na |
+ s := (String new:na withAll:$a),'bla bla 1234'.
+ self assert:( s includesAny:'12').
+ self assert:( s includesAny:'21').
+ self assert:( s includesAny:'15').
+ self assert:( s includesAny:'51').
+ self assert:( s includesAny:'45').
+ self assert:( s includesAny:'54').
+ self assert:( s includesAny:'56') not.
+ ].
+
+ "
+ self new test42_includesAny
+ "
+
test42_occurrencesOf
|s|
@@ -504,6 +522,106 @@
"
!
+test52_indexOfSeparator
+ |s|
+
+ self assert:('' indexOfSeparator) == 0.
+ 1 to:20 do:[:n |
+ s := (String new:n withAll:$a).
+ 1 to:20 do:[:start |
+ self assert:(s indexOfSeparatorStartingAt:start) == 0.
+ ].
+ ].
+ 1 to:20 do:[:n |
+ s := (String new:n withAll:$a),' '.
+ 1 to:n do:[:start |
+ self assert:(s indexOfSeparatorStartingAt:start) == (n+1).
+ ].
+ ].
+
+ {
+ Character space .
+ Character tab .
+ Character return .
+ Character lf .
+ } do:[:sep |
+ 1 to:20 do:[:na |
+ 1 to:20 do:[:nb |
+ s := (String new:na withAll:$a),sep,(String new:na withAll:$a).
+ 1 to:na do:[:start |
+ self assert:(s indexOfSeparatorStartingAt:start) == (na+1).
+ ]
+ ]
+ ].
+ ].
+
+ {
+ Character esc .
+ Character null .
+ $a .
+ } do:[:nonSep |
+ 1 to:20 do:[:na |
+ 1 to:20 do:[:nb |
+ s := (String new:na withAll:$a),nonSep,(String new:na withAll:$a).
+ 1 to:20 do:[:start |
+ self assert:(s indexOfSeparatorStartingAt:start) == 0.
+ ]
+ ]
+ ].
+ ].
+
+ s := String new:1000 withAll:$a.
+ self assert:(s indexOfSeparatorStartingAt:1) == 0.
+ 400 to: 417 do:[:i |
+ s := String new:1000 withAll:$a.
+ s at:i put:(Character space).
+ self assert:(s indexOfSeparatorStartingAt:1) == i.
+
+ s := String new:1000 withAll:$a.
+ s at:i put:(Character return).
+ self assert:(s indexOfSeparatorStartingAt:1) == i.
+ ]
+
+ "
+ self new test52_indexOfSeparator
+ "
+!
+
+test54_occurrencesOf
+ |s|
+
+ self assert:('' occurrencesOf:$a) == 0.
+ 1 to:20 do:[:n |
+ s := (String new:n withAll:$a).
+ self assert:(s occurrencesOf:$a) == n.
+ ].
+ 1 to:20 do:[:na |
+ 1 to:20 do:[:nb |
+ s := (String new:na withAll:$a),(String new:nb withAll:$b).
+ self assert:(s occurrencesOf:$a) == na.
+ ].
+ ].
+ 1 to:40 do:[:n |
+ s := String new:n withAll:$a.
+ 1 to:n by:2 do:[:n |
+ s at:n put:$b.
+ ].
+ self assert:(s occurrencesOf:$a) == (n // 2).
+ ].
+
+ s := String new:1000 withAll:$a.
+ self assert:(s occurrencesOf:$a) == 1000.
+ 1 to:1000 do:[:i |
+ s at:i put:$b.
+ self assert:(s occurrencesOf:$a) == (1000-i).
+ self assert:(s occurrencesOf:$b) == i.
+ ].
+
+ "
+ self new test54_occurrencesOf
+ "
+!
+
test60_hash
"
As of 2013-01-09 for strings of size 7 String & Unicode16String hash
@@ -632,12 +750,12 @@
self assert: str = 'FFF'.
self should:[
- str from:-1 to:-1 put:$x
+ str from:-1 to:-1 put:$x
] raise:SubscriptOutOfBoundsError.
self assert: str = 'FFF'.
self should:[
- str from:-1 to:1 put:$x
+ str from:-1 to:1 put:$x
] raise:SubscriptOutOfBoundsError.
self assert: str = 'FFF'.
!