diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /dom/webgpu/tests/cts/checkout/src/unittests/preprocessor.spec.ts | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/webgpu/tests/cts/checkout/src/unittests/preprocessor.spec.ts')
-rw-r--r-- | dom/webgpu/tests/cts/checkout/src/unittests/preprocessor.spec.ts | 207 |
1 files changed, 207 insertions, 0 deletions
diff --git a/dom/webgpu/tests/cts/checkout/src/unittests/preprocessor.spec.ts b/dom/webgpu/tests/cts/checkout/src/unittests/preprocessor.spec.ts new file mode 100644 index 0000000000..040629355d --- /dev/null +++ b/dom/webgpu/tests/cts/checkout/src/unittests/preprocessor.spec.ts @@ -0,0 +1,207 @@ +export const description = ` +Test for "pp" preprocessor. +`; + +import { makeTestGroup } from '../common/framework/test_group.js'; +import { pp } from '../common/util/preprocessor.js'; + +import { UnitTest } from './unit_test.js'; + +class F extends UnitTest { + test(act: string, exp: string): void { + this.expect(act === exp, 'got: ' + act.replace('\n', '⏎')); + } +} + +export const g = makeTestGroup(F); + +g.test('empty').fn(t => { + t.test(pp``, ''); + t.test(pp`\n`, '\n'); + t.test(pp`\n\n`, '\n\n'); +}); + +g.test('plain').fn(t => { + t.test(pp`a`, 'a'); + t.test(pp`\na`, '\na'); + t.test(pp`\n\na`, '\n\na'); + t.test(pp`\na\n`, '\na\n'); + t.test(pp`a\n\n`, 'a\n\n'); +}); + +g.test('substitutions,1').fn(t => { + const act = pp`a ${3} b`; + const exp = 'a 3 b'; + t.test(act, exp); +}); + +g.test('substitutions,2').fn(t => { + const act = pp`a ${'x'}`; + const exp = 'a x'; + t.test(act, exp); +}); + +g.test('substitutions,3').fn(t => { + const act = pp`a ${'x'} b`; + const exp = 'a x b'; + t.test(act, exp); +}); + +g.test('substitutions,4').fn(t => { + const act = pp` +a +${pp._if(false)} +${'x'} +${pp._endif} +b`; + const exp = '\na\n\nb'; + t.test(act, exp); +}); + +g.test('if,true').fn(t => { + const act = pp` +a +${pp._if(true)}c${pp._endif} +d +`; + const exp = '\na\nc\nd\n'; + t.test(act, exp); +}); + +g.test('if,false').fn(t => { + const act = pp` +a +${pp._if(false)}c${pp._endif} +d +`; + const exp = '\na\n\nd\n'; + t.test(act, exp); +}); + +g.test('else,1').fn(t => { + const act = pp` +a +${pp._if(true)} +b +${pp._else} +c +${pp._endif} +d +`; + const exp = '\na\n\nb\n\nd\n'; + t.test(act, exp); +}); + +g.test('else,2').fn(t => { + const act = pp` +a +${pp._if(false)} +b +${pp._else} +c +${pp._endif} +d +`; + const exp = '\na\n\nc\n\nd\n'; + t.test(act, exp); +}); + +g.test('elif,1').fn(t => { + const act = pp` +a +${pp._if(false)} +b +${pp._elif(true)} +e +${pp._else} +c +${pp._endif} +d +`; + const exp = '\na\n\ne\n\nd\n'; + t.test(act, exp); +}); + +g.test('elif,2').fn(t => { + const act = pp` +a +${pp._if(true)} +b +${pp._elif(true)} +e +${pp._else} +c +${pp._endif} +d +`; + const exp = '\na\n\nb\n\nd\n'; + t.test(act, exp); +}); + +g.test('nested,1').fn(t => { + const act = pp` +a +${pp._if(false)} +b +${pp.__if(true)} +e +${pp.__endif} +c +${pp._endif} +d +`; + const exp = '\na\n\nd\n'; + t.test(act, exp); +}); + +g.test('nested,2').fn(t => { + const act = pp` +a +${pp._if(false)} +b +${pp._else} +h +${pp.__if(false)} +e +${pp.__elif(true)} +f +${pp.__else} +g +${pp.__endif} +c +${pp._endif} +d +`; + const exp = '\na\n\nh\n\nf\n\nc\n\nd\n'; + t.test(act, exp); +}); + +g.test('errors,pass').fn(() => { + pp`${pp._if(true)}${pp._endif}`; + pp`${pp._if(true)}${pp._else}${pp._endif}`; + pp`${pp._if(true)}${pp.__if(true)}${pp.__endif}${pp._endif}`; +}); + +g.test('errors,fail').fn(t => { + const e = (fn: () => void) => t.shouldThrow('Error', fn); + e(() => pp`${pp._if(true)}`); + e(() => pp`${pp._elif(true)}`); + e(() => pp`${pp._else}`); + e(() => pp`${pp._endif}`); + e(() => pp`${pp.__if(true)}`); + e(() => pp`${pp.__elif(true)}`); + e(() => pp`${pp.__else}`); + e(() => pp`${pp.__endif}`); + + e(() => pp`${pp._if(true)}${pp._elif(true)}`); + e(() => pp`${pp._if(true)}${pp._elif(true)}${pp._else}`); + e(() => pp`${pp._if(true)}${pp._else}`); + e(() => pp`${pp._else}${pp._endif}`); + + e(() => pp`${pp._if(true)}${pp.__endif}`); + e(() => pp`${pp.__if(true)}${pp.__endif}`); + e(() => pp`${pp.__if(true)}${pp._endif}`); + + e(() => pp`${pp._if(true)}${pp._else}${pp._else}${pp._endif}`); + e(() => pp`${pp._if(true)}${pp.__if(true)}${pp.__else}${pp.__else}${pp.__endif}${pp._endif}`); +}); |