[View]  [Edit]  [Lock]  [References]  [Attachments]  [History]  [Home]  [Changes]  [Search]  [Help] 

sunit[s8] literal arrays

This test verify that literal Arrays are instantiated ok.
Note we use #doIt to force compilation during evaluation of test expressions.

TestCase 
   subclass: #TestLiteralArrays
   instanceVariableNames: ''
   category: 'sunit-s8'!

! TestLiteralArrays methodsFor: 'test'!
testEmpty

   | empty |
   empty := '#()' doIt.	
   self assert: (empty isArray and: [empty size = 0 ])! !

! TestLiteralArrays methodsFor: 'test'!
testWithNumbers
   "Test simple literal array with numbers"
   
   | sample |
   sample := '#( 1 2.3 3.1 4 )' doIt.
   self assert: (sample size = 4)! !

! TestLiteralArrays methodsFor: 'test'!
testWithSymbols
   "Test simple literal array with symbols (no #)"

   | array |
   array := '#( one #two )' doIt.
   self assert: (((array isArray and:[array size = 2]) 
                   and:[array first isString]) 
                   and: [array second isString])! !

! TestLiteralArrays methodsFor: 'test'!
testWithUppercaseSymbols
   "Test literal array with uppercase symbols"

   | array |
   array := '#( One #Two )' doIt.
   self assert: (((array isArray and:[array size = 2]) 
                   and:[array first isString]) 
                   and: [array second isString])! !

! TestLiteralArrays methodsFor: 'test'!
testWithHeterogeneousSymbols
   "Test simple literal array with heterogeneous content"
   
   | array |
   array := '#( 1.2 + 5 new #new new: New: Point nil true false under_scored )' doIt.
   self assert: ((((((((((((
		(array isArray and:[array size = 12]) 
		and:[array first isNumber]) 
                and:[array second isString]) 
                and:[array third  isNumber]) 
                and:[array fourth isString]) 
                and:[(array at:5) isString]) 
                and:[(array at:6) isString]) 
                and:[(array at:7) isString]) 
                and:[(array at:8) isString]) 
                and:[(array at:9) isNil]) 
                 and:[(array at:10) isMemberOf: Boolean]) 
                and:[(array at:11) isMemberOf: Boolean]) 
                and:[(array at:12) isString]).! !

! TestLiteralArrays methodsFor: 'test'!
testNestedLiteral
   "Test nested literal arrays"
   
   | array root nested |
   array := '#( One #(Two nil #() ) )' doIt.
   root := ((
             (array isArray and:[ array size = 2]) 
              and:[array first  isString]) 
              and:[array second isArray]).
   nested := (((array second first isString 
              and:[array second second isNil]) 
              and:[((array at:2) at: 3) isArray]) 
              and:[((array at:2) at: 3) isEmpty]).
   self assert: (root and:[nested])! !