-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtests.js
More file actions
222 lines (170 loc) · 7.62 KB
/
tests.js
File metadata and controls
222 lines (170 loc) · 7.62 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
import { Classes } from './src/classes.js';
import Constantes from './src/constantes.js';
import { BombObject } from './src/bombObject.js';
export class Tests {
constructor() {
}
async launchTests() {
let names = Object.getOwnPropertyNames (Object.getPrototypeOf (this));
let filtered = names.filter(propName => ( propName !== 'constructor' && /* remove constructor */
propName !== 'launchTests' && /* remove own call */
typeof this[propName] === 'function'));
for (let i = 0; i < filtered.length; i++) {
const methodName = filtered[i];
await this[methodName]();
}
}
Test() {
console.log( '--------------SHOW DEFINITION/EXPLODED OBJECTS-------------------');
let perfil = new BombObject();
perfil.reference = '=this.margin.left';
perfil.margin.left = 50;
var exploded = perfil.explode();
//exploded.reference should be resolved, with a value of 50
console.log( perfil );
console.log( exploded );
}
TestFormula() {
console.log( '--------------CHECK SIMPLE FORMULA-------------------');
let perfil = new BombObject();
perfil.reference = '=this.margin.left';
perfil.margin.left = 50;
let exploded = perfil.explode();
console.log( exploded.reference === 50 ? 'CORRECT' : 'ERROR' );
}
TestMethodFormula() {
console.log( '--------------CHECK METHOD FORMULA-------------------');
let perfil = new BombObject();
perfil.reference = `={
if( this.margin.left === 50) {
this.margin.top = 15;
}
return 1000;
}`;
perfil.margin.left = 50;
let exploded = perfil.explode();
console.log( exploded.margin.top === 15 && exploded.reference === 1000 ? 'CORRECT' : 'ERROR' );
}
TestNestedFormula() {
console.log( '--------------CHECK NESTED FORMULA-------------------');
let perfil = new BombObject();
perfil.reference = '=this.margin.left';
perfil.margin.left = 50;
perfil.margin.right = '=this.margin.left - 25;';
let exploded = perfil.explode();
console.log( exploded.margin.right === 25 ? 'CORRECT' : 'ERROR' );
}
TestConsoleLog() {
console.log( '--------------CHECK CONSOLE LOG-------------------');
let perfil = new BombObject();
perfil.reference = '=console.log("LOGGING->" + this.margin.left);';
perfil.margin.left = 50;
perfil.explode();
console.log( 'CORRECT' );
}
TestConstants() {
console.log( '--------------CHECK CONSTANT USAGE-------------------');
let perfil = new BombObject();
perfil.margin.right= '=Constantes.COLOR;';
let exploded = perfil.explode();
console.log( exploded.margin.right === Constantes.COLOR ? 'CORRECT' : 'ERROR' );
}
TestBefore() {
console.log( '--------------CHECK BEFORE FORMULA-------------------');
let perfil = new BombObject();
perfil.margin.left = 50;
perfil.margin.right= '=this.margin.left;';
perfil.before = '=this.margin.left = 25;';
let exploded = perfil.explode();
console.log( exploded.margin.right === 25 ? 'CORRECT' : 'ERROR' );
}
TestAfter() {
console.log( '--------------CHECK AFTER FORMULA-------------------');
let perfil = new BombObject();
perfil.margin.left = 50;
perfil.margin.right= '=this.margin.left;';
perfil.after = '=this.margin.right = 5;';
let exploded = perfil.explode();
console.log( exploded.margin.right === 5 ? 'CORRECT' : 'ERROR' );
}
TestJSON() {
console.log( '--------------CHECK JSON EXPLODE-------------------');
let json = {
ref: 15,
val: {
aa: 5,
bb: '=this.ref;'
}
}
new BombObject()._explodeValue(json, json);
console.log( json.val.bb === json.ref ? 'CORRECT' : 'ERROR' );
}
async TestClassMethod() {
console.log( '--------------CHECK METHOD IMPORT-------------------');
let classStr = `export function Sum(a,b) { return a + b; }`
let classes = new Classes();
let parsed = await classes.loadClass( classStr );
classes.addClassesToWindowContext( parsed );
let perfil = new BombObject();
perfil.margin.left = `=Sum(5,10);`;
let exploded = perfil.explode();
console.log( exploded.margin.left === 15 ? 'CORRECT' : 'ERROR' );
classes.removeClassesFromWindowContext( parsed.keys );
}
async TestClassImport() {
console.log( '--------------CHECK IMPORT WITHIN IMPORT-------------------');
let classStr = `import * as THREE from 'https://cdn.jsdelivr.net/npm/three@0.134.0/build/three.module.js';
export class CustomVector {
constructor() {
this.vector = new THREE.Vector3();
this.vector.set(15, 5, 10);
}
init( ) {
console.log( this.vector );
}
}`
let classes = new Classes();
let parsed = await classes.loadClass( classStr );
classes.addClassesToWindowContext( parsed );
let perfil = new BombObject();
perfil.margin.left = `={
let v = new CustomVector();
v.init();
this.margin.right = v.vector.x;
return 1000;
}`;
let exploded = perfil.explode();
console.log( exploded.margin.left === 1000 && exploded.margin.right === 15 ? 'CORRECT' : 'ERROR' );
classes.removeClassesFromWindowContext( parsed.keys );
}
async TestClassProjectClassImport() {
/*
IMPORTANT!!
in order to export classes there are 2 things to do:
1.- add correspondent library options in the output section of webpack config. This exports the bundled with library name (https://webpack.js.org/configuration/output/#outputlibrary)
library: ['library', '[name]'],
libraryTarget: "umd",
//NOTE: with one entry point we can simply set library: 'library', otherwise we must add as an array and set entry as json object.
Each key will be deployed as library.key
2.- add in main.js (or other entry point in webpack) the desired export classes (GeometryItem in the example)
*/
console.log( '--------------CHECK PROJECT IMPORT WITHIN IMPORT-------------------');
let classStr = `export class Triangle extends library.main.GeometryItem{
constructor() {
super();
this.margin.left = 15;
}
}`;
let classes = new Classes();
let parsed = await classes.loadClass( classStr );
classes.addClassesToWindowContext( parsed );
let perfil = new BombObject();
perfil.margin.left = `={
let instance = new Triangle();
return instance.margin.left;
}`;
let exploded = perfil.explode();
console.log( exploded.margin.left === 15 ? 'CORRECT' : 'ERROR' );
classes.removeClassesFromWindowContext( parsed.keys );
}
}