Splitting the structure tests

This commit is contained in:
tombuildsstuff 2017-03-27 17:54:21 +01:00
parent 459c9a0a5a
commit 6efdc94ae3
1 changed files with 6 additions and 6 deletions

View File

@ -4,10 +4,7 @@ import (
"testing" "testing"
) )
func TestNormalizeJsonString(t *testing.T) { func TestNormalizeJsonString_valid(t *testing.T) {
var err error
var actual string
// Well formatted and valid. // Well formatted and valid.
validJson := `{ validJson := `{
"abc": { "abc": {
@ -24,7 +21,7 @@ func TestNormalizeJsonString(t *testing.T) {
}` }`
expected := `{"abc":{"def":123,"xyz":[{"a":"ホリネズミ"},{"b":"1\\n2"}]}}` expected := `{"abc":{"def":123,"xyz":[{"a":"ホリネズミ"},{"b":"1\\n2"}]}}`
actual, err = NormalizeJsonString(validJson) actual, err := NormalizeJsonString(validJson)
if err != nil { if err != nil {
t.Fatalf("Expected not to throw an error while parsing JSON, but got: %s", err) t.Fatalf("Expected not to throw an error while parsing JSON, but got: %s", err)
} }
@ -32,7 +29,9 @@ func TestNormalizeJsonString(t *testing.T) {
if actual != expected { if actual != expected {
t.Fatalf("Got:\n\n%s\n\nExpected:\n\n%s\n", actual, expected) t.Fatalf("Got:\n\n%s\n\nExpected:\n\n%s\n", actual, expected)
} }
}
func TestNormalizeJsonString_invalid(t *testing.T) {
// Well formatted but not valid, // Well formatted but not valid,
// missing closing squre bracket. // missing closing squre bracket.
invalidJson := `{ invalidJson := `{
@ -45,7 +44,8 @@ func TestNormalizeJsonString(t *testing.T) {
} }
} }
}` }`
actual, err = NormalizeJsonString(invalidJson) expected := `{"abc":{"def":123,"xyz":[{"a":"ホリネズミ"},{"b":"1\\n2"}]}}`
actual, err := NormalizeJsonString(invalidJson)
if err == nil { if err == nil {
t.Fatalf("Expected to throw an error while parsing JSON, but got: %s", err) t.Fatalf("Expected to throw an error while parsing JSON, but got: %s", err)
} }