@@ -145,6 +145,87 @@ func TestCodecRabin(t *testing.T) {
145145 }
146146}
147147
148+ func TestTypeName (t * testing.T ) {
149+ cases := []struct {
150+ Schema string
151+ expectedFullName string
152+ expectedNamespace string
153+ }{
154+ {
155+ Schema : `"null"` ,
156+ expectedFullName : "null" ,
157+ expectedNamespace : "" ,
158+ },
159+ {
160+ Schema : `"boolean"` ,
161+ expectedFullName : "boolean" ,
162+ expectedNamespace : "" ,
163+ },
164+ {
165+ Schema : `"int"` ,
166+ expectedFullName : "int" ,
167+ expectedNamespace : "" ,
168+ },
169+ {
170+ Schema : `"long"` ,
171+ expectedFullName : "long" ,
172+ expectedNamespace : "" ,
173+ },
174+ {
175+ Schema : `"float"` ,
176+ expectedFullName : "float" ,
177+ expectedNamespace : "" ,
178+ },
179+ {
180+ Schema : `[ "int" ]` ,
181+ expectedFullName : "union" ,
182+ expectedNamespace : "" ,
183+ },
184+ {
185+ Schema : `[ "int" , {"type":"boolean"} ]` ,
186+ expectedFullName : "union" ,
187+ expectedNamespace : "" ,
188+ },
189+ {
190+ Schema : `{"fields":[], "type":"record", "name":"foo"}` ,
191+ expectedFullName : "foo" ,
192+ expectedNamespace : "" ,
193+ },
194+ {
195+ Schema : `{"type":"enum", "name":"foo", "symbols":["A1"]}` ,
196+ expectedFullName : "foo" ,
197+ expectedNamespace : "" ,
198+ },
199+ {
200+ Schema : `{"name":"foo","type":"fixed","size":15}` ,
201+ expectedFullName : "foo" ,
202+ expectedNamespace : "" ,
203+ },
204+ {
205+ Schema : `{"fields":[], "type":"record", "name":"foo", "namespace":"x.y"}` ,
206+ expectedFullName : "foo" ,
207+ expectedNamespace : "x.y" ,
208+ },
209+ {
210+ Schema : `{"namespace":"x.y.z", "type":"enum", "name":"foo", "doc":"foo bar", "symbols":["A1", "A2"]}` ,
211+ expectedFullName : "foo" ,
212+ expectedNamespace : "x.y.z" ,
213+ },
214+ }
215+
216+ for _ , c := range cases {
217+ codec , err := NewCodec (c .Schema )
218+ if err != nil {
219+ t .Fatalf ("CASE: %s; cannot create codec: %s" , c .Schema , err )
220+ }
221+ typeName := codec .TypeName ()
222+ expected , _ := newName (c .expectedFullName , c .expectedNamespace , "" )
223+ if typeName != * expected {
224+ t .Errorf ("CASE: %s; GOT: %s; WANT: %s" , c .Schema , codec .TypeName (), * expected )
225+ }
226+ }
227+ }
228+
148229func TestSingleObjectEncoding (t * testing.T ) {
149230 t .Run ("int" , func (* testing.T ) {
150231 schema := `"int"`
0 commit comments