-
Notifications
You must be signed in to change notification settings - Fork 77
/
type_test.go
83 lines (74 loc) · 1.69 KB
/
type_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Copyright 2020 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package licensecheck
import "testing"
func TestTypeString(t *testing.T) {
for _, b := range typeBits {
s := b.t.String()
if s != b.s {
t.Errorf("%s.String() = %q, want %q", b.s, s, b.s)
}
}
numError := 0
for typ := Type(0); typ < Discouraged+100; typ++ {
s := typ.String()
ptyp, err := ParseType(s)
if err != nil {
t.Errorf("Type(%#x).String = %q; ParseType(...): %v", uint(typ), s, err)
if numError++; numError > 20 {
t.FailNow()
}
continue
}
if ptyp != typ {
t.Errorf("Type(%#x).String = %q; ParseType(...) = %#x", uint(typ), s, uint(ptyp))
if numError++; numError > 20 {
t.FailNow()
}
continue
}
}
}
var typeMergeTests = []struct {
t, u Type
out Type
}{
{Unknown, Notice, Unknown},
{Unknown, NonCommercial, Unknown},
{Unknown, Discouraged, Unknown},
{Notice, NonCommercial, Notice | NonCommercial},
{Notice, ShareProgram, ShareProgram},
}
func TestTypeMerge(t *testing.T) {
for _, tt := range typeMergeTests {
if out := tt.t.Merge(tt.u); out != tt.out {
t.Errorf("(%v).Merge(%v) = %v, want %v", tt.t, tt.u, out, tt.out)
}
}
}
func licenseType(id string) Type {
for _, l := range builtinLREs {
if l.ID == id {
return l.Type
}
}
return Unknown
}
var licenseTypeTests = map[string]Type{
"WTFPL": Discouraged,
}
func TestLicenseType(t *testing.T) {
for _, l := range BuiltinLicenses() {
typ, ok := licenseTypeTests[l.ID]
if !ok {
typ = Unknown
}
if l.Type != typ {
if l.LRE != "" {
l.LRE = "..."
}
t.Errorf("License%+v: expected Type:%v", l, typ)
}
}
}