/
ClassVariableTest.class.st
107 lines (80 loc) · 2.89 KB
/
ClassVariableTest.class.st
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
"
Tests for ClassVariable
"
Class {
#name : #ClassVariableTest,
#superclass : #TestCase,
#classVars : [
'TestVariable'
],
#category : #'Slot-Tests-VariablesAndSlots'
}
{ #category : #'tests - properties' }
ClassVariableTest >> testIsReadInMethod [
DefaultTimeLimit printString. "reading class variable".
self assert: ((TestCase classVariableNamed: #DefaultTimeLimit) isReadIn: self class >> testSelector)
]
{ #category : #'tests - properties' }
ClassVariableTest >> testIsWrittenInMethod [
DefaultTimeLimit := DefaultTimeLimit. "writing class variable".
self assert: ((TestCase classVariableNamed: #DefaultTimeLimit) isWrittenIn: self class >> testSelector)
]
{ #category : #'tests - properties' }
ClassVariableTest >> testNotReadInMethod [
self deny: ((TestCase classVariableNamed: #DefaultTimeLimit) isReadIn: self class >> testSelector)
]
{ #category : #'tests - properties' }
ClassVariableTest >> testNotWrittenInMethodWhenItIsOnlyRead [
DefaultTimeLimit printString. "reading class variable".
self deny: ((TestCase classVariableNamed: #DefaultTimeLimit) isWrittenIn: self class >> testSelector)
]
{ #category : #'tests - properties' }
ClassVariableTest >> testPropertyAtPut [
| testValue classVariable |
testValue := Date today.
classVariable := self class classVariableNamed: #TestVariable.
classVariable propertyAt: #testKeySelector put: testValue.
self
assert: (classVariable propertyAt: #testKeySelector)
equals: testValue.
TestVariable := 5. "of course changing the var does not change the property"
self
assert: (classVariable propertyAt: #testKeySelector)
equals: testValue.
classVariable removeProperty: #testKeySelector.
self assert: classVariable properties isNil.
]
{ #category : #'tests - properties' }
ClassVariableTest >> testReadingFromContext [
| classVariable |
TestVariable := #testValue.
classVariable := self class classVariableNamed: #TestVariable.
self
assert: (classVariable readInContext: thisContext)
equals: #testValue
]
{ #category : #'tests - properties' }
ClassVariableTest >> testRemoveProperty [
| classVariable |
classVariable := self class classVariableNamed: #TestVariable.
classVariable propertyAt: #testKeySelector put: 1.
classVariable removeProperty: #testKeySelector.
self
assert: (classVariable propertyAt: #testKeySelector)
equals: nil.
self assert: classVariable properties isNil.
]
{ #category : #tests }
ClassVariableTest >> testScope [
| variable |
variable := SmalltalkImage classVariableNamed: #CompilerClass.
self assert: variable scope equals: SmalltalkImage.
self assert: (variable scope lookupVar: variable name) equals: variable
]
{ #category : #'tests - properties' }
ClassVariableTest >> testWritingToContext [
| classVariable |
classVariable := self class classVariableNamed: #TestVariable.
classVariable write: #testValue inContext: thisContext.
self assert: TestVariable equals: #testValue
]