From f7eb854196b4c8755d71850839b193b848a865a6 Mon Sep 17 00:00:00 2001 From: Ruthenic Date: Wed, 23 Feb 2022 16:26:00 -0500 Subject: [PATCH] Init --- .gitignore | 1 + package.json | 15 +++++++++++++++ src/cases/equality/index.js | 16 ++++++++++++++++ src/index.js | 7 +++++++ src/test.js | 18 ++++++++++++++++++ src/testFunc.js | 19 +++++++++++++++++++ 6 files changed, 76 insertions(+) create mode 100644 .gitignore create mode 100644 package.json create mode 100644 src/cases/equality/index.js create mode 100644 src/index.js create mode 100644 src/test.js create mode 100644 src/testFunc.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/package.json b/package.json new file mode 100644 index 0000000..53579cd --- /dev/null +++ b/package.json @@ -0,0 +1,15 @@ +{ + "name": "cumlisp", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC", + "dependencies": { + "cumlisp": "^1.3.1" + }, + "type": "module" +} diff --git a/src/cases/equality/index.js b/src/cases/equality/index.js new file mode 100644 index 0000000..7bdda23 --- /dev/null +++ b/src/cases/equality/index.js @@ -0,0 +1,16 @@ +import { wrapFunc, trueValue, falseValue } from "cumlisp" + +export default { + equals: wrapFunc("equals", 2, (args) => { + if (args[0] === args[1]) return trueValue + return falseValue + }), + inequals: wrapFunc("inequals", 2, (args) => { + if (args[0] === args[1]) return falseValue + return trueValue + }), + truthy: wrapFunc("truthy", 1, (args) => { + if (args[0] === trueValue) return trueValue + return falseValue + }) +} diff --git a/src/index.js b/src/index.js new file mode 100644 index 0000000..95b2921 --- /dev/null +++ b/src/index.js @@ -0,0 +1,7 @@ +import equalities from "./cases/equality/index.js" +import test from "./testFunc.js" + +export default function(vm) { + vm.install(test) + vm.install(equalities) +} diff --git a/src/test.js b/src/test.js new file mode 100644 index 0000000..03a9139 --- /dev/null +++ b/src/test.js @@ -0,0 +1,18 @@ +import { VM, run, libBasic } from "cumlisp" + +import test from "./index.js" + +const vm = new VM() + +libBasic.installBasic(vm) +test(vm) + +//is it funny that we're testing the unit testing with the unit testing? +// +//yes +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)) diff --git a/src/testFunc.js b/src/testFunc.js new file mode 100644 index 0000000..53511ca --- /dev/null +++ b/src/testFunc.js @@ -0,0 +1,19 @@ +import { wrapFunc, trueValue, falseValue } from "cumlisp"; +import { AssertionError } from "assert" +import { exit } from "process" + +export default { + assertTrue: wrapFunc("assertTrue", 2, (args) => { + 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]}'`) + } + return args[1] + }) +}