gpu.js/test/issues/263-to-string.js
Robert Plummer 27f4efb8d9 fix: Proper kernel.toString() unit tests (good grief, so many!) for CPU and GPU
feat: `switch` statements
feat: `kernel.toString()` has as well `.getPixels()`
fix: Proper fallback when arguments or constants are not supported
fix: Removal of infamous `|| 'Number'` for argument types and return types
fix: detect circlical logic in `FunctionBuilder.lookupReturnType()` and tests
fix: Allow subKernels to get their type detected as well
fix: `FunctionNode`'s `typeLookupMap` didn't have 'Float' or 'Integer'
feat: Turn off context checking in kernel, via `{ checkContext: false }`, used for `kernel.toString()`
fix: `GPU.upgradeDeprecatedCreateKernelSettings` to have a default return value
fix: Typings
fix: `kernelRunShortcut()` to better switch kernel when replacing
feat: It order to flatten methods, for `kernel.toString()` `utils.flattenFunctionToString()` and light unit testing of it
fix: Added sinon for testing
fix: Bump gl-wiretap
2019-06-03 19:32:21 -04:00

40 lines
1.2 KiB
JavaScript

const { assert, skip, test, module: describe } = require('qunit');
const { GPU } = require('../../src');
describe('issue #263');
function toString(mode, context, canvas) {
const gpu = new GPU({ mode, context, canvas });
const kernel = gpu.createKernel(function() {
return 1;
}, {
output: [1]
});
kernel.build();
const string = kernel.toString();
const kernel2 = new Function('return ' + string)()({ context, canvas });
const result = kernel2();
assert.equal(result[0], 1);
gpu.destroy();
}
(GPU.isWebGLSupported ? test : skip)('Issue #263 toString single function - webgl', () => {
const canvas = document.createElement('canvas');
const context = canvas.getContext('webgl');
toString('webgl', context, canvas);
});
(GPU.isWebGL2Supported ? test : skip)('Issue #263 toString single function - webgl2', () => {
const canvas = document.createElement('canvas');
const context = canvas.getContext('webgl2');
toString('webgl2', context, canvas);
});
(GPU.isHeadlessGLSupported ? test : skip)('Issue #263 toString single function - headlessgl', () => {
toString('headlessgl', require('gl')(1, 1), null);
});
test('Issue #263 toString single function - cpu', () => {
toString('cpu');
});