jsonstr.Compile() -> jsonstr.CompileStrings()

master
Charles Iliya Krempeaux 2023-09-27 12:28:37 +09:00
parent 160f1f1769
commit cca9187c97
3 changed files with 24 additions and 24 deletions

View File

@ -23,7 +23,7 @@ type Strings struct {
value string value string
} }
func Compile(a ...string) Strings { func CompileStrings(a ...string) Strings {
if len(a) <= 0 { if len(a) <= 0 {
return Strings{ return Strings{
value:"[]", value:"[]",

View File

@ -22,34 +22,34 @@ func TestString_MarshalJSON(t *testing.T) {
{ {
Strings: jsonstr.Compile("apple"), Strings: jsonstr.CompileStrings("apple"),
Expected: `["apple"]`, Expected: `["apple"]`,
}, },
{ {
Strings: jsonstr.Compile("apple", "banana"), Strings: jsonstr.CompileStrings("apple", "banana"),
Expected: `["apple","banana"]`, Expected: `["apple","banana"]`,
}, },
{ {
Strings: jsonstr.Compile("apple", "banana", "cherry"), Strings: jsonstr.CompileStrings("apple", "banana", "cherry"),
Expected: `["apple","banana","cherry"]`, Expected: `["apple","banana","cherry"]`,
}, },
{ {
Strings: jsonstr.Compile("😈"), Strings: jsonstr.CompileStrings("😈"),
Expected: `["😈"]`, Expected: `["😈"]`,
}, },
{ {
Strings: jsonstr.Compile("😈", "🙂🙁"), Strings: jsonstr.CompileStrings("😈", "🙂🙁"),
Expected: `["😈","🙂🙁"]`, Expected: `["😈","🙂🙁"]`,
}, },
{ {
Strings: jsonstr.Compile("😈", "🙂🙁", ""), Strings: jsonstr.CompileStrings("😈", "🙂🙁", ""),
Expected: `["😈","🙂🙁",""]`, Expected: `["😈","🙂🙁",""]`,
}, },
{ {
Strings: jsonstr.Compile("😈", "🙂🙁", "", "٠١٢٣۴۵۶٧٨٩"), Strings: jsonstr.CompileStrings("😈", "🙂🙁", "", "٠١٢٣۴۵۶٧٨٩"),
Expected: `["😈","🙂🙁","","٠١٢٣۴۵۶٧٨٩"]`, Expected: `["😈","🙂🙁","","٠١٢٣۴۵۶٧٨٩"]`,
}, },
} }

View File

@ -30,42 +30,42 @@ func TestString_UnmarshalJSON(t *testing.T) {
{ {
JSON: `["apple"]`, JSON: `["apple"]`,
Expected: jsonstr.Compile("apple"), Expected: jsonstr.CompileStrings("apple"),
}, },
{ {
JSON: `["apple","banana"]`, JSON: `["apple","banana"]`,
Expected: jsonstr.Compile("apple","banana"), Expected: jsonstr.CompileStrings("apple","banana"),
}, },
{ {
JSON: `["apple","banana","cherry"]`, JSON: `["apple","banana","cherry"]`,
Expected: jsonstr.Compile("apple","banana","cherry"), Expected: jsonstr.CompileStrings("apple","banana","cherry"),
}, },
{ {
JSON: `["😈"]`, JSON: `["😈"]`,
Expected: jsonstr.Compile("😈"), Expected: jsonstr.CompileStrings("😈"),
}, },
{ {
JSON: `["😈","🙂🙁"]`, JSON: `["😈","🙂🙁"]`,
Expected: jsonstr.Compile("😈","🙂🙁"), Expected: jsonstr.CompileStrings("😈","🙂🙁"),
}, },
{ {
JSON: `["😈","🙂🙁",""]`, JSON: `["😈","🙂🙁",""]`,
Expected: jsonstr.Compile("😈","🙂🙁",""), Expected: jsonstr.CompileStrings("😈","🙂🙁",""),
}, },
{ {
JSON: `["😈","🙂🙁","","٠١٢٣۴۵۶٧٨٩"]`, JSON: `["😈","🙂🙁","","٠١٢٣۴۵۶٧٨٩"]`,
Expected: jsonstr.Compile("😈","🙂🙁","","٠١٢٣۴۵۶٧٨٩"), Expected: jsonstr.CompileStrings("😈","🙂🙁","","٠١٢٣۴۵۶٧٨٩"),
}, },
{ {
JSON: `["1","two", "THREE", "iv", "۵"]`, JSON: `["1","two", "THREE", "iv", "۵"]`,
Expected: jsonstr.Compile("1","two", "THREE", "iv", "۵"), Expected: jsonstr.CompileStrings("1","two", "THREE", "iv", "۵"),
}, },
} }