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

test[s8] identity tests



" Test identity on multiple targets..."
|code| code := '
1 + 1 == 2 = true
1 + 1 - 1 == 2 = false
(1 + 1 - 1) toString == $1 = true
1 - 1 == nil = false
1 - 1 == false = false
1 - 1 == (1 - 2) = false
| x | x := 5@3. x == x = true
$a == #a = true
12 == 12 = true
nil == nil = true
1 + 1 == (8 - 6) = true
#(1 2 3) == #(3 2 1) reversed = false
true == #true = false
#12 == (10 + 2) = false
#1 == (1 + 1 - 1) = false
Array new == 0 = false
0 == Array new = false
0 == XXXX = false
XXXX == 0 = false
XXXX == nil = false
#(0) == 0 = false
0 == #(0) = false
#(#(0 1)) first first == 0 = true
#(#(0 1)) last last == 1 = true
#(98) == nil = false
#(7 nil) last == nil = true
nil = #(98) == false
nil == #(98 nil) last = true
#(98) last - 98 == 0 = true
self print:''// multiple identity tests complete''. true
' stream.
[code atEnd] whileFalse: [ | line |
    line := code nextLine trimBlanks.
    line notEmpty ifTrue: [
        line evaluate = true ifFalse: [
            self print: '//eqeq test failed: ',line printString
        ]
    ].
].


"Test issue #15 - Equality of primitive types behaves incorrectly"
! Boolean methodsFor: #testIdentity !
isFalse
	" Returns true if the receiver is false. "

	^self == false! !

true    isFalse ifTrue:  [ self error: 'Wrong result for true.' ].
false   isFalse ifFalse: [ self error: 'Wrong result for false.' ].
(1 = 2) isFalse ifFalse: [ self error: 'Wrong result for (1 = 2).' ].


"Test (obsolete) #yourself hacks"
123 yourself == 123 ifFalse: [ self error: 'Failed for Number' ].
true yourself == true ifFalse: [ self error: 'Failed for Boolean' ].
#new yourself == #new ifFalse: [ self error: 'Failed for String' ].
(5@3) yourself == (5@3) ifTrue: [ self error: 'Failed for Point' ].