diff --git a/src/test.js b/src/test.js index 03a9139..a649689 100644 --- a/src/test.js +++ b/src/test.js @@ -10,9 +10,16 @@ test(vm) //is it funny that we're testing the unit testing with the unit testing? // //yes -console.log(await run(`%( +/*console.log(await run(`%( (set x "deez") (assertTrue "Successful assertion to true" (equals 1 1)) (assertTrue "Failed assertion to true" (equals 1 0)) (assertTrue "Assertion with variables and strings" (equals (x) "deez")) +)`, vm))*/ +console.log(await run(`%( + (set x "deez") + (testSet "Test set 1" + (assertTrue "Successful assertion to true" (equals 1 1)) + (assertTrue "Failed assertion to true" (equals 1 0)) + (assertTrue "Assertion with variables and strings" (equals (x) "deez"))) )`, vm)) diff --git a/src/testFunc.js b/src/testFunc.js index 53511ca..a046ea4 100644 --- a/src/testFunc.js +++ b/src/testFunc.js @@ -3,17 +3,35 @@ 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 + }), assertTrue: wrapFunc("assertTrue", 2, (args) => { + let res if (!args[1]) { - /*throw new AssertionError({ - message: `"${args[0]}" failed!`, - actual: args[1], - expected: trueValue - })*/ - console.log(`"${args[0]}" failed! -Expected: '${trueValue}' -Recieved: '${args[1]}'`) + res = false + } else { + res = true } - return args[1] + return JSON.stringify({ + res: res, + desc: args[0], + expected: trueValue, + recieved: args[1] + }) }) }