fix: localize toml parse errors
This commit is contained in:
@@ -21,6 +21,7 @@ func TestValidateInvalidTOMLReturnsInvalidAndDoesNotWrite(t *testing.T) {
|
||||
if len(got.Errors) == 0 {
|
||||
t.Fatalf("expected validation errors: %#v", got)
|
||||
}
|
||||
assertChineseTOMLError(t, got.Errors[0])
|
||||
assertFileContent(t, target, `name = "旧名称"`+"\n")
|
||||
}
|
||||
|
||||
@@ -56,6 +57,7 @@ func TestWriteInvalidTOMLRejectsAndLeavesOriginal(t *testing.T) {
|
||||
if err == nil {
|
||||
t.Fatal("expected invalid TOML write to be rejected")
|
||||
}
|
||||
assertChineseTOMLError(t, err.Error())
|
||||
assertFileContent(t, target, `name = "旧名称"`+"\n")
|
||||
}
|
||||
|
||||
@@ -159,3 +161,13 @@ func assertFileContent(t *testing.T, path string, want string) {
|
||||
t.Fatalf("%s content = %q, want %q", path, string(got), want)
|
||||
}
|
||||
}
|
||||
|
||||
func assertChineseTOMLError(t *testing.T, message string) {
|
||||
t.Helper()
|
||||
if strings.Contains(message, "invalid syntax") {
|
||||
t.Fatalf("TOML error leaked English parser text: %q", message)
|
||||
}
|
||||
if !strings.Contains(message, "字符串字段语法无效") {
|
||||
t.Fatalf("TOML error = %q, want Chinese string syntax error", message)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user