RegressionTests__StreamTests.st
changeset 1213 0de4acfc2597
parent 1085 29bb4657f206
child 1249 3b882caff8e6
--- a/RegressionTests__StreamTests.st	Fri Sep 26 16:10:52 2014 +0200
+++ b/RegressionTests__StreamTests.st	Sat Oct 04 22:29:18 2014 +0200
@@ -85,6 +85,188 @@
     "
 
     "Created: / 16-09-2011 / 15:26:10 / cg"
+!
+
+test02_readStream
+    {
+        #($a $b $c $d $a $b $c $d $a $b $c $d $a $b $c $d) .
+        #[97 98 99 100 97 98 99 100 97 98 99 100]          .
+        'abcdabcdabcdabcd'                                 .
+        'abcdabcdabcdabcd' asUnicode16String               .
+        'abcdabcdabcdabcd' asUnicode32String               .
+    } do:[:coll|
+        |s e t|
+
+        s := coll readStream.
+
+        "/ initial state?
+        self assert:(s atEnd not).
+        self assert:(s position == 0).
+        "/ peek returns the correct value
+        e := s peek.
+        self assert:(e asInteger == 97).
+
+        "/ peek should not change any state
+        self assert:(s atEnd not).
+        self assert:(s position == 0).
+        e := s next.
+        self assert:(e asInteger == 97).
+        self assert:(s position == 1).
+        self assert:(s atEnd not).
+
+        e := s peek.
+        self assert:(s position == 1).
+        self assert:(e asInteger == 98).
+
+        s position:0.
+        self assert:(s atEnd not).
+        self assert:(s position == 0).
+        e := s peek.
+        self assert:(e asInteger == 97).
+
+        s position:coll size.
+        self assert:(s atEnd).
+        self assert:(s position == coll size).
+
+        s position:0.
+        self assert:(s position == 0).
+        e := s peek.
+        self assert:(e asInteger == 97).
+
+        t := s next:2.
+        self assert:(t size == 2).
+        self assert:(t at:1) asInteger == 97.
+        self assert:(t at:2) asInteger == 98.
+        self assert:(s position == 2).
+
+        s position:1.
+        self assert:(s position == 1).
+        e := s peek.
+        self assert:(e asInteger == 98).
+        t := s upTo:(coll at:1).
+        self assert:(t size == 3).
+        self assert:(t at:1) == (coll at:2).
+        self assert:(t at:2) == (coll at:3).
+        self assert:(t at:3) == (coll at:4).
+
+        self assert:(s position == 5).
+        self assert:(s peek asInteger == (coll at:2) asInteger).
+
+        s position:1.
+        (coll at:1) isCharacter ifTrue:[
+            s skipSeparators.
+            self assert:(s position == 1).
+        ].
+
+        s position:(coll size - 1).
+        t := s upToEnd.
+        self assert:(s position == coll size).
+        self assert:(t size == 1).
+        self assert:(t at:1) == (coll at:coll size).
+
+        s position:0.
+        (coll at:1) isCharacter ifTrue:[
+            t := s nextAlphaNumericWord.
+            self assert:(t asArray = coll asArray).
+            self assert:(s position == coll size).
+        ].
+        
+    ].
+
+    "
+     self run:#test02_readStream
+     self new test02_readStream
+    "
+!
+
+test03_readStream
+    {
+        #($a $b $c $d $ $a $b $c $d $a $b $c $d $a $b $c $d) .
+        #[97 98 99 100 20 97 98 99 100 97 98 99 100]          .
+        'abcd abcdabcdabcd'                                 .
+        'abcd abcdabcdabcd' asUnicode16String               .
+        'abcd abcdabcdabcd' asUnicode32String               .
+    } do:[:coll|
+        |s e t|
+
+        s := coll readStream.
+
+        s position:3.
+        (coll at:1) isCharacter ifTrue:[
+            s skipSeparators.
+            self assert:(s position == 3).
+            s next.
+            s skipSeparators.
+            self assert:(s position == 5).
+        ].
+
+        s position:0.
+        (coll at:1) isCharacter ifTrue:[
+            t := s nextAlphaNumericWord.
+            self assert:(t asArray = (coll asArray copyTo:4)).
+            self assert:(s position == 4).
+        ].
+        
+    ].
+
+    "
+     self run:#test02_readStream
+     self new test02_readStream
+    "
+!
+
+test04_readIntegers
+    |s n|
+
+         "0123456789012345678901"
+    s := '1234 56789    123    ' readStream.
+    self assert:((n := s nextDecimalInteger) == 1234).
+    self assert:(s position == 4).
+
+    s skipSeparators.
+    self assert:(s position == 5).
+
+    self assert:((n := s nextDecimalInteger) == 56789).
+    self assert:(s position == 10).
+
+    s skipSeparators.
+    self assert:(s position == 14).
+
+    self assert:((n := s nextDecimalInteger) == 123).
+    self assert:(s position == 17).
+
+    "/ is this the correct behavior?
+    self assert:((n := s nextDecimalInteger) == 0).
+    self assert:(s position == 17).
+
+    "
+     self run:#test04_readIntegers
+     self new test04_readIntegers
+    "
+!
+
+test05_readAlphanumericWords
+    |s w|
+
+         "0123456789012345678901"
+    s := 'a234 b6789    c23    ' readStream.
+    self assert:((w := s nextAlphaNumericWord) = 'a234').
+    self assert:(s position == 4).
+
+    self assert:((w := s nextAlphaNumericWord) = 'b6789').
+    self assert:(s position == 10).
+
+    self assert:((w := s nextAlphaNumericWord) = 'c23').
+    self assert:(s position == 17).
+
+    "/ is this the correct behavior?
+    self assert:((w := s nextAlphaNumericWord) isNil).
+    self assert:(s position == 21).
+
+    "
+     self run:#test05_readAlphanumericWords
+     self new test05_readAlphanumericWords
+    "
 ! !
 
 !StreamTests class methodsFor:'documentation'!