Skip to content

Commit 03aa0fd

Browse files
committed
WIP on fewer-keystrokes
1 parent 7aef403 commit 03aa0fd

File tree

3 files changed

+35
-9
lines changed

3 files changed

+35
-9
lines changed

isType.mjs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class TypeTest {
9696
this.nonempty = !this.empty;
9797
}
9898
else{
99-
this.empty = this.nonempty = void 0;
99+
this.empty = this.nonempty = false;
100100
}
101101
}
102102

test/test.htm

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,42 @@
2121
color: #888;
2222
}
2323

24+
#types {
25+
font-family: sans-serif;
26+
margin-top: 5em;
27+
}
2428
#types th {
2529
position: relative;
26-
padding: 0 1.25em;
30+
padding: 0 0.625em;
2731
border: none;
2832
}
2933
#types th div {
3034
position: absolute;
3135
transform-origin: top left;
3236
transform: rotate(-60deg);
33-
left: calc(50% - 1.25em* cos(30deg));
37+
left: calc(50% - 1em * cos(30deg));
3438
line-height: 1.25;
35-
top: calc(-1em* sin(30deg));
39+
top: calc(-1em * sin(30deg) - 0.25em);
40+
}
41+
#types td {
42+
padding: 0 0.25em 0.25em;
43+
min-width: 1.375em;
44+
vertical-align: middle;
45+
white-space: nowrap;
46+
text-align: left;
47+
background: #90ee9022;
48+
}
49+
#types td:nth-child(n+3) {
50+
text-align: center;
51+
}
52+
#types td:first-child {
53+
background: none;
54+
}
55+
#types td.match {
56+
background: lightgreen;
57+
}
58+
#types td.error {
59+
background: lightcoral;
3660
}
3761
</style>
3862

test/test.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ let testResults = [];
55
{
66
_is(()=>(void 0), is.undefined, is.primitive, is.nullish, is.falsy);
77
_is(()=>(new Number(Infinity)), is.number, is.defined, is.object, is.objectish, is.truthy, is.infinite, is.numberish);
8+
_is(()=>([]), is.array, is.defined, is.object, is.objectish, is.truthy, is.empty);
89
}
910

1011
document.addEventListener("DOMContentLoaded", ()=>{document.body.innerHTML += createTable()});
1112

1213
/**
1314
* Perform a test and add the result details to the `testResults` array.
1415
*
15-
* @param {function} fn - An arrow function returning the value to be tested. The function body is saved as a string for later use.
16+
* @param {function} fn - An arrow function, in the form of `()=>(...)`, returning the value to be tested. The function body is saved as a string for later use.
1617
* @param {string} type - The expected type of the test value.
1718
* @param {...string} [trues] - Names of all additional properties of the test result that are expected to evaluate as `true`.
1819
*/
@@ -71,12 +72,12 @@ function createTable(){
7172
*/
7273
function createRow(result){
7374

74-
let typeMatch = result.type.expected !== result.type.actual;
75+
let typeMatch = result.type.expected === result.type.actual;
7576

7677
let code = result.code.replace("&","&amp;").replace("<","&lt;").replace(">","&gt;").replace("\"","&quot;");
7778

78-
let cells = `<td>${code}</td><td ${!typeMatch ? 'class="error"' : ""}>${result.type.actual}`;
79-
if(typeMatch) cells += ` (expected ${result.type.expected})`;
79+
let cells = `<td><code>${code}</code></td><td class="${typeMatch ? "match" : "error"}">${result.type.actual}`;
80+
if(!typeMatch) cells += `<br>(expected ${result.type.expected})`;
8081
cells += `</td>`;
8182

8283
for(const prop in result.properties){
@@ -95,7 +96,8 @@ function createRow(result){
9596
function createCell(expected, actual){
9697

9798
if(!(expected || actual)) return `<td></td>`;
98-
return `<td class="${expected === actual ? "match" : "error"}">${expected ? "✔️" : "✖️"}</td>`;
99+
if(expected === actual) return `<td class="match">✔️</td>`;
100+
return `<td class="error" title="expected ${expected}">${actual ? "✔️" : ""}</td>`;
99101
}
100102

101103
/*{

0 commit comments

Comments
 (0)