test(wpcarro/slx): Add (basic) tests
Tests with React? ...wat? Change-Id: I95ccd08bb6e66e9d74a63a596b5f844f9dab0361 Reviewed-on: https://cl.tvl.fyi/c/depot/+/7884 Reviewed-by: wpcarro <wpcarro@gmail.com> Autosubmit: wpcarro <wpcarro@gmail.com> Tested-by: BuildkiteCI
This commit is contained in:
parent
6945601ef3
commit
7f37cfb184
5 changed files with 1589 additions and 0 deletions
3
users/wpcarro/slx.js/.gitignore
vendored
Normal file
3
users/wpcarro/slx.js/.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
/.parcel-cache
|
||||||
|
/dist
|
||||||
|
/node_modules
|
13
users/wpcarro/slx.js/index.html
Normal file
13
users/wpcarro/slx.js/index.html
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<title>Tests</title>
|
||||||
|
<link rel="stylesheet" href="https://unpkg.com/terminal.css@0.7.2/dist/terminal.min.css" />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="mount"></div>
|
||||||
|
<script src="./index.js"></script>
|
||||||
|
<script src="./tests.js" type="module"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
14
users/wpcarro/slx.js/package.json
Normal file
14
users/wpcarro/slx.js/package.json
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
{
|
||||||
|
"name": "slx.js",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"main": "index.js",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"parcel": "^2.8.3",
|
||||||
|
"react": "^18.2.0",
|
||||||
|
"react-dom": "^18.2.0"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"process": "^0.11.10"
|
||||||
|
}
|
||||||
|
}
|
64
users/wpcarro/slx.js/tests.js
Normal file
64
users/wpcarro/slx.js/tests.js
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
import { createRoot } from "react-dom/client";
|
||||||
|
import React from "react";
|
||||||
|
|
||||||
|
|
||||||
|
const john = { first: 'John', last: 'Cleese', age: 83, birthday: new Date("10/27/1939") };
|
||||||
|
const graham = { first: 'Graham', last: 'Chapman', age: 48, birthday: new Date("01/08/1941") };
|
||||||
|
|
||||||
|
const xs = [
|
||||||
|
john,
|
||||||
|
graham,
|
||||||
|
];
|
||||||
|
const cfg = {
|
||||||
|
caseSensitive: false,
|
||||||
|
preferRegex: true,
|
||||||
|
dateKey: 'birthday',
|
||||||
|
};
|
||||||
|
const tests = [
|
||||||
|
['support numeric comparisons', 'age=83', xs, cfg, [john]],
|
||||||
|
['supports grouping (1)', 'last:/^C/ (age=83 OR age=48)', xs, cfg, [john, graham]],
|
||||||
|
['supports grouping (2)', '(age=83)', xs, cfg, [john]],
|
||||||
|
['supports grouping (3)', '(age=83 OR age=48)', xs, cfg, [john, graham]],
|
||||||
|
];
|
||||||
|
|
||||||
|
function equal(xs, ys) {
|
||||||
|
return xs.length === ys.length && xs.every((x, i) => x === ys[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
class App extends React.Component {
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
}
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<th>pass/fail</th>
|
||||||
|
<th>Label</th>
|
||||||
|
<th>code</th>
|
||||||
|
<th>actual</th>
|
||||||
|
<th>expected</th>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{this.props.tests.map(test => {
|
||||||
|
const [label, query, xs, cfg, expected] = test;
|
||||||
|
const actual = select(query, xs, cfg);
|
||||||
|
return (
|
||||||
|
<tr>
|
||||||
|
<td>{equal(actual, expected) ? "pass" : "fail"}</td>
|
||||||
|
<td>{label}</td>
|
||||||
|
<td>select("{query}", {JSON.stringify(xs)}, {JSON.stringify(cfg)})</td>
|
||||||
|
<td>{JSON.stringify(actual)}</td>
|
||||||
|
<td>{JSON.stringify(expected)}</td>
|
||||||
|
</tr>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const container = document.getElementById("mount");
|
||||||
|
const root = createRoot(container);
|
||||||
|
root.render(<App tests={tests} />);
|
1495
users/wpcarro/slx.js/yarn.lock
Normal file
1495
users/wpcarro/slx.js/yarn.lock
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue