0
|
1 |
"{ Package: 'stx:goodies/ring/tests' }"
|
|
2 |
|
|
3 |
"{ NameSpace: Smalltalk }"
|
|
4 |
|
|
5 |
TestCase subclass:#RGVariableDefinitionTest
|
|
6 |
instanceVariableNames:''
|
|
7 |
classVariableNames:''
|
|
8 |
poolDictionaries:''
|
|
9 |
category:'Ring-Core-Kernel-Tests'
|
|
10 |
!
|
|
11 |
|
|
12 |
RGVariableDefinitionTest comment:'SUnit tests for variable definitions'
|
|
13 |
!
|
|
14 |
|
|
15 |
!RGVariableDefinitionTest methodsFor:'testing'!
|
|
16 |
|
|
17 |
testClassInstanceVariable
|
|
18 |
| instVar newClass metaClass |
|
|
19 |
|
|
20 |
instVar:= RGClassInstanceVariableDefinition named: 'sizes'.
|
|
21 |
|
|
22 |
self assert: (instVar isClassInstanceVariable).
|
|
23 |
self assert: (instVar isVariable).
|
|
24 |
self assert: (instVar name = 'sizes').
|
|
25 |
self assert: (instVar parent isNil).
|
|
26 |
self assert: (instVar isMetaSide).
|
|
27 |
|
|
28 |
newClass:= RGClassDefinition named: #OrderedCollection.
|
|
29 |
newClass withMetaclass.
|
|
30 |
metaClass:= newClass theMetaClass.
|
|
31 |
instVar:= metaClass addInstVarNamed: 'sizes'.
|
|
32 |
self assert: (instVar parent = metaClass).
|
|
33 |
self assert: (metaClass instanceVariables size = 1).
|
|
34 |
!
|
|
35 |
|
|
36 |
testClassVariable
|
|
37 |
| instVar newClass |
|
|
38 |
|
|
39 |
instVar:= RGClassVariableDefinition named: 'DependentsFields'.
|
|
40 |
|
|
41 |
self assert: (instVar isClassVariable).
|
|
42 |
self assert: (instVar isVariable).
|
|
43 |
self assert: (instVar name = 'DependentsFields').
|
|
44 |
self assert: (instVar parent isNil).
|
|
45 |
self assert: (instVar isMetaSide not).
|
|
46 |
|
|
47 |
newClass:= RGClassDefinition named: #Object.
|
|
48 |
instVar:= (RGClassVariableDefinition named: 'DependentsFields') parent: newClass.
|
|
49 |
|
|
50 |
self assert: (instVar parent = newClass).
|
|
51 |
self assert: (newClass classVariables isEmpty).
|
|
52 |
|
|
53 |
newClass classVariables add: instVar.
|
|
54 |
self assert: (newClass classVariables size = 1).
|
|
55 |
!
|
|
56 |
|
|
57 |
testInstanceVariable
|
|
58 |
| instVar newClass |
|
|
59 |
|
|
60 |
instVar:= RGInstanceVariableDefinition named: 'size'.
|
|
61 |
|
|
62 |
self assert: (instVar isInstanceVariable).
|
|
63 |
self assert: (instVar isVariable).
|
|
64 |
self assert: (instVar name = 'size').
|
|
65 |
self assert: (instVar parent isNil).
|
|
66 |
self assert: (instVar isMetaSide not).
|
|
67 |
|
|
68 |
newClass:= RGClassDefinition named: #OrderedCollection.
|
|
69 |
instVar:= newClass addInstVarNamed: 'array'.
|
|
70 |
self assert: (instVar parent = newClass).
|
|
71 |
self assert: (newClass instanceVariables size = 1).
|
|
72 |
!
|
|
73 |
|
|
74 |
testPoolVariable
|
|
75 |
| poolVar newClass |
|
|
76 |
|
|
77 |
poolVar:= RGPoolVariableDefinition named: 'TextConstants'.
|
|
78 |
|
|
79 |
self assert: (poolVar isPoolVariable).
|
|
80 |
self assert: (poolVar isVariable).
|
|
81 |
self assert: (poolVar name = 'TextConstants').
|
|
82 |
self assert: (poolVar parent isNil).
|
|
83 |
self assert: (poolVar isMetaSide not).
|
|
84 |
|
|
85 |
newClass:= RGClassDefinition named: #OrderedCollection.
|
|
86 |
poolVar:= (RGPoolVariableDefinition named: 'TextConstants' ) parent: newClass.
|
|
87 |
self assert: (poolVar parent = newClass).
|
|
88 |
self assert: (newClass sharedPools isEmpty).
|
|
89 |
|
|
90 |
newClass sharedPools add: poolVar.
|
|
91 |
self assert: (newClass sharedPools size = 1).
|
|
92 |
!
|
|
93 |
|
|
94 |
testVariableEquality
|
|
95 |
|
|
96 |
| variable1 variable2|
|
|
97 |
|
|
98 |
variable1 := (OrderedCollection asRingDefinition) instanceVariableNamed: #array.
|
|
99 |
variable2 := (OrderedCollection asRingDefinition) instanceVariableNamed: #array.
|
|
100 |
self assert: variable1 = variable2.
|
|
101 |
|
|
102 |
variable1 := (RGClassVariableDefinition named: #Foo) parentName: #Test.
|
|
103 |
variable2 := (RGClassVariableDefinition named: #Foo) parentName: #Test.
|
|
104 |
self assert: variable1 = variable2.
|
|
105 |
|
|
106 |
variable2 := (RGClassVariableDefinition named: #Foo) parentName: #Test2.
|
|
107 |
self deny: variable1 = variable2.
|
|
108 |
|
|
109 |
! !
|
|
110 |
|