-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIOSCompiler.test.ts
More file actions
265 lines (225 loc) · 7.55 KB
/
Copy pathIOSCompiler.test.ts
File metadata and controls
265 lines (225 loc) · 7.55 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
/**
* IOSCompiler Tests
*
* Tests for the HoloScript → iOS Swift ARKit compiler.
* Verifies correct Swift code generation for ARKit experiences.
*/
import { describe, it, expect, beforeEach } from 'vitest';
import { IOSCompiler, type IOSCompilerOptions } from './IOSCompiler';
import type { HoloComposition, HoloObjectDecl } from '../parser/HoloCompositionTypes';
describe('IOSCompiler', () => {
let compiler: IOSCompiler;
beforeEach(() => {
compiler = new IOSCompiler();
});
// Helper to create a minimal composition
function createComposition(overrides: Partial<HoloComposition> = {}): HoloComposition {
return {
type: 'Composition',
name: 'TestARScene',
objects: [],
templates: [],
spatialGroups: [],
lights: [],
imports: [],
timelines: [],
audio: [],
zones: [],
transitions: [],
conditionals: [],
iterators: [],
npcs: [],
quests: [],
abilities: [],
dialogues: [],
stateMachines: [],
achievements: [],
talentTrees: [],
shapes: [],
...overrides,
};
}
// Helper to create an object declaration
function createObject(name: string, overrides: Partial<HoloObjectDecl> = {}): HoloObjectDecl {
return {
name,
properties: [],
traits: [],
...overrides,
} as HoloObjectDecl;
}
describe('Basic Compilation', () => {
it('should create a compiler instance', () => {
expect(compiler).toBeDefined();
expect(compiler).toBeInstanceOf(IOSCompiler);
});
it('should compile an empty composition', () => {
const composition = createComposition();
const result = compiler.compile(composition);
expect(result).toBeDefined();
expect(result.viewFile).toBeDefined();
expect(result.sceneFile).toBeDefined();
expect(result.stateFile).toBeDefined();
expect(result.infoPlist).toBeDefined();
});
it('should generate valid Swift imports', () => {
const composition = createComposition();
const result = compiler.compile(composition);
expect(result.viewFile).toContain('import SwiftUI');
expect(result.sceneFile).toContain('import ARKit');
});
it('should use custom class name', () => {
const customCompiler = new IOSCompiler({ className: 'CustomARView' });
const composition = createComposition();
const result = customCompiler.compile(composition);
expect(result.viewFile).toContain('CustomARView');
});
});
describe('iOS Versions', () => {
it('should support iOS 17.0', () => {
const customCompiler = new IOSCompiler({ iosVersion: '17.0' });
const composition = createComposition();
const result = customCompiler.compile(composition);
expect(result.viewFile).toContain('17.0');
});
it('should support iOS 15.0', () => {
const customCompiler = new IOSCompiler({ iosVersion: '15.0' });
const composition = createComposition();
const result = customCompiler.compile(composition);
expect(result.viewFile).toContain('15.0');
});
});
describe('Object Compilation', () => {
it('should compile objects with geometry', () => {
const composition = createComposition({
objects: [
createObject('TestSphere', {
properties: [
{ key: 'geometry', value: 'sphere' },
{ key: 'position', value: [0, 0, -1] },
],
}),
],
});
const result = compiler.compile(composition);
expect(result.sceneFile).toContain('TestSphere');
});
it('should compile objects with colors', () => {
const composition = createComposition({
objects: [
createObject('ColoredCube', {
properties: [
{ key: 'geometry', value: 'cube' },
{ key: 'color', value: '#ff0000' },
],
}),
],
});
const result = compiler.compile(composition);
expect(result.sceneFile).toContain('ColoredCube');
});
it('should compile interactive objects', () => {
const composition = createComposition({
objects: [
createObject('TappableObject', {
traits: ['clickable'],
properties: [{ key: 'geometry', value: 'cube' }],
}),
],
});
const result = compiler.compile(composition);
expect(result.sceneFile).toContain('TappableObject');
});
});
describe('SwiftUI Integration', () => {
it('should use SwiftUI by default', () => {
const composition = createComposition();
const result = compiler.compile(composition);
expect(result.viewFile).toContain('SwiftUI');
});
it('should support disabling SwiftUI', () => {
const customCompiler = new IOSCompiler({ useSwiftUI: false });
const composition = createComposition();
const result = customCompiler.compile(composition);
expect(result.viewFile).toBeDefined();
});
});
describe('RealityKit Support', () => {
it('should not use RealityKit by default', () => {
const composition = createComposition();
const result = compiler.compile(composition);
// Default uses ARKit/SceneKit
expect(result.sceneFile).toContain('ARKit');
});
it('should support RealityKit when enabled', () => {
const customCompiler = new IOSCompiler({ useRealityKit: true });
const composition = createComposition();
const result = customCompiler.compile(composition);
expect(result.sceneFile).toBeDefined();
});
});
describe('Info.plist Generation', () => {
it('should generate valid Info.plist', () => {
const composition = createComposition();
const result = compiler.compile(composition);
expect(result.infoPlist).toContain('<?xml version');
expect(result.infoPlist).toContain('plist');
});
it('should include camera usage description', () => {
const composition = createComposition();
const result = compiler.compile(composition);
expect(result.infoPlist).toContain('NSCameraUsageDescription');
});
});
describe('Lights Compilation', () => {
it('should compile directional lights', () => {
const composition = createComposition({
lights: [
{
name: 'SunLight',
lightType: 'directional',
properties: [
{ key: 'color', value: '#ffffff' },
{ key: 'intensity', value: 1.0 },
],
},
],
});
const result = compiler.compile(composition);
expect(result.sceneFile).toContain('SunLight');
});
it('should compile ambient lights', () => {
const composition = createComposition({
lights: [
{
name: 'AmbientLight',
lightType: 'ambient',
properties: [
{ key: 'color', value: '#aaaaaa' },
{ key: 'intensity', value: 0.5 },
],
},
],
});
const result = compiler.compile(composition);
expect(result.sceneFile).toBeDefined();
});
});
describe('State Management', () => {
it('should generate state file', () => {
const composition = createComposition({
objects: [
createObject('StatefulObject', {
properties: [
{ key: 'geometry', value: 'cube' },
{ key: 'state', value: { count: 0 } },
],
}),
],
});
const result = compiler.compile(composition);
expect(result.stateFile).toBeDefined();
expect(result.stateFile.length).toBeGreaterThan(0);
});
});
});