Encoder: try to use pointer type TextMarshaler (#679)

If a type does not implement the encoding.TextMarshaler interface but
its pointer type does, use it if possible.

Fixes #678
This commit is contained in:
Thomas Pelletier
2021-11-24 14:43:49 -05:00
committed by GitHub
parent 8645d6376b
commit 2b3de620e8
3 changed files with 80 additions and 25 deletions
+30
View File
@@ -664,6 +664,36 @@ func TestUnmarshal(t *testing.T) {
}
},
},
{
desc: "long string array into []string",
input: `A = ["0","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17"]`,
gen: func() test {
type doc struct {
A []string
}
return test{
target: &doc{},
expected: &doc{A: []string{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17"}},
}
},
},
{
desc: "long string array into []interface{}",
input: `A = ["0","1","2","3","4","5","6","7","8","9","10","11","12","13","14",
"15","16","17"]`,
gen: func() test {
type doc struct {
A []interface{}
}
return test{
target: &doc{},
expected: &doc{A: []interface{}{"0", "1", "2", "3", "4", "5", "6",
"7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17"}},
}
},
},
{
desc: "standard table",
input: `[A]