Skip to content

Commit 8c6a843

Browse files
Xiaoji Chendy
authored andcommitted
clean up tests
1 parent 0d4351a commit 8c6a843

File tree

1 file changed

+81
-31
lines changed

1 file changed

+81
-31
lines changed

test/index.js

Lines changed: 81 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -330,11 +330,15 @@ test('Episodes', function () {
330330

331331
test('Argument qualifiers', function() {
332332

333-
// clone inputs
334-
test('void f(float a, vec3 b, mat4 c) { b.x = 1.0; }', function () {
333+
test('Clone inputs', function () {
335334
var compile = GLSL();
336335

337-
assert.equal(clean(compile(this.title)), clean(`
336+
var source = `
337+
void f(float a, vec3 b, mat4 c) {
338+
b.x = 1.0;
339+
}`;
340+
341+
assert.equal(clean(compile(source)), clean(`
338342
function f (a, b, c) {
339343
b = b.slice();
340344
c = c.slice();
@@ -343,23 +347,35 @@ test('Argument qualifiers', function() {
343347
`))
344348
});
345349

346-
// output w/o return statement
347-
test('void f(float a, out float b) { b = 1.0; }', function () {
350+
test('Output without return statements', function () {
348351
var compile = GLSL();
349352

350-
assert.equal(clean(compile(this.title)), clean(`
353+
var source = `
354+
void f(float a, out float b) {
355+
b = 1.0;
356+
}`;
357+
358+
assert.equal(clean(compile(source)), clean(`
351359
function f (a, b) {
352360
b = 1.0;
353361
f.__out__ = [b];
354362
};
355363
`))
356364
});
357365

358-
// output w/ return statement
359-
test('void f(float a, out float b) { if (a < 0.0) { b = -1.0; return; } b = 1.0; }', function () {
366+
test('Output with return statements', function () {
360367
var compile = GLSL();
361368

362-
assert.equal(clean(compile(this.title)), clean(`
369+
var source = `
370+
void f(float a, out float b) {
371+
if (a < 0.0) {
372+
b = -1.0;
373+
return;
374+
}
375+
b = 1.0;
376+
}`;
377+
378+
assert.equal(clean(compile(source)), clean(`
363379
function f (a, b) {
364380
if (a < 0.0) {
365381
b = -1.0;
@@ -372,11 +388,18 @@ test('Argument qualifiers', function() {
372388
`))
373389
});
374390

375-
// multiple outputs
376-
test('float f(out float a, out vec2 b, inout vec2 c) { a = 0.1; b = vec2(2.0); c = b; return 0.0; }', function () {
391+
test('Multiple outputs', function () {
377392
var compile = GLSL();
378393

379-
assert.equal(clean(compile(this.title)), clean(`
394+
var source = `
395+
float f(out float a, out vec2 b, inout vec2 c) {
396+
a = 0.1;
397+
b = vec2(2.0);
398+
c = b;
399+
return 0.0;
400+
}`;
401+
402+
assert.equal(clean(compile(source)), clean(`
380403
function f (a, b, c) {
381404
c = c.slice();
382405
a = 0.1;
@@ -389,33 +412,59 @@ test('Argument qualifiers', function() {
389412
`))
390413
});
391414

392-
// calling
393-
test(`float f(float a, out float b, out float c) { b = 1.0; c = 2.0; return a + 1.0; }
394-
void main() { float x = 0.1; float y; float z; x = f(x, y, z); }`, function () {
415+
test('Calling function with output arguments', function () {
395416
var compile = GLSL();
396-
assert.equal(clean(compile(this.title)), clean(`
417+
418+
var source = `
419+
float f(float a, out float b, out float c) {
420+
b = 1.0;
421+
c = 2.0;
422+
return a + 1.0;
423+
}
424+
float x = 0.1;
425+
float y;
426+
float z;
427+
x = f(x, y, z);
428+
gl_Position = vec4(x, y, z, 1.0);
429+
`;
430+
431+
assert.equal(clean(compile(source)), clean(`
397432
function f (a, b, c) {
398433
b = 1.0;
399434
c = 2.0;
400435
f.__return__ = a + 1.0;
401436
f.__out__ = [b, c];
402437
return f.__return__;
403438
};
404-
function main () {
405-
var x = 0.1;
406-
var y = 0;
407-
var z = 0;
408-
x = (f(x, y, z), [y, z] = f.__out__, f.__return__);
409-
};
439+
var x = 0.1;
440+
var y = 0;
441+
var z = 0;
442+
x = (f(x, y, z), [y, z] = f.__out__, f.__return__);
443+
gl_Position = [x, y, z, 1];
410444
`))
445+
446+
assert.deepEqual(eval(source, {debug: false}), [1.1, 1, 2, 1]);
411447
});
412448

413449
// recursive calling
414-
test(`float f1(float a, out float b) { b = 1.0; return a + 1.0; }
415-
float f2(float a, out float b) { return f1(a, b) + 1.0; }
416-
void main() { float x = 0.1; float y; x = f2(x, y); }`, function () {
450+
test('Calling nested functions with output arguments', function () {
417451
var compile = GLSL();
418-
assert.equal(clean(compile(this.title)), clean(`
452+
453+
var source = `
454+
float f1(float a, out float b) {
455+
b = 1.0;
456+
return a + 1.0;
457+
}
458+
float f2(float a, out float b) {
459+
return f1(a, b) + 1.0;
460+
}
461+
float x = 0.1;
462+
float y;
463+
x = f2(x, y);
464+
gl_Position = vec4(x, y, 0.0, 1.0);
465+
`;
466+
467+
assert.equal(clean(compile(source)), clean(`
419468
function f1 (a, b) {
420469
b = 1.0;
421470
f1.__return__ = a + 1.0;
@@ -427,12 +476,13 @@ test('Argument qualifiers', function() {
427476
f2.__out__ = [b];
428477
return f2.__return__;
429478
};
430-
function main () {
431-
var x = 0.1;
432-
var y = 0;
433-
x = (f2(x, y), [y] = f2.__out__, f2.__return__);
434-
};
479+
var x = 0.1;
480+
var y = 0;
481+
x = (f2(x, y), [y] = f2.__out__, f2.__return__);
482+
gl_Position = [x, y, 0, 1];
435483
`))
484+
485+
assert.deepEqual(eval(source, {debug: false}), [2.1, 1, 0, 1]);
436486
});
437487
})
438488

0 commit comments

Comments
 (0)