-
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
57044da
commit a6c5233
Showing
24 changed files
with
113 additions
and
55 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 |
---|---|---|
|
@@ -23,3 +23,5 @@ go.work | |
gofmt.wasm | ||
*.tgz | ||
gofmt.js | ||
|
||
node_modules |
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,5 +1,7 @@ | ||
.github | ||
.vscode | ||
testdata | ||
test_* | ||
src | ||
node_modules | ||
*.tgz | ||
*.patch | ||
*.sh | ||
*.patch | ||
.* |
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,10 +1,14 @@ | ||
{ | ||
"go.testEnvVars": { | ||
"GOARCH": "wasm", | ||
"GOOS": "js" | ||
}, | ||
"go.toolsEnvVars": { | ||
"GOARCH": "wasm", | ||
"GOOS": "js" | ||
} | ||
} | ||
"go.testEnvVars": { | ||
"GOARCH": "wasm", | ||
"GOOS": "js" | ||
}, | ||
"go.toolsEnvVars": { | ||
"GOARCH": "wasm", | ||
"GOOS": "js" | ||
}, | ||
"deno.enable": true, | ||
"deno.enablePaths": [ | ||
"test_deno" | ||
] | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,13 +1,13 @@ | ||
/* | ||
Source containing CR/LF line endings. | ||
The gofmt'ed output must only have LF | ||
line endings. | ||
Test case for issue 3961. | ||
*/ | ||
package main | ||
func main() { | ||
// line comment | ||
println("hello, world!") // another line comment | ||
println() | ||
} | ||
/* | ||
Source containing CR/LF line endings. | ||
The gofmt'ed output must only have LF | ||
line endings. | ||
Test case for issue 3961. | ||
*/ | ||
package main | ||
|
||
func main() { | ||
// line comment | ||
println("hello, world!") // another line comment | ||
println() | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,33 @@ | ||
import init, { format } from "../gofmt.js"; | ||
|
||
import { assertEquals } from "https://deno.land/std@0.201.0/assert/mod.ts"; | ||
import { walk } from "https://deno.land/std@0.201.0/fs/walk.ts"; | ||
import { relative } from "https://deno.land/std@0.201.0/path/mod.ts"; | ||
|
||
await init(); | ||
|
||
const update = Deno.args.includes("--update"); | ||
|
||
const test_root = new URL("../test_data", import.meta.url); | ||
|
||
for await (const entry of walk(test_root, { | ||
includeDirs: false, | ||
exts: ["input"], | ||
})) { | ||
const expect_path = entry.path.replace(/input$/, "golden"); | ||
const input = Deno.readTextFileSync(entry.path); | ||
|
||
const actual = format(input); | ||
|
||
if (update) { | ||
Deno.writeTextFileSync(expect_path, actual); | ||
} else { | ||
const expected = Deno.readTextFileSync(expect_path); | ||
|
||
const test_name = relative(test_root.pathname, entry.path); | ||
|
||
Deno.test(test_name, () => { | ||
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import init, { format } from "../gofmt.js"; | ||
import { test } from "node:test"; | ||
import assert from "node:assert/strict"; | ||
import fs from "node:fs/promises"; | ||
import path from "node:path"; | ||
import { fileURLToPath } from "node:url"; | ||
|
||
await init(); | ||
|
||
/** | ||
* @param {string} dir | ||
* @returns {Generator<string>} | ||
*/ | ||
async function* walk(dir) { | ||
for await (const d of await fs.opendir(dir)) { | ||
const entry = path.join(dir, d.name); | ||
if (d.isDirectory()) yield* walk(entry); | ||
else if (d.isFile()) yield entry; | ||
} | ||
} | ||
|
||
const test_root = 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([ | ||
fs.readFile(input_path, { encoding: "utf-8" }), | ||
fs.readFile(input_path.replace(ext, ".golden"), { encoding: "utf-8" }), | ||
]); | ||
|
||
const actual = format(input, input_path); | ||
|
||
test(test_name, () => { | ||
assert.equal(actual, expected); | ||
}); | ||
} |