|
1 "{ Package: 'stx:goodies/petitparser/compiler/tests' }" |
|
2 |
|
3 "{ NameSpace: Smalltalk }" |
|
4 |
|
5 TestCase subclass:#PPCClassBuilderTest |
|
6 instanceVariableNames:'builder method1 result' |
|
7 classVariableNames:'' |
|
8 poolDictionaries:'' |
|
9 category:'PetitCompiler-Tests-Core' |
|
10 ! |
|
11 |
|
12 !PPCClassBuilderTest methodsFor:'as yet unclassified'! |
|
13 |
|
14 foo |
|
15 ^ PPCMethod new |
|
16 id: #foo; |
|
17 code: '^ 1'; |
|
18 yourself |
|
19 ! |
|
20 |
|
21 setUp |
|
22 super setUp. |
|
23 builder := PPCClassBuilder new. |
|
24 ! |
|
25 |
|
26 tearDown |
|
27 super tearDown. |
|
28 result removeFromSystem. |
|
29 ! |
|
30 |
|
31 testCompileClass |
|
32 builder compiledClassName: #PPCGenerated. |
|
33 builder compiledSuperclass: Object. |
|
34 |
|
35 method1 := self foo. |
|
36 builder methodDictionary at: #foo put: method1. |
|
37 |
|
38 builder instvars add: #foo. |
|
39 |
|
40 builder constants at: #foobar put: #foobar. |
|
41 builder constants at: #barbar put: #barbar. |
|
42 |
|
43 result := builder compileClass. |
|
44 |
|
45 self assert: result isNil not. |
|
46 self assert: result name = #PPCGenerated. |
|
47 self assert: result superclass = Object. |
|
48 |
|
49 self assert: result methodDictionary size =1. |
|
50 self assert: result instanceVariables size = 1. |
|
51 self assert: result classVariables size = 2. |
|
52 self assert: (result classVariableNamed: #foobar) value = #foobar. |
|
53 self assert: (result classVariableNamed: #barbar) value = #barbar. |
|
54 |
|
55 self assert: result new foo = 1. |
|
56 ! |
|
57 |
|
58 testCompileClass2 |
|
59 Object subclass: #PPCGenerated |
|
60 instanceVariableNames: '' |
|
61 classVariableNames: 'foobar' |
|
62 category: 'PetitCompiler-generated'. |
|
63 |
|
64 (Smalltalk at: #PPCGenerated) compileSilently: 'bar ^ 12' classified: 'test'. |
|
65 (Smalltalk at: #PPCGenerated) compileSilently: 'foo ^ 123' classified: 'generated'. |
|
66 (Smalltalk at: #PPCGenerated) compileSilently: 'foo2 ^ 1234' classified: 'generated'. |
|
67 |
|
68 builder compiledClassName: #PPCGenerated. |
|
69 builder compiledSuperclass: Object. |
|
70 |
|
71 method1 := self foo. |
|
72 builder methodDictionary at: #foo put: method1. |
|
73 |
|
74 result := builder compileClass. |
|
75 |
|
76 self assert: result isNil not. |
|
77 self assert: result name = #PPCGenerated. |
|
78 self assert: result superclass = Object. |
|
79 self assert: result methodDictionary size = 2. |
|
80 |
|
81 self assert: result classVariables size = 0. |
|
82 |
|
83 self assert: result new foo = 1. |
|
84 self assert: result new bar = 12. |
|
85 ! |
|
86 |
|
87 testCompileClass3 |
|
88 Object subclass: #PPCGenerated |
|
89 instanceVariableNames: '' |
|
90 classVariableNames: 'foobar' |
|
91 category: 'PetitCompiler-generated'. |
|
92 |
|
93 (Smalltalk at: #PPCGenerated) compileSilently: 'foo ^ 123' classified: 'testing'. |
|
94 |
|
95 builder compiledClassName: #PPCGenerated. |
|
96 builder compiledSuperclass: Object. |
|
97 |
|
98 method1 := self foo. |
|
99 builder methodDictionary at: #foo put: method1. |
|
100 |
|
101 result := builder compileClass. |
|
102 |
|
103 self assert: result isNil not. |
|
104 self assert: result name = #PPCGenerated. |
|
105 self assert: result superclass = Object. |
|
106 self assert: result methodDictionary size = 1. |
|
107 |
|
108 self assert: result new foo = 123. |
|
109 ! ! |
|
110 |