RegressionTests__StringTests.st
changeset 2364 41b2b20fa672
parent 2328 cfee3c8c8f98
child 2365 c49d92aa47aa
--- a/RegressionTests__StringTests.st	Thu Aug 01 11:36:25 2019 +0200
+++ b/RegressionTests__StringTests.st	Sat Aug 10 14:04:42 2019 +0200
@@ -702,6 +702,115 @@
     "Modified: / 25-05-2019 / 09:01:43 / Claus Gittinger"
 !
 
+test30b_indexOfSubCollection
+    |i|
+
+      "/  12345678901
+    i := 'hello world' indexOfSubCollection:'w' startingAt:1 ifAbsent:0 caseSensitive:true.
+    self assert:(i == 7).
+    i := 'hello world' indexOfSubCollection:'w' startingAt:6 ifAbsent:0 caseSensitive:true.
+    self assert:(i == 7).
+    i := 'hello world' indexOfSubCollection:'w' startingAt:7 ifAbsent:0 caseSensitive:true.
+    self assert:(i == 7).
+    i := 'hello world' indexOfSubCollection:'w' startingAt:8 ifAbsent:0 caseSensitive:true.
+    self assert:(i == 0).
+    i := 'hello world' indexOfSubCollection:'x' startingAt:1 ifAbsent:0 caseSensitive:true.
+    self assert:(i == 0).
+
+      "/  12345678901
+    i := 'hello world' indexOfSubCollection:'wo' startingAt:1 ifAbsent:0 caseSensitive:true.
+    self assert:(i == 7).
+    i := 'hello world' indexOfSubCollection:'wo' startingAt:6 ifAbsent:0 caseSensitive:true.
+    self assert:(i == 7).
+    i := 'hello world' indexOfSubCollection:'wo' startingAt:7 ifAbsent:0 caseSensitive:true.
+    self assert:(i == 7).
+    i := 'hello world' indexOfSubCollection:'wo' startingAt:8 ifAbsent:0 caseSensitive:true.
+    self assert:(i == 0).
+    i := 'hello world' indexOfSubCollection:'xx' startingAt:1 ifAbsent:0 caseSensitive:true.
+    self assert:(i == 0).
+    i := 'hello world' indexOfSubCollection:'wO' startingAt:1 ifAbsent:0 caseSensitive:true.
+    self assert:(i == 0).
+    i := 'hello world' indexOfSubCollection:'wO' startingAt:6 ifAbsent:0 caseSensitive:true.
+    self assert:(i == 0).
+    i := 'hello world' indexOfSubCollection:'wO' startingAt:7 ifAbsent:0 caseSensitive:true.
+    self assert:(i == 0).
+    i := 'hello world' indexOfSubCollection:'wO' startingAt:8 ifAbsent:0 caseSensitive:true.
+    self assert:(i == 0).
+
+      "/  12345678901
+    i := 'hello world' indexOfSubCollection:'world' startingAt:1 ifAbsent:0 caseSensitive:true.
+    self assert:(i == 7).
+    i := 'hello wOrLd' indexOfSubCollection:'world' startingAt:1 ifAbsent:0 caseSensitive:true.
+    self assert:(i == 0).
+    i := 'hello wOrLd' indexOfSubCollection:'world' startingAt:1 ifAbsent:0 caseSensitive:false.
+    self assert:(i == 7).
+    i := 'hello wOrLd' indexOfSubCollection:'ll' startingAt:1 ifAbsent:0 caseSensitive:false.
+    self assert:(i == 3).
+
+    i := 'hello wOrLd yellow' indexOfSubCollection:'ll' startingAt:1 ifAbsent:0 caseSensitive:false.
+    self assert:(i == 3).
+    i := 'hello wOrLd yellow' indexOfSubCollection:'ll' startingAt:3 ifAbsent:0 caseSensitive:false.
+    self assert:(i == 3).
+    i := 'hello wOrLd yellow' indexOfSubCollection:'ll' startingAt:4 ifAbsent:0 caseSensitive:false.
+    self assert:(i == 15).
+
+    i := 'hello wOrLd yellow' indexOfSubCollection:'low' startingAt:1 ifAbsent:0 caseSensitive:false.
+    self assert:(i == 16).
+    i := 'hello wOrLd yellow' indexOfSubCollection:'low' startingAt:17 ifAbsent:0 caseSensitive:false.
+    self assert:(i == 0).
+    i := 'hello wOrLd yellow' indexOfSubCollection:'low' startingAt:18 ifAbsent:0 caseSensitive:false.
+    self assert:(i == 0).
+
+    i := 'world' indexOfSubCollection:'world' startingAt:1 ifAbsent:0 caseSensitive:true.
+    self assert:(i == 1).
+    i := 'world' indexOfSubCollection:'world' startingAt:1 ifAbsent:0 caseSensitive:false.
+    self assert:(i == 1).
+    i := 'world' indexOfSubCollection:'world' startingAt:2 ifAbsent:0 caseSensitive:true.
+    self assert:(i == 0).
+    i := 'world' indexOfSubCollection:'world' startingAt:2 ifAbsent:0 caseSensitive:false.
+    self assert:(i == 0).
+    i := 'world' indexOfSubCollection:'world' startingAt:6 ifAbsent:0 caseSensitive:true.
+    self assert:(i == 0).
+    i := 'world' indexOfSubCollection:'world' startingAt:6 ifAbsent:0 caseSensitive:false.
+    self assert:(i == 0).
+
+    i := 'hello world' indexOfSubCollection:'world' startingAt:1 ifAbsent:0 caseSensitive:false.
+    self assert:(i == 7).
+    i := 'hello world' indexOfSubCollection:'world' startingAt:1 ifAbsent:0 caseSensitive:true.
+    self assert:(i == 7).
+
+    i := 'hello world' indexOfSubCollection:'world' startingAt:1 ifAbsent:0 caseSensitive:false.
+    self assert:(i == 7).
+    i := 'hello world' indexOfSubCollection:'world' startingAt:1 ifAbsent:0 caseSensitive:true.
+    self assert:(i == 7).
+
+    i := 'hello world' indexOfSubCollection:'world' startingAt:4 ifAbsent:0 caseSensitive:false.
+    self assert:(i == 7).
+    i := 'hello world' indexOfSubCollection:'world' startingAt:4 ifAbsent:0 caseSensitive:true.
+    self assert:(i == 7).
+
+    i := 'hello world' indexOfSubCollection:'world' startingAt:7 ifAbsent:0 caseSensitive:false.
+    self assert:(i == 7).
+    i := 'hello world' indexOfSubCollection:'world' startingAt:7 ifAbsent:0 caseSensitive:true.
+    self assert:(i == 7).
+
+    i := 'hello world' indexOfSubCollection:'world' startingAt:8 ifAbsent:0 caseSensitive:false.
+    self assert:(i == 0).
+    i := 'hello world' indexOfSubCollection:'world' startingAt:8 ifAbsent:0 caseSensitive:true.
+    self assert:(i == 0).
+    
+    i := 'hello wOrLd' indexOfSubCollection:'world' startingAt:1 ifAbsent:0 caseSensitive:true.
+    self assert:(i == 0).
+    i := 'hello wOrLd' indexOfSubCollection:'world' startingAt:1 ifAbsent:0 caseSensitive:false.
+    self assert:(i == 7).
+
+    "
+     self new test30b_indexOfSubCollection
+    "
+
+    "Modified: / 25-05-2019 / 09:01:43 / Claus Gittinger"
+!
+
 test31_occurrencesOfString
     |n|
       "/  12345678901
@@ -1333,6 +1442,23 @@
     "Created: / 02-04-2019 / 10:55:26 / Claus Gittinger"
 !
 
+test61_hash
+    "all string-representations must hash equal"
+    
+    | string8 string16 string32 |
+
+    string8 := 'sun/nio/cs/UTF_8.class'.
+    string16 := string8 asUnicode16String.
+    string32 := string8 asUnicode16String.
+
+    self assert: string8 hash == string16 hash.
+    self assert: string8 hash == string32 hash.
+    self assert: string8 hash == string8 asSymbol hash.
+
+    "Created: / 09-10-2014 / 12:41:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 02-04-2019 / 10:42:35 / Claus Gittinger"
+!
+
 test65_concatenation
     |strA strB|
 
@@ -1863,21 +1989,99 @@
     "Created: / 02-04-2019 / 10:57:44 / Claus Gittinger"
 !
 
-test90_hash
-    "all string-representations must hash equal"
+test90_enumeratingLines
     
-    | string8 string16 string32 |
+    |  |
+
+    #(
+        c''
+        c'abc'
+        c'\n'
+        c'abc\n'
+        c'\n\n'
+        c'abc\n\n'
+        c'\n\nabc'
+        c'\nabc\n'
+        c'abc\nabc\nabc'
+        c'abc\nabc\nabc\n'
+        c'abc\nabc\nabc\n\n'
+        c'a\nb\nc\n\n'
+        c'a\n\n\nb\nc\n\n\n\nd'
+    ) do:[:eachTestString |
+        |testString sColl calledWith1 calledWith2 count1 count2 countReturned|
+
+        #( yourself asUnicode16String asUnicode32String ) do:[:conv |
+            testString := eachTestString perform:conv.
+
+            "/ try asStringCollection as reference
+            sColl := testString asStringCollection.
+            count1 := 0.
+            calledWith1 := OrderedCollection new.
+            sColl do:[:each |
+                count1 := count1 + 1.
+                calledWith1 add:each.
+            ].
+
+            "/ check asCollectionOfLinesDo: 
+            count2 := 0.
+            calledWith2 := OrderedCollection new.
+            countReturned := testString asCollectionOfLinesDo:[:each |
+                count2 := count2 + 1.
+                calledWith2 add:each.
+            ].
+            self assert:(count1 == count2).
+            self assert:(count2 == countReturned).
+            self assert:(calledWith1 = calledWith2).
+        ].
+    ].
+!
 
-    string8 := 'sun/nio/cs/UTF_8.class'.
-    string16 := string8 asUnicode16String.
-    string32 := string8 asUnicode16String.
+test91_enumeratingWords
+    
+    |  |
+
+    #(
+        0 c''
+        1 c'abc'
+        0 c'\n'
+        1 c'abc\n'
+        0 c'\n\n'
+        1 c'abc\n\n'
+        1 c'\n\nabc'
+        1 c'\nabc\n'
+        3 c'abc\nabc\nabc'
+        3 c'abc\nabc\nabc\n'
+        3 c'abc\nabc\nabc\n\n'
+        3 c'a\nb\nc\n\n'
+        4 c'a\n\n\nb\nc\n\n\n\nd'
+    ) pairWiseDo:[:expectedCount :eachTestString |
+        |testString sColl calledWith1 calledWith2 count1 count2 countReturned|
 
-    self assert: string8 hash == string16 hash.
-    self assert: string8 hash == string32 hash.
-    self assert: string8 hash == string8 asSymbol hash.
+        #( yourself asUnicode16String asUnicode32String ) do:[:conv |
+            testString := eachTestString perform:conv.
+
+            "/ try asStringCollection as reference
+            sColl := testString asCollectionOfWords.
+            count1 := 0.
+            calledWith1 := OrderedCollection new.
+            sColl do:[:each |
+                count1 := count1 + 1.
+                calledWith1 add:each.
+            ].
 
-    "Created: / 09-10-2014 / 12:41:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 02-04-2019 / 10:42:35 / Claus Gittinger"
+            "/ check asCollectionOfWordsDo: 
+            count2 := 0.
+            calledWith2 := OrderedCollection new.
+            countReturned := testString asCollectionOfWordsDo:[:each |
+                count2 := count2 + 1.
+                calledWith2 add:each.
+            ].
+            self assert:(count1 == expectedCount).
+            self assert:(count1 == count2).
+            self assert:(count2 == countReturned).
+            self assert:(calledWith1 = calledWith2).
+        ].
+    ].
 ! !
 
 !StringTests class methodsFor:'documentation'!