-
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
a2bd50d
commit 0757ed6
Showing
4 changed files
with
58 additions
and
16 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
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 |
---|---|---|
|
@@ -38,9 +38,11 @@ | |
"patch": "git apply ./gofmt.patch", | ||
"build": "tinygo build -o=gofmt.wasm -target=wasm -no-debug -stack-size=24kb ./src/lib.go", | ||
"postbuild": "npm run gofmt && npm run patch", | ||
"test:node": "node --test", | ||
"test:deno": "deno test --allow-read" | ||
"test:node": "node --test test_node", | ||
"test:deno": "deno test test_deno --allow-read", | ||
"test:bun": "bun test test_bun" | ||
}, | ||
"packageManager": "[email protected]", | ||
"engines": { | ||
"node": ">=16.17.0" | ||
}, | ||
|
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { expect, test } from "bun:test"; | ||
import init, { format } from "../gofmt.js"; | ||
import fs from "node:fs/promises"; | ||
import path from "node:path"; | ||
|
||
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)); | ||
|
||
for await (const input_path of walk(test_root)) { | ||
const ext = path.extname(input_path); | ||
|
||
switch (ext) { | ||
case ".input": | ||
break; | ||
|
||
default: | ||
continue; | ||
} | ||
|
||
const test_name = path.relative(test_root, input_path); | ||
const [input, expected] = await Promise.all([ | ||
Bun.file(input_path).text(), | ||
Bun.file(input_path.replace(ext, ".golden")).text(), | ||
]); | ||
|
||
const actual = format(input); | ||
|
||
test(test_name, () => { | ||
expect(actual).toBe(expected); | ||
}); | ||
} |
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