RegressionTests__CollectionTests.st
branchjv
changeset 2039 74c3ad75b376
parent 1986 3408db0c1c35
--- a/RegressionTests__CollectionTests.st	Tue May 29 13:25:30 2018 +0200
+++ b/RegressionTests__CollectionTests.st	Tue May 29 15:07:45 2018 +0200
@@ -1350,6 +1350,109 @@
     "Created: / 29-05-2018 / 12:53:31 / svestkap"
     "Modified (comment): / 29-05-2018 / 14:04:22 / svestkap"
     "Modified: / 15-07-2018 / 10:18:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+testSequenceableCollection_02_asCollectionOfSubCollectionsSeparatedByAnyForWhich
+
+    | aString stringCollection |
+
+    aString := 'helloWorldHereICome'.
+    stringCollection := aString asCollectionOfSubCollectionsSeparatedByAnyForWhich: [ :ch | ch isUppercase ] withSeparatorsIncluded: false.
+    self assert: (stringCollection size = 4).    
+    self assert: (stringCollection first = 'hello').
+    self assert: ((stringCollection last) size = 3).
+    self assert: (stringCollection last = 'ome').    
+
+    aString := 'helloWorldHereICome'.
+    stringCollection := aString asCollectionOfSubCollectionsSeparatedByAnyForWhich: [ :ch | ch isUppercase ] withSeparatorsIncluded: true.
+    self assert: (stringCollection size = 5).    
+    self assert: (stringCollection first = 'hello').
+    self assert: ((stringCollection last) first = $C).  
+    self assert: ((stringCollection last) size = 4).  
+    self assert: (stringCollection last = 'Come').    
+        
+    aString := '1Tim2Jones3Iva4Tom'.
+    stringCollection := aString asCollectionOfSubCollectionsSeparatedByAnyForWhich: [ :ch | ch isDigit ] withSeparatorsIncluded: false.
+    self assert: (stringCollection size = 4).    
+    self assert: (stringCollection first = 'Tim').
+    self assert: ((stringCollection last) size = 3).
+    self assert: (stringCollection last = 'Tom').      
+
+    aString := '1Tim2Jones3Iva4Tom'.
+    stringCollection := aString asCollectionOfSubCollectionsSeparatedByAnyForWhich: [ :ch | ch isDigit ] withSeparatorsIncluded: true.
+    self assert: (stringCollection size = 4).    
+    self assert: (stringCollection first = '1Tim').
+    self assert: ((stringCollection last) first = $4).  
+    self assert: ((stringCollection last) size = 4).  
+    self assert: (stringCollection last = '4Tom').    
+
+    aString := '9Tim2Jones3Iva8Tom'.
+    stringCollection := aString asCollectionOfSubCollectionsSeparatedByAnyForWhich: [ :ch | ch isDigit ] withSeparatorsIncluded: true.   
+    stringCollection := (stringCollection copy) collect:[:eachString | 
+        eachString asCollectionOfSubCollectionsSeparatedByAnyForWhich: [ :ch | ch isUppercase ] withSeparatorsIncluded: true.
+    ].    
+    stringCollection := (stringCollection copy) flatten.
+    self assert: (stringCollection size = 8).   
+    self assert: ((stringCollection first) = '9').
+    self assert: ((stringCollection last) = 'Tom').  
+
+    "
+     self new testSequenceableCollection_02_asCollectionOfSubCollectionsSeparatedByAnyForWhich    
+    "
+
+    "Created: / 29-05-2018 / 14:09:08 / svestkap"
+!
+
+testSequenceableCollection_03_splitByAnyForWhich
+
+    | aString stringCollection |
+
+    aString := 'helloWorldHereICome'.
+    stringCollection := aString splitByAnyForWhich: [ :ch | ch isUppercase ] withSeparatorIncluded: false.
+    self assert: (stringCollection size = 4).    
+    self assert: (stringCollection first = 'hello').
+    self assert: ((stringCollection last) size = 3).
+    self assert: (stringCollection last = 'ome').    
+
+    aString := 'helloWorldHereICome'.
+    stringCollection := aString splitByAnyForWhich: [ :ch | ch isUppercase ] withSeparatorIncluded: true.
+    self assert: (stringCollection size = 5).    
+    self assert: (stringCollection first = 'hello').
+    self assert: ((stringCollection last) first = $C).  
+    self assert: ((stringCollection last) size = 4).  
+    self assert: (stringCollection last = 'Come').    
+
+    aString := '1Tim2Jones3Iva4Tom'.
+    stringCollection := aString splitByAnyForWhich: [ :ch | ch isDigit ] withSeparatorIncluded: false.
+    self assert: (stringCollection size = 4).    
+    self assert: (stringCollection first = 'Tim').
+    self assert: ((stringCollection last) size = 3).
+    self assert: (stringCollection last = 'Tom').      
+
+    aString := '1Tim2Jones3Iva4Tom'.
+    stringCollection := aString splitByAnyForWhich: [ :ch | ch isDigit ] withSeparatorIncluded: true.
+    self assert: (stringCollection size = 4).    
+    self assert: (stringCollection first = '1Tim').
+    self assert: ((stringCollection last) first = $4).  
+    self assert: ((stringCollection last) size = 4).  
+    self assert: (stringCollection last = '4Tom').    
+
+    aString := '9Tim2Jones3Iva8Tom'.
+    stringCollection := aString splitByAnyForWhich: [ :ch | ch isDigit ] withSeparatorIncluded: true.   
+    stringCollection := (stringCollection copy) collect:[:eachString | 
+        eachString splitByAnyForWhich: [ :ch | ch isUppercase ] withSeparatorIncluded: true.
+    ].    
+    stringCollection := (stringCollection copy) flatten.
+    self assert: (stringCollection size = 8).   
+    self assert: ((stringCollection first) = '9').
+    self assert: ((stringCollection last) = 'Tom').  
+
+    "
+     self new testSequenceableCollection_03_splitByAnyForWhich
+    "
+
+    "Created: / 29-05-2018 / 14:50:13 / svestkap"
+    "Modified: / 13-10-2018 / 09:31:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !CollectionTests methodsFor:'tests-sorting'!