RC#1 — build wrote 2-space instead of .editorconfig's 4-space
- editorconfig_format.go: the glob translator escaped {/} as literals, so [*.{json,jsonc}]→indent_size=4 never matched any file and formatting fell back to [*]→2. Implemented real editorconfig brace expansion — {a,b,c} alternation and {n..m} numeric ranges. Nothing is hardcoded; saveLockfile already read .editorconfig, it just got the wrong section.
RC#2 — validate wrote a lockfile (it must be read-only)
- The three registry collectors persisted lockfiles as a side effect of collection; ValidateProject calls collection outside its snapshot guard, so the write leaked. Threaded a persistLocks bool through collectGeneratedRegistryDatasets and the damagetypes/itemprops/racialtypes collectors. Only buildNativeUnchecked (the real build allocator) passes true; validate, discovery, packaging queries, and wiki discovery pass false.
Tests added: editorconfig_glob_test.go (brace match + 4-space via brace glob), registry_readonly_test.go (read-only writes nothing; persist writes allocations).
Reviewed-on: #5
Co-authored-by: vickydotbat <vickydotbat@tutamail.com>
Co-committed-by: vickydotbat <vickydotbat@tutamail.com>
57 lines
1.7 KiB
Go
57 lines
1.7 KiB
Go
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))
|
|
}
|
|
}
|