Skip to content

Commit

Permalink
Move import mapper test into main test
Browse files Browse the repository at this point in the history
  • Loading branch information
spinillos committed Apr 20, 2023
1 parent ea7b68c commit 26527fd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
24 changes: 16 additions & 8 deletions generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,14 @@ func TestGenerateWithImports(t *testing.T) {
ToDo: map[string]string{
"imports/oneref_verbose": "Figure out how to disambiguate struct literals from the struct-with-braces-and-one-element case",
},
ImportMappers: map[string]func(string) (string, error){
"imports/imports": func(s string) (string, error) {
if s == "example.com/dep" {
return "@example/deps", nil
}
return s, nil
},
}

importMappers := map[string]func(s string) (string, error){
"imports/imports": func(s string) (string, error) {
if s == "example.com/dep" {
return "@example/deps", nil
}
return s, nil
},
}

Expand All @@ -64,9 +65,16 @@ func TestGenerateWithImports(t *testing.T) {
t.Fatal(v.Err())
}

im := func(s string) (string, error) {
return "", nil
}
if i, ok := importMappers[t.Name]; ok {
im = i
}

b, err := cuetsy.Generate(v, cuetsy.Config{
Export: true,
ImportMapper: t.ImportMapperFn,
ImportMapper: im,
})
if err != nil {
errors.Print(t, err, nil)
Expand Down
13 changes: 2 additions & 11 deletions internal/cuetxtar/cuetxtar.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ type TxTarTest struct {

// ToDo is a map of tests that should be skipped now, but should be fixed.
ToDo map[string]string

ImportMappers map[string]func(string) (string, error)
}

// A Test represents a single test based on a .txtar file.
Expand All @@ -86,7 +84,7 @@ type Test struct {

hasGold bool

ImportMapperFn func(s string) (string, error)
Name string
}

func (t *Test) Write(b []byte) (n int, err error) {
Expand Down Expand Up @@ -270,6 +268,7 @@ func (x *TxTarTest) Run(t *testing.T, f func(tc *Test)) {
T: t,
Archive: a,
Dir: filepath.Dir(filepath.Join(dir, fullpath)),
Name: testName,

prefix: path.Join("out", x.Name),
}
Expand All @@ -292,14 +291,6 @@ func (x *TxTarTest) Run(t *testing.T, f func(tc *Test)) {
t.Skip(msg)
}

if im, ok := x.ImportMappers[testName]; ok {
tc.ImportMapperFn = im
} else {
tc.ImportMapperFn = func(s string) (string, error) {
return "", nil
}
}

f(tc)

update := false
Expand Down

0 comments on commit 26527fd

Please sign in to comment.