-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6d01e21
commit a7f8e3e
Showing
1 changed file
with
9 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,27 @@ | ||
import { Glob } from "bun"; | ||
import { expect, test } from "bun:test"; | ||
import fs from "node:fs/promises"; | ||
import path from "node:path"; | ||
import init, { format } from "../pkg"; | ||
import init, { format } from "../pkg/lua_fmt"; | ||
|
||
await init(); | ||
|
||
async function* walk(dir: string): AsyncGenerator<string> { | ||
for await (const d of await fs.readdir(dir)) { | ||
const entry = path.join(dir, d); | ||
const stat = await fs.stat(entry); | ||
|
||
if (stat.isDirectory()) { | ||
yield* walk(entry); | ||
} | ||
|
||
if (stat.isFile()) { | ||
yield entry; | ||
} | ||
} | ||
} | ||
|
||
const test_root = Bun.fileURLToPath(new URL("../test_data", import.meta.url)); | ||
const glob = new Glob("**/*.lua"); | ||
|
||
for await (const input_path of walk(test_root)) { | ||
for await (const input_path of glob.scan(test_root)) { | ||
if (path.basename(input_path).startsWith(".")) { | ||
continue; | ||
} | ||
|
||
const ext = path.extname(input_path); | ||
|
||
switch (ext) { | ||
case ".lua": | ||
break; | ||
|
||
default: | ||
continue; | ||
} | ||
const full_path = path.join(test_root, input_path); | ||
|
||
const test_name = path.relative(test_root, input_path); | ||
const [input, expected] = await Promise.all([ | ||
Bun.file(input_path).text(), | ||
Bun.file(input_path + ".snap").text(), | ||
Bun.file(full_path).text(), | ||
Bun.file(full_path + ".snap").text(), | ||
]); | ||
|
||
test(test_name, () => { | ||
const actual = format(input, input_path); | ||
test(input_path, () => { | ||
const actual = format(input, input_path); | ||
expect(actual).toBe(expected); | ||
}); | ||
} |