-
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
5dddd61
commit f4e0f57
Showing
5 changed files
with
103 additions
and
56 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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/usr/bin/env -S deno run --allow-read --allow-write | ||
import { walk } from "jsr:@std/fs/walk"; | ||
|
||
import init, { format } from "../build/dart_fmt.js" | ||
|
||
await init(); | ||
|
||
const test_root = new URL(import.meta.resolve("../test_data")); | ||
|
||
for await (const entry of walk(test_root, { | ||
includeDirs: false, | ||
exts: ["unit"], | ||
})) { | ||
if (entry.name.startsWith(".")) { | ||
continue; | ||
} | ||
|
||
const expect_path = entry.path + ".snap"; | ||
const input = Deno.readTextFileSync(entry.path); | ||
|
||
const actual = format(input, entry.path); | ||
Deno.writeTextFileSync(expect_path, actual); | ||
} | ||
console.log("done"); |
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,25 @@ | ||
import { Glob } from "bun"; | ||
import { expect, test } from "bun:test"; | ||
import { chdir } from "node:process"; | ||
import { fileURLToPath } from "node:url"; | ||
|
||
import init, { format } from "../build/dart_fmt.js"; | ||
|
||
await init(); | ||
|
||
const test_root = fileURLToPath(import.meta.resolve("../test_data")); | ||
chdir(test_root); | ||
|
||
const glob = new Glob("**/*.unit"); | ||
|
||
for await (const input_path of glob.scan()) { | ||
const [input, expected] = await Promise.all([ | ||
Bun.file(input_path).text(), | ||
Bun.file(input_path + ".snap").text(), | ||
]); | ||
|
||
test(input_path, () => { | ||
const actual = format(input, input_path); | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,29 @@ | ||
import init, { format } from "../build/dart_fmt.js" | ||
import { assertEquals } from "jsr:@std/assert"; | ||
import { walk } from "jsr:@std/fs/walk"; | ||
|
||
import { assertEquals } from "https://deno.land/std@0.219.0/assert/mod.ts"; | ||
import { walk } from "https://deno.land/std@0.219.0/fs/walk.ts"; | ||
import { relative } from "https://deno.land/std@0.219.0/path/mod.ts"; | ||
import init, { format } from "../build/dart_fmt.js" | ||
|
||
await init(); | ||
|
||
const update = Deno.args.includes("--update"); | ||
|
||
const test_root = new URL("../test_data", import.meta.url); | ||
const test_root = new URL(import.meta.resolve("../test_data")); | ||
Deno.chdir(test_root); | ||
|
||
for await (const entry of walk(test_root, { | ||
includeDirs: false, | ||
exts: ["unit"], | ||
for await (const entry of walk(".", { | ||
includeDirs: false, | ||
exts: ["unit"], | ||
})) { | ||
if (entry.name.startsWith(".")) { | ||
continue; | ||
} | ||
if (entry.name.startsWith(".")) { | ||
continue; | ||
} | ||
|
||
const input = Deno.readTextFileSync(entry.path); | ||
const input_path = entry.path; | ||
const expect_path = input_path + ".snap"; | ||
|
||
if (update) { | ||
const actual = format(input, entry.path); | ||
Deno.writeTextFileSync(entry.path + ".snap", actual); | ||
} else { | ||
const test_name = relative(test_root.pathname, entry.path); | ||
const expected = Deno.readTextFileSync(entry.path + ".snap"); | ||
const input = Deno.readTextFileSync(input_path); | ||
const expected = Deno.readTextFileSync(expect_path); | ||
|
||
Deno.test(test_name, () => { | ||
const actual = format(input, entry.path); | ||
assertEquals(actual, expected); | ||
}); | ||
} | ||
Deno.test(input_path, () => { | ||
const actual = format(input, entry.path); | ||
assertEquals(actual, 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,31 @@ | ||
import init, { format } from "../build/dart_fmt_node.js"; | ||
import { test } from "node:test"; | ||
import assert from "node:assert/strict"; | ||
import fs from "node:fs/promises"; | ||
import path from "node:path"; | ||
import { basename } from "node:path"; | ||
import { chdir } from "node:process"; | ||
import { test } from "node:test"; | ||
import { fileURLToPath } from "node:url"; | ||
|
||
await init(); | ||
|
||
const test_root = fileURLToPath(new URL("../test_data", import.meta.url)); | ||
|
||
for await (const dirent of await fs.opendir(test_root, { recursive: true })) { | ||
if (!dirent.isFile()) { | ||
continue; | ||
} | ||
import init, { format } from "../build/dart_fmt_node.js"; | ||
|
||
if (dirent.name.startsWith(".")) { | ||
continue; | ||
} | ||
await init(); | ||
|
||
const input_path = path.join(dirent.path, dirent.name); | ||
const ext = path.extname(input_path); | ||
const test_root = fileURLToPath(import.meta.resolve("../test_data")); | ||
chdir(test_root); | ||
|
||
switch (ext) { | ||
case ".unit": | ||
break; | ||
for await (const input_path of fs.glob("**/*.unit")) { | ||
if (basename(input_path).startsWith(".")) { | ||
continue; | ||
} | ||
|
||
default: | ||
continue; | ||
} | ||
const expect_path = input_path + ".snap"; | ||
|
||
const test_name = path.relative(test_root, input_path); | ||
const [input, expected] = await Promise.all([ | ||
fs.readFile(input_path, { encoding: "utf-8" }), | ||
fs.readFile(input_path + ".snap", { encoding: "utf-8" }), | ||
]); | ||
const [input, expected] = await Promise.all([ | ||
fs.readFile(input_path, "utf-8"), | ||
fs.readFile(expect_path, "utf-8"), | ||
]); | ||
|
||
test(test_name, () => { | ||
const actual = format(input, input_path); | ||
assert.equal(actual, expected); | ||
}); | ||
test(input_path, () => { | ||
const actual = format(input, input_path); | ||
assert.equal(actual, expected); | ||
}); | ||
} |