MCPcopy Index your code
hub / github.com/coder/guts / TestGeneration

Function TestGeneration

convert_test.go:62–169  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

60var updateGoldenFiles = flag.Bool("update", false, "Update golden files")
61
62func TestGeneration(t *testing.T) {
63 t.Parallel()
64 files, err := os.ReadDir("testdata")
65 require.NoError(t, err, "read dir")
66
67 for _, f := range files {
68 if !f.IsDir() {
69 // Only test directories
70 continue
71 }
72 f := f
73 t.Run(f.Name(), func(t *testing.T) {
74 t.Parallel()
75
76 gen, err := guts.NewGolangParser()
77 require.NoError(t, err, "new convert")
78
79 // PreserveComments will attach golang comments to the typescript nodes.
80 gen.PreserveComments()
81
82 dir := filepath.Join(".", "testdata", f.Name())
83 err = gen.IncludeGenerate("./" + dir)
84 require.NoErrorf(t, err, "include %q", dir)
85
86 switch dir {
87 case "testdata/anyreference":
88 err = gen.IncludeReference("github.com/coder/guts/testdata/prefix", "Prefix")
89 require.NoErrorf(t, err, "include %q", dir)
90 case "testdata/excludecustom":
91 err = gen.ExcludeCustom("github.com/coder/guts/testdata/excludecustom.Secret")
92 require.NoErrorf(t, err, "exclude %q", dir)
93 case "testdata/alias":
94 err = gen.IncludeCustom(map[guts.GolangType]guts.GolangType{
95 "github.com/coder/guts/testdata/alias.RemappedAlias": "string",
96 })
97 require.NoError(t, err)
98 }
99
100 gen.IncludeCustomDeclaration(config.StandardMappings())
101
102 ts, err := gen.ToTypescript()
103 require.NoError(t, err, "to typescript")
104
105 mutations := []guts.MutationFunc{
106 config.EnumAsTypes,
107 config.EnumLists,
108 config.ExportTypes,
109 config.ReadOnly,
110 config.NullUnionSlices,
111 }
112
113 mutsCSV, err := os.ReadFile(filepath.Join(dir, "mutations"))
114 if err == nil {
115 mutations = make([]guts.MutationFunc, 0)
116 // load specific mutations
117 muts := strings.Split(strings.TrimSpace(string(mutsCSV)), ",")
118 for _, m := range muts {
119 switch m {

Callers

nothing calls this directly

Calls 11

NewGolangParserFunction · 0.92
StandardMappingsFunction · 0.92
PreserveCommentsMethod · 0.80
IncludeGenerateMethod · 0.80
IncludeReferenceMethod · 0.80
ExcludeCustomMethod · 0.80
IncludeCustomMethod · 0.80
ToTypescriptMethod · 0.80
ApplyMutationsMethod · 0.80
SerializeMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…