Respect editorconfig formatting
This commit is contained in:
@@ -1148,6 +1148,87 @@ func TestSaveLockfilePreservesExistingOrderAndAppendsNewKeys(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSaveLockfileUsesEditorConfigJSONFormatting(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
writeFile(t, filepath.Join(root, ".editorconfig"), `root = true
|
||||
|
||||
[topdata/data/*.json]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
|
||||
[topdata/data/**/*.json]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
`)
|
||||
lockPath := filepath.Join(root, "topdata", "data", "feat", "lock.json")
|
||||
mkdirAll(t, filepath.Dir(lockPath))
|
||||
writeFile(t, lockPath, "{\n \"b\": 2,\n \"a\": 1\n}\n")
|
||||
|
||||
if err := saveLockfile(lockPath, map[string]int{
|
||||
"b": 2,
|
||||
"a": 1,
|
||||
"c": 3,
|
||||
}); err != nil {
|
||||
t.Fatalf("saveLockfile failed: %v", err)
|
||||
}
|
||||
|
||||
got, err := os.ReadFile(lockPath)
|
||||
if err != nil {
|
||||
t.Fatalf("read lockfile: %v", err)
|
||||
}
|
||||
want := "{\n \"b\": 2,\n \"a\": 1,\n \"c\": 3\n}\n"
|
||||
if string(got) != want {
|
||||
t.Fatalf("unexpected lockfile contents:\n%s", string(got))
|
||||
}
|
||||
}
|
||||
|
||||
func TestSaveNativeLockfilesNormalizesEditorConfigFormattingWhenDataIsUnchanged(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
writeFile(t, filepath.Join(root, ".editorconfig"), `root = true
|
||||
|
||||
[topdata/data/**/*.json]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
`)
|
||||
lockPath := filepath.Join(root, "topdata", "data", "feat", "lock.json")
|
||||
mkdirAll(t, filepath.Dir(lockPath))
|
||||
writeFile(t, lockPath, "{\n \"feat:a\": 1,\n \"feat:b\": 2\n}\n")
|
||||
|
||||
added, pruned, err := saveNativeLockfiles([]nativeCollectedDataset{
|
||||
{
|
||||
Dataset: nativeDataset{
|
||||
Name: "feat",
|
||||
LockPath: lockPath,
|
||||
},
|
||||
LockData: map[string]int{
|
||||
"feat:a": 1,
|
||||
"feat:b": 2,
|
||||
},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("saveNativeLockfiles failed: %v", err)
|
||||
}
|
||||
if added != 0 || pruned != 0 {
|
||||
t.Fatalf("expected formatting-only normalization not to count as lock data change, got added=%d pruned=%d", added, pruned)
|
||||
}
|
||||
|
||||
got, err := os.ReadFile(lockPath)
|
||||
if err != nil {
|
||||
t.Fatalf("read lockfile: %v", err)
|
||||
}
|
||||
want := "{\n \"feat:a\": 1,\n \"feat:b\": 2\n}\n"
|
||||
if string(got) != want {
|
||||
t.Fatalf("unexpected lockfile contents:\n%s", string(got))
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildNativeAllocatesConfiguredDatasetsIntoFirstNullBaseRows(t *testing.T) {
|
||||
root := testProjectRoot(t)
|
||||
mkdirAll(t, filepath.Join(root, "topdata", "data", "portraits", "modules"))
|
||||
|
||||
Reference in New Issue
Block a user