Skip to content

Commit

Permalink
passing test and better error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
nicksnyder committed Feb 3, 2024
1 parent 7c6508d commit 15b26d9
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion i18n/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@ func TestParseMessageFileBytes(t *testing.T) {
}},
},
},
{
name: "nested with reserved key",
file: `{"nested": {"description": {"other": "world"}}}`,
path: "en.json",
messageFile: &MessageFile{
Path: "en.json",
Tag: language.English,
Format: "json",
Messages: []*Message{{
ID: "nested.description",
Other: "world",
}},
},
},
{
name: "basic test with dot separator in key",
file: `{"prepended.hello": "world"}`,
Expand Down Expand Up @@ -179,13 +193,21 @@ outer:
t.Errorf("expected format %q; got %q", testCase.messageFile.Format, actual.Format)
}
if !equalMessages(actual.Messages, testCase.messageFile.Messages) {
t.Errorf("expected %#v; got %#v", testCase.messageFile.Messages, actual.Messages)
t.Errorf("expected %#v; got %#v", deref(testCase.messageFile.Messages), deref(actual.Messages))
}
}
})
}
}

func deref(mptrs []*Message) []Message {
messages := make([]Message, len(mptrs))
for i, m := range mptrs {
messages[i] = *m
}
return messages
}

// equalMessages compares two slices of messages, ignoring private fields and order.
// Sorts both input slices, which are therefore modified by this function.
func equalMessages(m1, m2 []*Message) bool {
Expand Down

0 comments on commit 15b26d9

Please sign in to comment.