Skip to content

Commit

Permalink
mod/module: add more tests
Browse files Browse the repository at this point in the history
These tests expose some issues with `module.ImportPath`
that will be fixed in the next CL in this chain.

For #3155

Signed-off-by: Roger Peppe <rogpeppe@gmail.com>
Change-Id: Ieb04af53153957d8435ca59c52fcdb1830922ce4
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1195278
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
  • Loading branch information
rogpeppe authored and mvdan committed May 28, 2024
1 parent d187b40 commit b88cfcf
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions mod/module/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,46 @@ var parseImportPathTests = []struct {
Qualifier: "bar",
},
wantCanonical: "foo.com/bar@v0",
}, {
testName: "WithPattern",
path: "foo.com/bar/.../blah",
want: ImportPath{
Path: "foo.com/bar/.../blah",
Version: "",
ExplicitQualifier: false,
Qualifier: "blah",
},
wantCanonical: "foo.com/bar/.../blah",
}, {
testName: "WithPatternAtEnd",
path: "foo.com/bar/...",
want: ImportPath{
Path: "foo.com/bar/...",
Version: "",
ExplicitQualifier: false,
Qualifier: "...",
},
wantCanonical: "foo.com/bar/...",
}, {
testName: "WithUnderscoreLastElement",
path: "foo.com/bar/_foo",
want: ImportPath{
Path: "foo.com/bar/_foo",
Version: "",
ExplicitQualifier: false,
Qualifier: "_foo",
},
wantCanonical: "foo.com/bar/_foo",
}, {
testName: "WithHashLastElement",
path: "foo.com/bar/#foo",
want: ImportPath{
Path: "foo.com/bar/#foo",
Version: "",
ExplicitQualifier: false,
Qualifier: "#foo",
},
wantCanonical: "foo.com/bar/#foo",
}}

func TestParseImportPath(t *testing.T) {
Expand All @@ -313,3 +353,11 @@ func TestImportPathStringAddsQualifier(t *testing.T) {
}
qt.Assert(t, qt.Equals(ip.String(), "foo.com/bar@v0:baz"))
}

func TestImportPathStringAddsQualifierWhenNoVersion(t *testing.T) {
ip := ImportPath{
Path: "foo.com/bar",
Qualifier: "baz",
}
qt.Assert(t, qt.Equals(ip.String(), "foo.com/bar"))
}

0 comments on commit b88cfcf

Please sign in to comment.