@@ -276,3 +276,60 @@ func TestParser_Null(t *testing.T) {
276276 })
277277 }
278278}
279+
280+ type exportable struct {
281+ export func () any
282+ }
283+
284+ func (e * exportable ) Export () any {
285+ return e .export ()
286+ }
287+
288+ func TestParser_Exportable (t * testing.T ) {
289+ testcases := []struct {
290+ name string
291+ data interface {}
292+ schema * schema.Schema
293+ test func (t * testing.T , v interface {}, err error )
294+ }{
295+ {
296+ name : "schema integer" ,
297+ data : & exportable {export : func () any { return 123 }},
298+ schema : schematest .New ("integer" ),
299+ test : func (t * testing.T , v interface {}, err error ) {
300+ require .NoError (t , err )
301+ require .Equal (t , int64 (123 ), v )
302+ },
303+ },
304+ {
305+ name : "no schema" ,
306+ data : & exportable {export : func () any { return 123 }},
307+ schema : nil ,
308+ test : func (t * testing.T , v interface {}, err error ) {
309+ require .NoError (t , err )
310+ require .Equal (t , 123 , v )
311+ },
312+ },
313+ {
314+ name : "exportable as additional property" ,
315+ data : map [string ]interface {}{"foo" : & exportable {export : func () any { return 123 }}},
316+ schema : schematest .New ("object" ),
317+ test : func (t * testing.T , v interface {}, err error ) {
318+ require .NoError (t , err )
319+ require .Equal (t , map [string ]any {"foo" : 123 }, v )
320+ },
321+ },
322+ }
323+
324+ t .Parallel ()
325+ for _ , tc := range testcases {
326+ tc := tc
327+ t .Run (tc .name , func (t * testing.T ) {
328+ t .Parallel ()
329+
330+ p := & parser.Parser {Schema : tc .schema }
331+ v , err := p .Parse (tc .data )
332+ tc .test (t , v , err )
333+ })
334+ }
335+ }
0 commit comments