Crucible: Fix Formatting Churn
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
package topdata
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestEditorConfigPatternMatchesBraceExpansion(t *testing.T) {
|
||||
cases := []struct {
|
||||
pattern string
|
||||
path string
|
||||
want bool
|
||||
}{
|
||||
{"*.{json,jsonc}", "lock.json", true},
|
||||
{"*.{json,jsonc}", "types.jsonc", true},
|
||||
{"*.{json,jsonc}", "notes.md", false},
|
||||
{"*.{js,ts,tsx}", "main.tsx", true},
|
||||
{"{foo,bar}.txt", "bar.txt", true},
|
||||
{"{foo,bar}.txt", "baz.txt", false},
|
||||
{"page{1..3}.json", "page2.json", true},
|
||||
{"page{1..3}.json", "page4.json", false},
|
||||
// No comma and not a range: editorconfig treats braces literally.
|
||||
{"{single}.txt", "{single}.txt", true},
|
||||
{"{single}.txt", "single.txt", false},
|
||||
}
|
||||
for _, c := range cases {
|
||||
got, err := editorConfigPatternMatches(c.pattern, c.path)
|
||||
if err != nil {
|
||||
t.Fatalf("pattern %q path %q: %v", c.pattern, c.path, err)
|
||||
}
|
||||
if got != c.want {
|
||||
t.Errorf("editorConfigPatternMatches(%q, %q) = %v, want %v", c.pattern, c.path, got, c.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSaveLockfileHonorsBraceGlobIndentSize(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
writeFile(t, filepath.Join(root, ".editorconfig"), "root = true\n\n[*]\nindent_style = space\nindent_size = 2\n\n[*.{json,jsonc}]\nindent_size = 4\n")
|
||||
lockPath := filepath.Join(root, "data", "damagetypes", "registry", "lock.json")
|
||||
mkdirAll(t, filepath.Dir(lockPath))
|
||||
writeFile(t, lockPath, "{\n \"damagetype:acid\": 4\n}\n")
|
||||
|
||||
if err := saveLockfile(lockPath, map[string]int{"damagetype:acid": 4}); err != nil {
|
||||
t.Fatalf("saveLockfile: %v", err)
|
||||
}
|
||||
got, err := os.ReadFile(lockPath)
|
||||
if err != nil {
|
||||
t.Fatalf("read lockfile: %v", err)
|
||||
}
|
||||
want := "{\n \"damagetype:acid\": 4\n}\n"
|
||||
if string(got) != want {
|
||||
t.Fatalf("expected 4-space indent resolved from [*.{json,jsonc}]; got:\n%q", string(got))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user