diff options
| author | Shulhan <ms@kilabit.info> | 2022-08-03 22:27:33 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2022-08-03 22:27:33 +0700 |
| commit | ec98ea095fa85b5a4b64bd7ad37414c30d14310e (patch) | |
| tree | a0d0af0ad27852b1644972ee2b11e870ea5acc03 /lib/strings/row_test.go | |
| parent | 39d9c20c35a11c44cdd27783e407c1225027d820 (diff) | |
| download | pakakeh.go-ec98ea095fa85b5a4b64bd7ad37414c30d14310e.tar.xz | |
lib/strings: clean up test codes
Changes,
* Use test.Data for test that require longer text input and output
* Replace variable declaration ":=" with explicit one.
* Use literal string
Diffstat (limited to 'lib/strings/row_test.go')
| -rw-r--r-- | lib/strings/row_test.go | 84 |
1 files changed, 49 insertions, 35 deletions
diff --git a/lib/strings/row_test.go b/lib/strings/row_test.go index b3ac097d..2d63f501 100644 --- a/lib/strings/row_test.go +++ b/lib/strings/row_test.go @@ -11,56 +11,70 @@ import ( ) func TestRowIsEqual(t *testing.T) { - cases := []struct { - a, b Row - exp bool - }{{ - a: Row{{"a"}, {"b", "c"}}, - b: Row{{"a"}, {"b", "c"}}, + type testCase struct { + a Row + b Row + exp bool + } + + var cases = []testCase{{ + a: Row{{`a`}, {`b`, `c`}}, + b: Row{{`a`}, {`b`, `c`}}, exp: true, }, { - a: Row{{"a"}, {"b", "c"}}, - b: Row{{"a"}, {"c", "b"}}, + a: Row{{`a`}, {`b`, `c`}}, + b: Row{{`a`}, {`c`, `b`}}, exp: true, }, { - a: Row{{"a"}, {"b", "c"}}, - b: Row{{"c", "b"}, {"a"}}, + a: Row{{`a`}, {`b`, `c`}}, + b: Row{{`c`, `b`}, {`a`}}, exp: true, }, { - a: Row{{"a"}, {"b", "c"}}, - b: Row{{"a"}, {"b", "a"}}, + a: Row{{`a`}, {`b`, `c`}}, + b: Row{{`a`}, {`b`, `a`}}, }} - for _, c := range cases { - got := c.a.IsEqual(c.b) - test.Assert(t, "", c.exp, got) + var ( + c testCase + got bool + ) + for _, c = range cases { + got = c.a.IsEqual(c.b) + test.Assert(t, ``, c.exp, got) } } func TestRowJoin(t *testing.T) { - cases := []struct { - row Row - lsep, ssep string - exp string - }{{ - // - lsep: ";", - ssep: ",", - exp: "", + type testCase struct { + lsep string + ssep string + exp string + row Row + } + var cases = []testCase{{ + // Empty input. + }, { + lsep: `;`, + ssep: `,`, + exp: ``, }, { - row: Row{{"a"}, {}}, - lsep: ";", - ssep: ",", - exp: "a;", + row: Row{{`a`}, {}}, + lsep: `;`, + ssep: `,`, + exp: `a;`, }, { - row: Row{{"a"}, {"b", "c"}}, - lsep: ";", - ssep: ",", - exp: "a;b,c", + row: Row{{`a`}, {`b`, `c`}}, + lsep: `;`, + ssep: `,`, + exp: `a;b,c`, }} - for _, c := range cases { - got := c.row.Join(c.lsep, c.ssep) - test.Assert(t, "", c.exp, got) + var ( + c testCase + got string + ) + for _, c = range cases { + got = c.row.Join(c.lsep, c.ssep) + test.Assert(t, ``, c.exp, got) } } |
