[View] [Edit] [Lock] [References] [Attachments] [History] [Home] [Changes] [Search] [Help]
test[scripting] 130 - Literals
"literal array"
| literal |
literal := (ScriptParser new parse: ('
#( 1 2 3
"four" "a""string"
#aSymbol
#( 1 2 3 )
$A $b $c
true false nil
)
' replace: $" with: $')) evaluate.
literal first = 1 ifFalse: [ self error: 'Must be 1' ].
(literal copyFrom: 1 to: 3) = #(1 2 3) ifFalse: [ self error: 'Must be #(1 2 3)' ].
literal fourth = #four ifFalse: [ self error: 'Must be ',#four printString ].
((literal at: 5) includes: $') ifFalse: [ self error: 'Must have a $''.' ].
(literal at: 6) = #aSymbol ifFalse: [ self error: 'Must be #aSymbol' ].
(literal at: 7) = #(1 2 3) ifFalse: [ self error: 'Must be subarray #(1 2 3)' ].
(literal at: 8) isCharacter ifFalse: [ self error: 'Must be a Character' ].
(literal at: 8) = $A ifFalse: [ self error: 'Must be $A' ].
(literal at: 11) == true ifFalse: [ self error: 'Must be true' ].
(literal at: 11) == (literal at: 12) not ifFalse: [ self error: 'Must be true vs. false' ].
literal last isNil ifFalse: [ self error: 'Must be nil' ].
literal size = 13 ifFalse: [ self error: 'Size must be 13' ].
"wrong asignment to literal array"
| syntax |
syntax := ScriptParser new parse: (' #( 1 2 3 ) := 5 ').
syntax isParseFailure ifFalse: [ self error: 'Must be a failure' ].
"character literal"
| literal |
literal := (ScriptParser new parse: ' $A ') evaluate.
literal isCharacter ifFalse: [ self error: 'Must be a Character' ].
literal = $A ifFalse: [ self error: 'Must be $A' ].
"wrong asignment to Character literal"
| syntax |
syntax := ScriptParser new parse: (' $A := 5 ').
syntax isParseFailure ifFalse: [ self error: 'Must be a failure' ].
"number literal"
| literal |
literal := (ScriptParser new parse: ' 123.24 ') evaluate.
literal isNumber ifFalse: [ self error: 'Must be a Number' ].
literal * 100 = 12324 ifFalse: [ self error: 'Must be 123.24' ].
"wrong asignment to number literal"
| syntax |
syntax := ScriptParser new parse: (' 123 := 5 ').
syntax isParseFailure ifFalse: [ self error: 'Must be a failure' ].