diff --git a/example/example.go b/example/example.go index 92788f7..60112f8 100644 --- a/example/example.go +++ b/example/example.go @@ -15,14 +15,12 @@ type writer interface { } func writeToWriter(w writer) { - w.Write([]string{"userId", "secret", "comment"}) - w.Write([]string{"-21+63", "=A1", "foo, bar"}) - w.Write([]string{"+42", "\tsecret", "\nplop"}) - w.Write([]string{"123", "blablabla", "@foobar"}) + must(w.Write([]string{"userId", "secret", "comment"})) + must(w.Write([]string{"-21+63", "=A1", "foo, bar"})) + must(w.Write([]string{"+42", "\tsecret", "\nplop"})) + must(w.Write([]string{"123", "blablabla", "@foobar"})) w.Flush() - if err := w.Error(); err != nil { - panic(err) - } + must(w.Error()) } func unsafe() string { diff --git a/example/utils.go b/example/utils.go new file mode 100644 index 0000000..6f6f7dc --- /dev/null +++ b/example/utils.go @@ -0,0 +1,7 @@ +package main + +func must(err error) { + if err != nil { + panic(err) + } +} diff --git a/writer_test.go b/writer_test.go index d1260e4..3ec545e 100644 --- a/writer_test.go +++ b/writer_test.go @@ -7,6 +7,12 @@ import ( "github.com/stretchr/testify/assert" ) +func must(err error) { + if err != nil { + panic(err) + } +} + func buildTest(forceDoubleQuotes bool, escapeCharEqual bool, escapeCharPlus bool, escapeCharMinus bool, escapeCharAt bool, escapeCharTab bool, escapeCharCR bool) string { var buff strings.Builder @@ -22,14 +28,12 @@ func buildTest(forceDoubleQuotes bool, escapeCharEqual bool, escapeCharPlus bool EscapeCharCR: escapeCharCR, }, ) - writer.Write([]string{"userId", "secret", "comment"}) - writer.Write([]string{"-21+63", "=A1", "foo, bar"}) - writer.Write([]string{"+42", "\tsecret", "\nplop"}) - writer.Write([]string{"123", "blablabla", "@foobar"}) + must(writer.Write([]string{"userId", "secret", "comment"})) + must(writer.Write([]string{"-21+63", "=A1", "foo, bar"})) + must(writer.Write([]string{"+42", "\tsecret", "\nplop"})) + must(writer.Write([]string{"123", "blablabla", "@foobar"})) writer.Flush() - if err := writer.Error(); err != nil { - panic(err) - } + must(writer.Error()) return buff.String() }