Skip to content

Commit

Permalink
reverse-string: add UTF-8 multibyte test case
Browse files Browse the repository at this point in the history
Add reverseTestCase type in generator output to be
used in the test program.

Since file cases_test.go is generated from
problem-specifications/exercises/reverse-string/canonical-data.json,
add an additional test case for UTF-8 within the test program.

Resolves exercism#1068
  • Loading branch information
leenipper committed Feb 6, 2018
1 parent e458903 commit 7811ed5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
6 changes: 4 additions & 2 deletions exercises/reverse-string/.meta/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ var tmpl = `package reverse
{{.Header}}
var testCases = []struct {
type reverseTestCase struct {
description string
input string
expected string
}{ {{range .J.Cases}}
}
var testCases = []reverseTestCase{ {{range .J.Cases}}
{
description: {{printf "%q" .Description}},
input: {{printf "%q" .Input.Value}},
Expand Down
6 changes: 4 additions & 2 deletions exercises/reverse-string/cases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ package reverse
// Commit: 2f77985 reverse-string: apply "input" policy
// Problem Specifications Version: 1.1.0

var testCases = []struct {
type reverseTestCase struct {
description string
input string
expected string
}{
}

var testCases = []reverseTestCase{
{
description: "an empty string",
input: "",
Expand Down
13 changes: 12 additions & 1 deletion exercises/reverse-string/reverse_string_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

func TestReverse(t *testing.T) {
for _, testCase := range testCases {
for _, testCase := range append(testCases, multiByteCases...) {
if res := String(testCase.input); res != testCase.expected {
t.Fatalf("FAIL: %s(%s)\nExpected: %q\nActual: %q",
testCase.description, testCase.input, testCase.expected, res)
Expand All @@ -31,3 +31,14 @@ func BenchmarkReverse(b *testing.B) {
}
}
}

// mutiByteCases adds UTF-8 multi-byte case,
// since the canonical-data.json (generator data source for cases_test.go)
// doesn't have any such cases.
var multiByteCases = []reverseTestCase{
{
description: "a multi-byte test case",
input: "Hello, 世界",
expected: "界世 ,olleH",
},
}

0 comments on commit 7811ed5

Please sign in to comment.