test_harness #22

Merged
scott merged 3 commits from test_harness into main 2023-12-25 04:41:17 +00:00
7 changed files with 35 additions and 0 deletions
Showing only changes of commit d12d485583 - Show all commits

7
test/cases/if.ld Normal file
View 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
View File

@ -0,0 +1,2 @@
& EXPECT [:one, 2, "three"]
[:one, 2, "three"]

View File

@ -0,0 +1,2 @@
& EXPECT 12.123
12.123

2
test/cases/single_int.ld Normal file
View File

@ -0,0 +1,2 @@
& EXPECT 42
42

View File

@ -0,0 +1,2 @@
& EXPECT "foo"
"foo"

View File

@ -0,0 +1,2 @@
& EXPECT (true, false, nil)
(true, false, nil)

18
test/run_tests.js Normal file
View File

@ -0,0 +1,18 @@
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 script = await fs.readFile(`${case_path}/${file}`, {encoding: "utf8"})
const first_line = script.split("\n")[0]
const expected = first_line.split("EXPECT")[1].trim()
const result = run(script).result
t.test(`testing ${file}: EXPECT ${expected}, GOT ${result}`,
t => {
t.equal(expected, result)
t.end()
})
}