test(primitives): Add new tests to check if variables are constant

This commit is contained in:
nprimo 2022-09-01 15:54:39 +01:00 committed by Niccolò Primo
parent ec55a11e80
commit 2f4900d8d2
1 changed files with 13 additions and 0 deletions

View File

@ -1,5 +1,14 @@
export const tests = []
const isConst = (name) => {
try {
eval(`${name} = 'm'`)
return false
} catch (err) {
return true
}
}
const t = (f) => tests.push(f)
// str is declared and of type string
t(() => typeof str === 'string')
@ -12,4 +21,8 @@ t(() => typeof bool === 'boolean')
// undef is declared and of type undefined
t(() => undef === undefined)
// check if all variables are const
t(() => ['str', 'num', 'bool', 'undef']
.every(isConst))
Object.freeze(tests)