| 1 |
// Copyright (c) 2019, Maxime Soulé |
| 2 |
// All rights reserved. |
| 3 |
// |
| 4 |
// This source code is licensed under the BSD-style license found in the |
| 5 |
// LICENSE file in the root directory of this source tree. |
| 6 |
|
| 7 |
package tdutil_test |
| 8 |
|
| 9 |
import ( |
| 10 |
"testing" |
| 11 |
|
| 12 |
"github.com/maxatome/go-testdeep/helpers/tdutil" |
| 13 |
) |
| 14 |
|
| 15 |
func TestFormatString(t *testing.T) { |
| 16 |
for _, curTest := range []struct { |
| 17 |
paramGot string |
| 18 |
expected string |
| 19 |
}{ |
| 20 |
{paramGot: "foobar", expected: `"foobar"`}, |
| 21 |
{paramGot: "foo\rbar", expected: `(string) (len=7) "foo\rbar"`}, |
| 22 |
{paramGot: "foo\u2028bar", expected: `(string) (len=9) "foo\u2028bar"`}, |
| 23 |
{paramGot: `foo"bar`, expected: "`foo\"bar`"}, |
| 24 |
{paramGot: "foo\n\"bar", expected: "`foo\n\"bar`"}, |
| 25 |
{paramGot: "foo`\"\nbar", expected: "(string) (len=9) \"foo`\\\"\\nbar\""}, |
| 26 |
{paramGot: "foo`\n\"bar", expected: "(string) (len=9) \"foo`\\n\\\"bar\""}, |
| 27 |
{paramGot: "foo\n`\"bar", expected: "(string) (len=9) \"foo\\n`\\\"bar\""}, |
| 28 |
{paramGot: "foo\n\"`bar", expected: "(string) (len=9) \"foo\\n\\\"`bar\""}, |
| 29 |
} { |
| 30 |
got := tdutil.FormatString(curTest.paramGot) |
| 31 |
if got != curTest.expected { |
| 32 |
t.Errorf(`got "%s" ≠ expected "%s"`, got, curTest.expected) |
| 33 |
} |
| 34 |
} |
| 35 |
} |