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

test[scripting] 122 - Class and Pool names

"Creating class (aClass) and pool (APool)"
Smalltalk at: #APool put: PoolDictionary new!
APool at: #Key1 put: 1; at: #Key2 put: 2!
Object
	subclass: #AClass
	instanceVariableNames: ' iv1 iv2 '
	classVariableNames: 'ClassVar'
	poolDictionaries: 'APool'
	category: #Test!

"Set the compiler to ScriptCompiler"
! AClass class methodsFor: #compiling !
compilerSupport
	" Returns the compiler of the receiver "

	^ScriptCompiler! !

"Adding Test methods"
!AClass class methods!
sum
	^Key1 + Key2 + self classVar! !

!AClass class methods!
classVar
	ClassVar isNil ifTrue: [ ClassVar := 10 ].
	^ClassVar! !

!AClass class methods!
classVar: aValue
	ClassVar := aValue! !

!AClass class methods!
key1: aValue
	Key1 := aValue! !

!AClass methods!
key1
	^Key1! !

!AClass methods!
key2
	^Key2! !


"Method tests..."
AClass classVariableNames = #(ClassVar) ifFalse: [ self error: 'Must be #(ClassVar)' ].
AClass poolDictionaryNames = #(APool) ifFalse: [ self error: 'Must be #(APool)' ].
AClass new key1 = 1 ifFalse: [ self error: 'Must be 1' ].
AClass classVar = 10 ifFalse: [ self error: 'Must be 10' ].
1 + 2 + 10 = AClass sum ifFalse: [ self error: 'Must be 13' ].
AClass classVar: 1 + AClass classVar.
14 = AClass sum ifFalse: [ self error: 'Must be 14' ].
AClass key1: AClass new key2.
15 = AClass sum ifFalse: [ self error: 'Must be 15' ].
AClass note: #Ok.


"Scripting tests"
(((ScriptParser for: AClass) parse: 'ClassVar := 123') evaluate: AClass new) = 123 ifFalse: [ ^self error: 'Wrong result' ].

AClass classVar = 123.

(((ScriptParser for: AClass) parse: 'ClassVar - 123') evaluate: AClass new) = 0 ifFalse: [ ^self error: 'Wrong result' ].

(((ScriptParser for: AClass class) parse: 'ClassVar - 123') evaluate: AClass) = 0 ifFalse: [ ^self error: 'Wrong result' ].

APool at: #Key1 put: 7.
(((ScriptParser for: AClass) parse: 'Key1 = 7') evaluate: AClass new) ifFalse: [ ^self error: 'Wrong result' ].

(((ScriptParser for: AClass) parse: 'Key1 := 1') evaluate: AClass new) = 1 ifFalse: [ ^self error: 'Wrong result' ].
 
(((ScriptParser for: AClass) parse: 'Key1 = 1') evaluate: AClass new) ifFalse: [ ^self error: 'Wrong result' ].

AClass note: #Ok.


"Removing test class and pools"
AClass removeFromSystem.
Smalltalk removeKey: #APool ifAbsent: [].