Skip to content

Commit 3e6fa0e

Browse files
committed
test page done
1 parent 03aa0fd commit 3e6fa0e

File tree

2 files changed

+79
-114
lines changed

2 files changed

+79
-114
lines changed

test/test.htm

Lines changed: 28 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -3,104 +3,70 @@
33
<title>isType tests</title>
44

55
<style>
6-
table {
6+
body {
7+
margin: 0;
8+
padding: 1.25em;
9+
font-family: sans-serif;
10+
}
11+
#tests {
712
border-collapse: collapse;
8-
margin: 1.25em;
13+
margin-right: 0.5em;
914
}
10-
th, td {
15+
#tests th,
16+
#tests td {
1117
border: 1px solid #000;
1218
padding: 0.25em 0.5em;
13-
vertical-align: top;
1419
}
15-
td.fail {
16-
background-color: #FEE;
17-
}
18-
td.fail::after {
19-
content: "(expected " attr(data-expected) ")";
20-
display: block;
21-
color: #888;
22-
}
23-
24-
#types {
25-
font-family: sans-serif;
26-
margin-top: 5em;
20+
#tests thead {
21+
height: 5em;
2722
}
28-
#types th {
23+
#tests th {
2924
position: relative;
3025
padding: 0 0.625em;
3126
border: none;
27+
vertical-align: top;
3228
}
33-
#types th div {
29+
#tests th div {
3430
position: absolute;
3531
transform-origin: top left;
3632
transform: rotate(-60deg);
3733
left: calc(50% - 1em * cos(30deg));
3834
line-height: 1.25;
39-
top: calc(-1em * sin(30deg) - 0.25em);
35+
bottom: -0.5em;
4036
}
41-
#types td {
42-
padding: 0 0.25em 0.25em;
37+
#tests td {
38+
padding: 0.25em;
4339
min-width: 1.375em;
4440
vertical-align: middle;
4541
white-space: nowrap;
4642
text-align: left;
4743
background: #90ee9022;
4844
}
49-
#types td:nth-child(n+3) {
45+
#tests td:nth-child(n+3) {
46+
padding: 0 0.25em 0.25em;
5047
text-align: center;
5148
}
52-
#types td:first-child {
49+
#tests td:first-child {
5350
background: none;
51+
white-space: normal;
52+
min-width: 10em;
5453
}
55-
#types td.match {
54+
#tests td.match {
5655
background: lightgreen;
5756
}
58-
#types td.error {
57+
#tests td.error {
5958
background: lightcoral;
6059
}
60+
#tests tbody tr:hover {
61+
background: lightblue;
62+
}
6163
</style>
6264

6365
<script src="test.js" type="module"></script>
6466
</head>
6567
<body>
6668

67-
<details open><summary>Types</summary>
68-
<table>
69-
<thead>
70-
<tr>
71-
<th>Value</th>
72-
<th>Type</th>
73-
<th>Object</th>
74-
<th>Properties</th>
75-
</tr>
76-
</thead>
77-
<tbody id="type_results"></tbody>
78-
</table>
79-
</details>
80-
81-
<details><summary>Type Tester Methods</summary>
82-
<table>
83-
<thead>
84-
<tr>
85-
<th>Value</th>
86-
<th>Successful Type Tester Methods</th>
87-
</tr>
88-
</thead>
89-
<tbody id="tester_results"></tbody>
90-
</table>
91-
</details>
92-
93-
<details><summary>Additional Methods</summary>
94-
<table>
95-
<thead>
96-
<tr>
97-
<th>Test</th>
98-
<th>Result</th>
99-
</tr>
100-
</thead>
101-
<tbody id="additional_results"></tbody>
102-
</table>
103-
</details>
69+
<table id="tests"></table>
10470

10571
</body>
10672
</html>

test/test.js

Lines changed: 51 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,59 @@ let testResults = [];
44

55
{
66
_is(()=>(void 0), is.undefined, is.primitive, is.nullish, is.falsy);
7+
_is(()=>(null), is.null, is.defined, is.primitive, is.nullish, is.objectish, is.falsy);
8+
_is(()=>(false), is.boolean, is.defined, is.primitive, is.false, is.falsy);
9+
_is(()=>(true), is.boolean, is.defined, is.primitive, is.true, is.truthy);
10+
_is(()=>(new Boolean(false)), is.object, is.defined, is.objectish, is.truthy);
11+
_is(()=>(0n), is.bigint, is.defined, is.primitive, is.falsy);
12+
_is(()=>(5n), is.bigint, is.defined, is.primitive, is.truthy);
13+
_is(()=>(0), is.number, is.defined, is.primitive, is.falsy, is.real, is.numberish);
14+
_is(()=>(5), is.number, is.defined, is.primitive, is.truthy, is.real, is.numberish);
15+
_is(()=>(new Number(0)), is.number, is.defined, is.object, is.objectish, is.truthy, is.real, is.numberish);
16+
_is(()=>(new Number(5)), is.number, is.defined, is.object, is.objectish, is.truthy, is.real, is.numberish);
17+
_is(()=>(Infinity), is.number, is.defined, is.primitive, is.truthy, is.infinite, is.numberish);
18+
_is(()=>(-1/0), is.number, is.defined, is.primitive, is.truthy, is.infinite, is.numberish);
719
_is(()=>(new Number(Infinity)), is.number, is.defined, is.object, is.objectish, is.truthy, is.infinite, is.numberish);
20+
_is(()=>(NaN), is.nan, is.defined, is.primitive, is.falsy, is.numberish);
21+
_is(()=>(+"a"), is.nan, is.defined, is.primitive, is.falsy, is.numberish);
22+
_is(()=>(new Number(NaN)), is.nan, is.defined, is.object, is.objectish, is.truthy, is.numberish);
23+
_is(()=>(new Number("a")), is.nan, is.defined, is.object, is.objectish, is.truthy, is.numberish);
24+
_is(()=>(""), is.string, is.defined, is.primitive, is.falsy, is.empty);
25+
_is(()=>("a"), is.string, is.defined, is.primitive, is.truthy, is.nonempty);
26+
_is(()=>(new String("")), is.string, is.defined, is.object, is.objectish, is.truthy, is.empty);
27+
_is(()=>(new String("a")), is.string, is.defined, is.object, is.objectish, is.truthy, is.nonempty);
28+
_is(()=>(Symbol()), is.symbol, is.defined, is.primitive, is.truthy);
829
_is(()=>([]), is.array, is.defined, is.object, is.objectish, is.truthy, is.empty);
30+
_is(()=>([1,2]), is.array, is.defined, is.object, is.objectish, is.truthy, is.nonempty);
31+
_is(()=>(new Array()), is.array, is.defined, is.object, is.objectish, is.truthy, is.empty);
32+
_is(()=>(new Array(1,2)), is.array, is.defined, is.object, is.objectish, is.truthy, is.nonempty);
33+
_is(()=>(new Map()), is.map, is.defined, is.object, is.objectish, is.truthy, is.empty);
34+
_is(()=>((new Map()).set("a",1)), is.map, is.defined, is.object, is.objectish, is.truthy, is.nonempty);
35+
_is(()=>(new Set()), is.set, is.defined, is.object, is.objectish, is.truthy, is.empty);
36+
_is(()=>(new Set([1,2])), is.set, is.defined, is.object, is.objectish, is.truthy, is.nonempty);
37+
_is(()=>(new WeakMap()), is.weakmap, is.defined, is.object, is.objectish, is.truthy);
38+
_is(()=>(new WeakSet()), is.weakset, is.defined, is.object, is.objectish, is.truthy);
39+
_is(()=>(new Date()), is.date, is.defined, is.object, is.objectish, is.truthy);
40+
_is(()=>(new Error()), is.error, is.defined, is.object, is.objectish, is.truthy);
41+
_is(()=>(new TypeError()), is.error, is.defined, is.object, is.objectish, is.truthy);
42+
_is(()=>(()=>{}), is.function, is.defined, is.object, is.objectish, is.truthy);
43+
_is(()=>(new Function("")), is.function, is.defined, is.object, is.objectish, is.truthy);
44+
_is(()=>(Object), is.function, is.defined, is.object, is.objectish, is.truthy);
45+
_is(()=>(new Promise(()=>{})), is.promise, is.defined, is.object, is.objectish, is.truthy);
46+
_is(()=>(/a/), is.regex, is.defined, is.object, is.objectish, is.truthy);
47+
_is(()=>(new RegExp("a")), is.regex, is.defined, is.object, is.objectish, is.truthy);
48+
_is(()=>({}), is.object, is.defined, is.object, is.objectish, is.truthy);
49+
_is(()=>(new Object()), is.object, is.defined, is.objectish, is.truthy);
50+
class A{}
51+
_is(()=>(/*class A{}*/ new A()), is.object, is.defined, is.objectish, is.truthy);
52+
class B extends String{}
53+
_is(()=>(/*class B extends String{}*/ new B()), is.string, is.defined, is.object, is.objectish, is.truthy, is.empty);
54+
class C { get [Symbol.toStringTag](){ return "D"; } }
55+
_is(()=>(/*class C {get [Symbol.toStringTag](){return "D"}}*/ new C()), is.object, is.defined, is.objectish, is.truthy);
56+
957
}
1058

11-
document.addEventListener("DOMContentLoaded", ()=>{document.body.innerHTML += createTable()});
59+
document.addEventListener("DOMContentLoaded", ()=>{document.querySelector("#tests").innerHTML = createTableContent()});
1260

1361
/**
1462
* Perform a test and add the result details to the `testResults` array.
@@ -50,7 +98,7 @@ function _is(fn, type, ...trues){
5098
/**
5199
* Create a table to show the results.
52100
*/
53-
function createTable(){
101+
function createTableContent(){
54102

55103
let rows = "";
56104
for(const result of testResults){
@@ -62,7 +110,7 @@ function createTable(){
62110
header += `<th><div>${propName}</div></th>`;
63111
}
64112

65-
return `<table id="types"><thead><tr>${header}</tr></thead><tbody>${rows}</tbody></table>`;
113+
return `<thead><tr>${header}</tr></thead><tbody>${rows}</tbody>`;
66114
}
67115

68116
/**
@@ -99,52 +147,3 @@ function createCell(expected, actual){
99147
if(expected === actual) return `<td class="match">✔️</td>`;
100148
return `<td class="error" title="expected ${expected}">${actual ? "✔️" : ""}</td>`;
101149
}
102-
103-
/*{
104-
_is([], "[]", "array", true);
105-
_is(new Array(), "new Array()", "array", true);
106-
_is([1,2], "[1,2]", "array", true);
107-
_is(new Array(1,2), "new Array(1,2)", "array", true);
108-
_is(5n, "5n", "bigint", false);
109-
_is(true, "true", "boolean", false);
110-
_is(false, "false", "boolean", false);
111-
_is(new Boolean(), "new Boolean()", "object", true);
112-
_is(new Date(), "new Date()", "date", true);
113-
_is(new Error(), "new Error()", "error", true);
114-
_is(new TypeError(), "new TypeError()", "error", true);
115-
_is(()=>{}, "()=>{}", "function", true);
116-
_is(Object, "Object", "function", true);
117-
_is(new Map(), "new Map()", "map", true);
118-
_is(NaN, "NaN", "nan", false);
119-
_is(new Number(NaN), "new Number(NaN)", "nan", true);
120-
_is(new Number('a'), "new Number('a')", "nan", true);
121-
_is(null, "null", "null", false);
122-
_is(5, "5", "number", false);
123-
_is(Infinity, "Infinity", "number", false);
124-
_is(new Number(), "new Number()", "number", true);
125-
_is({}, "{}", "object", true);
126-
_is(new Object(), "new Object()", "object", true);
127-
_is(new Promise(()=>{}), "new Promise(()=>{})", "promise", true);
128-
_is(/a/, "/a/", "regex", true);
129-
_is(new RegExp(), "new RegExp()", "regex", true);
130-
_is(new Set(), "new Set()", "set", true);
131-
_is("", '""', "string", false);
132-
_is("a", '"a"', "string", false);
133-
_is(new String(), "new String()", "string", true);
134-
_is(Symbol(), "Symbol()", "symbol", false);
135-
_is(void 0, "void 0", "undefined", false);
136-
_is(new WeakMap(), "new WeakMap()", "weakmap", true);
137-
_is(new WeakSet(), "new WeakSet()", "weakset", true);
138-
{
139-
class Foo {}
140-
_is(new Foo(), "<i>class Foo {}</i><br>new Foo()", "object", true);
141-
}
142-
{
143-
class Foo extends String {}
144-
_is(new Foo(), "<i>class Foo extends String {}</i><br>new Foo()", "string", true);
145-
}
146-
{
147-
class Foo { get [Symbol.toStringTag](){ return "Bar"; } }
148-
_is(new Foo(), "<i>class Foo { get [Symbol.toStringTag](){ return \"Bar\"; } }</i><br>new Foo()", "object", true);
149-
}
150-
}*/

0 commit comments

Comments
 (0)