params_builder_toplevel.spec.ts (2548B)
1 export const description = ` 2 Unit tests for parameterization. 3 `; 4 5 import { TestParams } from '../common/framework/fixture.js'; 6 import { kUnitCaseParamsBuilder } from '../common/framework/params_builder.js'; 7 import { makeTestGroup } from '../common/framework/test_group.js'; 8 import { makeTestGroupForUnitTesting } from '../common/internal/test_group.js'; 9 10 import { TestGroupTest } from './test_group_test.js'; 11 import { UnitTest } from './unit_test.js'; 12 13 export const g = makeTestGroup(TestGroupTest); 14 15 g.test('combine_none,arg_unit') 16 .params(u => u.combineWithParams([])) 17 .fn(t => { 18 t.fail("this test shouldn't run"); 19 }); 20 21 g.test('combine_none,arg_ignored') 22 .params(() => kUnitCaseParamsBuilder.combineWithParams([])) 23 .fn(t => { 24 t.fail("this test shouldn't run"); 25 }); 26 27 g.test('combine_none,plain_builder') 28 .params(kUnitCaseParamsBuilder.combineWithParams([])) 29 .fn(t => { 30 t.fail("this test shouldn't run"); 31 }); 32 33 g.test('combine_none,plain_array') 34 .paramsSimple([]) 35 .fn(t => { 36 t.fail("this test shouldn't run"); 37 }); 38 39 g.test('combine_one,case') 40 .params(u => 41 u // 42 .combineWithParams([{ x: 1 }]) 43 ) 44 .fn(t => { 45 t.expect(t.params.x === 1); 46 }); 47 48 g.test('combine_one,subcase') 49 .paramsSubcasesOnly(u => 50 u // 51 .combineWithParams([{ x: 1 }]) 52 ) 53 .fn(t => { 54 t.expect(t.params.x === 1); 55 }); 56 57 g.test('filter') 58 .params(u => 59 u 60 .combineWithParams([ 61 { a: true, x: 1 }, // 62 { a: false, y: 2 }, 63 ]) 64 .filter(p => p.a) 65 ) 66 .fn(t => { 67 t.expect(t.params.a); 68 }); 69 70 g.test('unless') 71 .params(u => 72 u 73 .combineWithParams([ 74 { a: true, x: 1 }, // 75 { a: false, y: 2 }, 76 ]) 77 .unless(p => p.a) 78 ) 79 .fn(t => { 80 t.expect(!t.params.a); 81 }); 82 83 g.test('generator').fn(t0 => { 84 const g = makeTestGroupForUnitTesting(UnitTest); 85 86 const ran: TestParams[] = []; 87 88 g.test('generator') 89 .params(u => 90 u.combineWithParams({ 91 *[Symbol.iterator]() { 92 for (let x = 0; x < 3; ++x) { 93 for (let y = 0; y < 2; ++y) { 94 yield { x, y }; 95 } 96 } 97 }, 98 }) 99 ) 100 .fn(t => { 101 ran.push(t.params); 102 }); 103 104 t0.expectCases(g, [ 105 { test: ['generator'], params: { x: 0, y: 0 } }, 106 { test: ['generator'], params: { x: 0, y: 1 } }, 107 { test: ['generator'], params: { x: 1, y: 0 } }, 108 { test: ['generator'], params: { x: 1, y: 1 } }, 109 { test: ['generator'], params: { x: 2, y: 0 } }, 110 { test: ['generator'], params: { x: 2, y: 1 } }, 111 ]); 112 });