You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.3 KiB

import { wrapFunc, trueValue, falseValue } from "cumlisp";
import { AssertionError } from "assert"
import { exit } from "process"
export default {
testSet: wrapFunc("testSet", -1, (args) => {
const setName = args.shift()
console.log(`Testing ${setName}...`)
let res = true
for (const i in args) {
args[i] = JSON.parse(args[i])
if (!args[i].res) {
console.log(` ${args[i].desc} failed!
- Expected: ${args[i].expected}
- Recieved: ${args[i].recieved}`)
res = false
} else {
console.log(` ${args[i].desc} succeeded!`)
}
}
return res
}),
testWrapper: wrapFunc("testWrapper", -1, (args) => {
//simple wrapper around multiple test sets that returns false if any test sets return false
for (const i in args) {
if (!JSON.parse(args[i])) {
return false
}
}
return trueValue
}),
assertTrue: wrapFunc("assertTrue", 2, (args) => {
let res
if (!args[1]) {
res = false
} else {
res = true
}
return JSON.stringify({
res: res,
desc: args[0],
expected: trueValue,
recieved: args[1]
})
}),
assertEquals: wrapFunc("assertEquals", 3, (args) => {
//this makes (equals) redundant but oh well
let res
res = (args[1] === args[2])
return JSON.stringify({
res: res,
desc: args[0],
recieved: args[1],
expected: args[2]
})
})
}