// Copyright 2024 Matthew Rich . All rights reserved. package fan import ( "github.com/stretchr/testify/assert" "testing" "decl/internal/codec" "decl/internal/folio" "decl/internal/data" "net/url" ) func TestNewJxSource(t *testing.T) { s := NewJxFile() assert.NotNil(t, s) } func TestJxSetURI(t *testing.T) { for _,v := range []struct{ url string; expectedformat codec.Format; expecteduri string }{ { url: "file://foo", expectedformat: codec.FormatYaml, expecteduri: "file://foo" }, { url: "json://foo", expectedformat: codec.FormatJson, expecteduri: "file://foo?format=json" }, { url: "yaml://foo", expectedformat: codec.FormatYaml, expecteduri: "file://foo?format=yaml" }, { url: "file://foo?format=json", expectedformat: codec.FormatJson, expecteduri: "file://foo?format=json" }, { url: "file://foo.jx.json", expectedformat: codec.FormatJson, expecteduri: "file://foo.jx.json" }, { url: "file://foo.jx.json.gz", expectedformat: codec.FormatJson, expecteduri: "file://foo.jx.json.gz" }, { url: "https://foo.jx.json.gz", expectedformat: codec.FormatJson, expecteduri: "https://foo.jx.json.gz" }, } { j := NewJxFile() assert.NotNil(t, j) u,_ := url.Parse(v.url) j.SetURI(u) assert.Equal(t, v.expectedformat, j.Format) assert.Equal(t, v.expecteduri, string(j.Uri)) } } func TestJxFactory(t *testing.T) { converter, err := folio.DocumentRegistry.ConverterTypes.New("json://-") assert.Nil(t, err) assert.NotNil(t, converter) assert.Equal(t, data.TypeName("jx"), converter.Type()) jxfile := converter.(*JxFile) assert.Equal(t, "-", jxfile.Path) assert.Equal(t, codec.FormatJson, jxfile.Format) }