Skip to content

Commit

Permalink
internal/fetch: add generics test
Browse files Browse the repository at this point in the history
For golang/go#48264

Change-Id: I94b1bae5b2a59753492148edf2e1f2931235802f
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/382976
Trust: Jonathan Amsterdam <[email protected]>
Run-TryBot: Jonathan Amsterdam <[email protected]>
Reviewed-by: Jamal Carvalho <[email protected]>
TryBot-Result: kokoro <[email protected]>
  • Loading branch information
jba committed Feb 4, 2022
1 parent fa3d909 commit 6e78612
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 0 deletions.
1 change: 1 addition & 0 deletions internal/fetch/fetch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ func TestFetchModule(t *testing.T) {
{name: "type example", mod: moduleTypeExample},
{name: "method example", mod: moduleMethodExample},
{name: "nonredistributable packages", mod: moduleNonRedist},
{name: "generics", mod: moduleGenerics},
// Proxy only as stdlib is not accounted for in local mode
{name: "stdlib module", mod: moduleStd, proxyOnly: true},
// Proxy only as version is pre specified in local mode
Expand Down
66 changes: 66 additions & 0 deletions internal/fetch/fetchdata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2810,6 +2810,72 @@ var moduleLatest = &testModule{
},
}

var moduleGenerics = &testModule{
modfunc: func() *proxytest.Module { return proxytest.FindModule(testModules, "example.com/generics", "") },
fr: &FetchResult{
HasGoMod: true,
Module: &internal.Module{
ModuleInfo: internal.ModuleInfo{
ModulePath: "example.com/generics",
HasGoMod: true,
SourceInfo: source.NewGitHubInfo("https://example.com/generics", "", "v1.0.0"),
IsRedistributable: true,
},
Units: []*internal.Unit{
{
UnitMeta: internal.UnitMeta{
Name: "generics",
Path: "example.com/generics",
},
Documentation: []*internal.Documentation{
{
GOOS: internal.All,
GOARCH: internal.All,
Synopsis: "Package generics uses generics.",
API: []*internal.Symbol{
{
SymbolMeta: internal.SymbolMeta{
Name: "Min",
Synopsis: "func Min(a, b T) T",
Section: "Functions",
Kind: "Function",
},
},
{
SymbolMeta: internal.SymbolMeta{
Name: "List",
Synopsis: "type List struct{ ... }",
Section: "Types",
Kind: "Type",
},
Children: []*internal.SymbolMeta{
{
Name: "List.Val",
Synopsis: "Val T",
Section: "Types",
Kind: "Field",
ParentName: "List",
},
{
Name: "List.Next",
Synopsis: "Next *List[T]",
Section: "Types",
Kind: "Field",
ParentName: "List",
},
},
},
},
},
},
BuildContexts: []internal.BuildContext{internal.BuildContextAll},
Imports: []string{"constraints"},
},
},
},
},
}

// moduleWithExamples returns a testModule that contains an example.
// It provides the common bits for the tests for package, function,
// type, and method examples below.
Expand Down
29 changes: 29 additions & 0 deletions internal/proxy/testdata/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
A module that uses generics.

-- go.mod --
module example.com/generics

go 1.18

-- LICENSE --
$MITLicense

-- file.go --

// Package generics uses generics.
package generics

import "constraints"

func Min[T constraints.Ordered](a, b T) T {
if a < b {
return a
}
return b
}

type List[T any] struct {
Val T
Next *List[T]
}

0 comments on commit 6e78612

Please sign in to comment.