|
6 | 6 | import { Graphviz } from "@hpcc-js/wasm-graphviz"; |
7 | 7 | import { getFirstFunction, initializeParsers, type Parsers } from "./utils"; |
8 | 8 | import { type TestFuncRecord } from "../../../test/commentTestUtils"; |
| 9 | + import { type TestFunction } from "../../../test/commentTestTypes"; |
| 10 | + import { requirementTests } from "../../../test/commentTestHandlers"; |
9 | 11 |
|
10 | 12 | let parsers: Parsers; |
11 | 13 | let graphviz: Graphviz; |
12 | 14 | let ast: string = ""; |
13 | 15 | let dot: string = ""; |
| 16 | + let visibleTestResults: string = ""; |
| 17 | + export let failed: boolean = false; |
14 | 18 | export let record: TestFuncRecord; |
15 | 19 | export let verbose: boolean = false; |
16 | 20 | export let simplify: boolean = true; |
|
25 | 29 | return {}; |
26 | 30 | } |
27 | 31 |
|
| 32 | + function runTest(record: TestFuncRecord) { |
| 33 | + const tree = parsers[record.language].parse(record.code); |
| 34 | + const testFunc: TestFunction = { |
| 35 | + function: getFirstFunction(tree), |
| 36 | + language: record.language, |
| 37 | + name: record.name, |
| 38 | + reqs: record.reqs, |
| 39 | + }; |
| 40 | + const testResults = []; |
| 41 | + for (const [key, value] of Object.entries(testFunc.reqs)) { |
| 42 | + const reqHandler = requirementTests[key]; |
| 43 | + if (!reqHandler) { |
| 44 | + continue; |
| 45 | + } |
| 46 | + testResults.push({ |
| 47 | + reqName: key, |
| 48 | + reqValue: value, |
| 49 | + failure: reqHandler(testFunc), |
| 50 | + }); |
| 51 | + } |
| 52 | + return testResults; |
| 53 | + } |
| 54 | +
|
28 | 55 | interface RenderOptions { |
29 | 56 | readonly simplify: boolean; |
30 | 57 | readonly verbose: boolean; |
|
56 | 83 | if (trim) cfg = trimFor(cfg); |
57 | 84 | if (simplify) cfg = simplifyCFG(cfg, mergeNodeAttrs); |
58 | 85 |
|
| 86 | + const testResults = runTest(record); |
| 87 | + visibleTestResults = JSON.stringify(testResults); |
| 88 | + failed = !!testResults.filter((result) => result.failure).length; |
| 89 | + console.log(failed); |
59 | 90 | dot = graphToDot(cfg, verbose); |
60 | 91 | ast = formatAST(functionSyntax.toString()); |
61 | 92 |
|
|
71 | 102 | } |
72 | 103 | </script> |
73 | 104 |
|
74 | | -<div class="results"> |
| 105 | +<div class="results" class:failed class:passed={!failed}> |
75 | 106 | {#await initialize() then} |
76 | 107 | <div class="graph"> |
77 | 108 | {@html renderWrapper(record, { simplify, verbose, trim, flatSwitch })} |
78 | 109 | </div> |
79 | 110 | {/await} |
| 111 | + <p> |
| 112 | + {visibleTestResults} |
| 113 | + </p> |
80 | 114 | {#if showAST} |
81 | 115 | <br /> |
82 | 116 | <details> |
|
100 | 134 | justify-content: center; |
101 | 135 | padding: 1em; |
102 | 136 | } |
| 137 | + .failed { |
| 138 | + background-color: #fdd; |
| 139 | + } |
103 | 140 | </style> |
0 commit comments