-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into jacques_ubi
Signed-off-by: Jacques Grove <[email protected]>
- Loading branch information
Showing
29 changed files
with
795 additions
and
693 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package jsonutil | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestMarshalNoEscape(t *testing.T) { | ||
cases := []struct { | ||
name string | ||
v interface{} | ||
expected string | ||
}{ | ||
{ | ||
name: "normal", | ||
v: struct { | ||
Usr string | ||
Pwd string | ||
}{ | ||
Usr: "vitess", | ||
Pwd: "vitess", | ||
}, | ||
expected: "{\"Usr\":\"vitess\",\"Pwd\":\"vitess\"}", | ||
}, | ||
{ | ||
name: "not exported", | ||
v: struct { | ||
usr string | ||
pwd string | ||
}{ | ||
usr: "vitess", | ||
pwd: "vitess", | ||
}, | ||
expected: "{}", | ||
}, | ||
} | ||
for _, c := range cases { | ||
t.Run(c.name, func(t *testing.T) { | ||
json, _ := MarshalNoEscape(c.v) | ||
sjson := string(json[:len(json)-1]) | ||
if sjson != c.expected { | ||
t.Errorf("expected: %v, got: %v", c.expected, sjson) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestMarshalIndentNoEscape(t *testing.T) { | ||
cases := []struct { | ||
name string | ||
v interface{} | ||
prefix string | ||
ident string | ||
expected string | ||
}{ | ||
{ | ||
name: "normal", | ||
v: struct { | ||
Usr string | ||
Pwd string | ||
}{ | ||
Usr: "vitess", | ||
Pwd: "vitess", | ||
}, | ||
prefix: "test", | ||
ident: "\t", | ||
expected: "{\ntest\t\"Usr\": \"vitess\",\ntest\t\"Pwd\": \"vitess\"\ntest}", | ||
}, | ||
{ | ||
name: "not exported", | ||
v: struct { | ||
usr string | ||
pwd string | ||
}{ | ||
usr: "vitess", | ||
pwd: "vitess", | ||
}, | ||
expected: "{}", | ||
}, | ||
} | ||
for _, c := range cases { | ||
t.Run(c.name, func(t *testing.T) { | ||
json, _ := MarshalIndentNoEscape(c.v, c.prefix, c.ident) | ||
sjson := string(json[:len(json)-1]) | ||
if sjson != c.expected { | ||
t.Errorf("expected: %v, got: %v", c.expected, sjson) | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.