Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit test for methods with generic receivers
- Loading branch information
Showing
2 changed files
with
53 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
//go:build go1.18 | ||
// +build go1.18 | ||
|
||
package gocognit_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/uudashr/gocognit" | ||
"golang.org/x/tools/go/analysis/analysistest" | ||
) | ||
|
||
func TestAnalyzer_Generics(t *testing.T) { | ||
testdata := analysistest.TestData() | ||
gocognit.Analyzer.Flags.Set("over", "0") | ||
analysistest.Run(t, testdata, gocognit.Analyzer, "c") | ||
} |
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,36 @@ | ||
package testdata | ||
|
||
type Node[T any] struct { | ||
} | ||
|
||
func (n *Node[T]) String() string { // want "cognitive complexity 1 of func \\(\\*Node\\[T\\]\\)\\.String is high \\(> 0\\)" | ||
if n != nil { // +1 | ||
return "Node" | ||
} | ||
|
||
return "" | ||
} // total complexity = 1 | ||
|
||
type Pair[K any, V any] struct { | ||
Key K | ||
Value V | ||
} | ||
|
||
func (p *Pair[K, V]) String() string { // want "cognitive complexity 1 of func \\(\\*Pair\\[K, V\\]\\)\\.String is high \\(> 0\\)" | ||
if p != nil { // +1 | ||
return "Pair" | ||
} | ||
|
||
return "" | ||
} // total complexity = 1 | ||
|
||
type Triple[K any, V any, T any] struct { | ||
} | ||
|
||
func (t *Triple[K, V, T]) String() string { // want "cognitive complexity 1 of func \\(\\*Triple\\[K, V, T\\]\\)\\.String is high \\(> 0\\)" | ||
if t != nil { // +1 ` | ||
return "Triple" | ||
} | ||
|
||
return "" | ||
} // total complexity = 1 |