-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #188 from grafana/use-proper-schema-value
Use _#schema to generate TS files
- Loading branch information
Showing
29 changed files
with
422 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package typescript | ||
|
||
import ( | ||
"github.com/stretchr/testify/require" | ||
"testing" | ||
|
||
"cuelang.org/go/cue/cuecontext" | ||
"github.com/grafana/thema" | ||
"github.com/grafana/thema/internal/txtartest/bindlin" | ||
"github.com/grafana/thema/internal/txtartest/vanilla" | ||
) | ||
|
||
func TestGenerate(t *testing.T) { | ||
test := vanilla.TxTarTest{ | ||
Root: "../../testdata/lineage", | ||
Name: "encoding/typescript/TestGenerate", | ||
ThemaFS: thema.CueJointFS, | ||
Skip: map[string]string{ | ||
"lineage/refexscalar": "bounds constraints are not supported as they lack a direct typescript equivalent", | ||
"lineage/refscalar": "bounds constraints are not supported as they lack a direct typescript equivalent", | ||
}, | ||
} | ||
|
||
ctx := cuecontext.New() | ||
rt := thema.NewRuntime(ctx) | ||
|
||
table := []struct { | ||
name string | ||
cfg *TypeConfig | ||
}{ | ||
{ | ||
name: "nilcfg", | ||
cfg: nil, | ||
}, | ||
} | ||
|
||
for _, tb := range table { | ||
t.Run(tb.name, func(t *testing.T) { | ||
testcpy := test | ||
testcpy.Name += "/" + tb.name | ||
testcpy.Run(t, func(tc *vanilla.Test) { | ||
if testing.Short() && tc.HasTag("slow") { | ||
t.Skip("case is tagged #slow, skipping for -short") | ||
} | ||
lin, err := bindlin.BindTxtarLineage(tc, rt) | ||
if err != nil { | ||
tc.Fatal(err) | ||
} | ||
|
||
for sch := lin.First(); sch != nil; sch = sch.Successor() { | ||
f, err := GenerateTypes(sch, tb.cfg) | ||
if err != nil { | ||
tc.Fatal(err) | ||
} | ||
_, err = tc.Write([]byte(f.String())) //nolint:gosec,errcheck | ||
require.NoError(t, err) | ||
} | ||
}) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.