-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
98 lines (92 loc) · 3.03 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
function test(func) {
const tests = [{
name: "i test",
status: /i=/.test(func) === false,
error: "Function should not use i as a counter or variable"
},
{
name: "white space test",
status: /\s+(?=(?:[^\'"]*[\'"][^\'"]*[\'"])*[^\'"]*$)/.test(func) === false,
error: "Function should not include white spaces outside of quotations"
},
{
name: "; test",
status: /;/.test(func) === false,
error: "Function should not include ;"
},
{
name: "newline test",
status: /\n|\r/.test(func) === false,
error: "Function should not include newlines"
},
{
name: "es6 function test",
status: /=>/.test(func) === true,
error: "Function should be ES6 arrow function"
},
{
name: "concise function test",
status: /=>{/.test(func) === false,
error: "Function must be conscise use () instead of {}"
},
{
name: "why are you using 1 or 0",
status: /[^a-zA-Z](1|0)+(?=(?:[^\'"]*[\'"][^\'"]*[\'"])*[^\'"]*$)/.test(func) === false,
error: "Function should not include 1 or 0 use [] instead"
},
{
name: "+1||-1",
status: /(\+|\-)1/.test(func) === false,
error: "Function should not use + or - 1 to increment or decrement, use -~n or ~-n"
},
{
name: "===||== test",
status: /={2,3}/.test(func) === false,
error: "Function should not use === or == for comparisions"
},
{
name: "true||false",
status: /(true|false)+(?=(?:[^\'"]*[\'"][^\'"]*[\'"])*[^\'"]*$)/.test(func) === false,
error: "Function should not use true or false keywords use implicit or explicit conversion instead"
},
{
name: ".length test",
status: /\.length/.test(func) === false,
error: "Function should not use .length to determine length of Arrays or Strings"
},
{
name: "declarations test",
status: /(const|let|var)+(?=(?:[^\'"]*[\'"][^\'"]*[\'"])*[^\'"]*$)/.test(func) === false,
error: "wait, how are you declaring var|const|let in a concise function"
},
{
name: "empty quotes",
status: /(""|'')/.test(func) === false,
error: "Function should not use empty quotations use [] or another alternative instead"
},
{
name: ">= or <=",
status: /(>=|<=)/.test(func) === false,
error: "Function should not use <= or >=, find something else to use"
},
{
name: "Eval test",
status: /eval+(?=(?:[^\'"]*[\'"][^\'"]*[\'"])*[^\'"]*$)/.test(func) === false,
error: "Function should not use eval, you cheater!"
},
];
let failed = 0;
console.log("Running IJS Tests...");
tests.forEach((item, index) => {
if (!item.status) failed++;
console.assert(item.status, item.error);
})
if (failed > 0) {
console.log(`%c${failed}/${tests.length} tests failed`, "color: red");
} else {
console.log("%cAll test passed", "color: green");
}
}
r=(w,q=+[],t=!![])=>w[q]+-~q?r(w,-~q,t^~-2?![]:{[w[q]]:!![]}[w[~-[...w].unshift()-q]]):t
console.log(r("racecar"))
test(r)