test_harness #22
2
justfile
2
justfile
|
@ -3,4 +3,4 @@ repl:
|
|||
clj -X:repl
|
||||
|
||||
build:
|
||||
shadow-cljs release node
|
||||
shadow-cljs release module
|
||||
|
|
4100
package-lock.json
generated
4100
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
|
@ -3,12 +3,14 @@
|
|||
"version": "0.1.0-alpha.7.9",
|
||||
"description": "A Ludus interpreter in a pure JS function.",
|
||||
"main": "target/js/ludus.js",
|
||||
"type": "module",
|
||||
"directories": {},
|
||||
"keywords": [],
|
||||
"author": "Scott Richmond",
|
||||
"license": "GPL-3.0",
|
||||
"files": "target/js/*",
|
||||
"devDependencies": {
|
||||
"shadow-cljs": "^2.26.0"
|
||||
},
|
||||
"dependencies": {}
|
||||
"shadow-cljs": "^2.26.0",
|
||||
"tap": "^18.6.1"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,9 +5,13 @@
|
|||
|
||||
:builds
|
||||
{:node {:target :node-library
|
||||
:output-to "target/js/ludus.js"
|
||||
:exports {:run ludus.node/run}
|
||||
:modules {:main {:entries [ludus.node]}}}
|
||||
:output-to "target/js/ludus.js"
|
||||
:exports {:run ludus.node/run}
|
||||
:modules {:main {:entries [ludus.node]}}}
|
||||
:module {:target :esm
|
||||
:output-dir "target/js"
|
||||
:modules {:ludus {:exports {run ludus.node/run test ludus.node/run-test}}}
|
||||
}
|
||||
:browser {:target :browser
|
||||
:output-dir "target/js"
|
||||
:asset-path "target"
|
||||
|
|
|
@ -64,7 +64,7 @@
|
|||
|
||||
(defn test-run [source] (run source true))
|
||||
|
||||
(do
|
||||
(comment
|
||||
|
||||
(def source "
|
||||
|
||||
|
|
7
test/cases/if.ld
Normal file
7
test/cases/if.ld
Normal file
|
@ -0,0 +1,7 @@
|
|||
& EXPECT (:true, :false, :true, :false)
|
||||
let true_literal = if true then :true else :false
|
||||
let false_literal = if false then :true else :false
|
||||
let truthy = if :truthy then :true else :false
|
||||
let falsy = if nil then :true else :false
|
||||
|
||||
(true_literal, false_literal, truthy, falsy)
|
2
test/cases/list_atoms.ld
Normal file
2
test/cases/list_atoms.ld
Normal file
|
@ -0,0 +1,2 @@
|
|||
& EXPECT [:one, 2, "three"]
|
||||
[:one, 2, "three"]
|
2
test/cases/single_float.ld
Normal file
2
test/cases/single_float.ld
Normal file
|
@ -0,0 +1,2 @@
|
|||
& EXPECT 12.123
|
||||
12.123
|
2
test/cases/single_int.ld
Normal file
2
test/cases/single_int.ld
Normal file
|
@ -0,0 +1,2 @@
|
|||
& EXPECT 42
|
||||
42
|
2
test/cases/single_string.ld
Normal file
2
test/cases/single_string.ld
Normal file
|
@ -0,0 +1,2 @@
|
|||
& EXPECT "foo"
|
||||
"foo"
|
2
test/cases/tuple_keywords.ld
Normal file
2
test/cases/tuple_keywords.ld
Normal file
|
@ -0,0 +1,2 @@
|
|||
& EXPECT (true, false, nil)
|
||||
(true, false, nil)
|
30
test/run_tests.js
Normal file
30
test/run_tests.js
Normal file
|
@ -0,0 +1,30 @@
|
|||
import {run} from "../target/js/ludus.js"
|
||||
import * as fs from "node:fs/promises"
|
||||
import t from "tap"
|
||||
|
||||
const case_path = "./cases"
|
||||
const files = await fs.readdir(case_path)
|
||||
|
||||
for (const file of files) {
|
||||
const source = await fs.readFile(`${case_path}/${file}`, {encoding: "utf8"})
|
||||
const first_line = source.split("\n")[0]
|
||||
const expected = first_line.split("EXPECT")[1].trim()
|
||||
if (expected === "PANIC") expect_panic(file, source)
|
||||
else expect_result(file, source, expected)
|
||||
}
|
||||
|
||||
function expect_panic(file, source) {
|
||||
const result = run(source).errors[0]
|
||||
t.test(`testing ${file}: EXPECT PANIC`, t => {
|
||||
t.ok(result)
|
||||
t.end()
|
||||
})
|
||||
}
|
||||
|
||||
function expect_result(file, source, expected) {
|
||||
const result = run(source).result
|
||||
t.test(`testing ${file}: EXPECT ${expected}, GOT ${result}`, t => {
|
||||
t.equal(expected, result)
|
||||
t.end()
|
||||
})
|
||||
}
|
Loading…
Reference in New Issue
Block a user