| 1 | package spdxexpscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/ |
| 2 | |
| 3 | import ( |
| 4 | "errorsscip-go gomod github.com/golang/go/src go1.24 errors/" |
| 5 | "testingscip-go gomod github.com/golang/go/src go1.24 testing/" |
| 6 | |
| 7 | "github.com/stretchr/testify/assertscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/" |
| 8 | "github.com/stretchr/testify/requirescip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/require`/" |
| 9 | ) |
| 10 | |
| 11 | func TestScanscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/TestScan().(t *testingscip-go gomod github.com/golang/go/src go1.24 testing/.Tscip-go gomod github.com/golang/go/src go1.24 testing/T#) { |
| 12 | tests := []struct { |
| 13 | name string |
| 14 | expression string |
| 15 | tokens []tokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token# |
| 16 | err error |
| 17 | }{ |
| 18 | {"single license", "MIT", |
| 19 | []tokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#{ |
| 20 | {rolescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#role.: licenseTokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/licenseToken., valuescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#value.: "MIT"}, |
| 21 | }, nil}, |
| 22 | {"single license - diff case", "mit", |
| 23 | []tokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#{ |
| 24 | {rolescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#role.: licenseTokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/licenseToken., valuescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#value.: "MIT"}, |
| 25 | }, nil}, |
| 26 | {"empty expression", "", []tokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#(nil), nil}, |
| 27 | {"invalid license", "NON-EXISTENT-LICENSE", []tokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#(nil), |
| 28 | errorsscip-go gomod github.com/golang/go/src go1.24 errors/.Newscip-go gomod github.com/golang/go/src go1.24 errors/New().("unknown license 'NON-EXISTENT-LICENSE' at offset 0")}, |
| 29 | {"two licenses using AND", "MIT AND Apache-2.0", |
| 30 | []tokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#{ |
| 31 | {rolescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#role.: licenseTokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/licenseToken., valuescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#value.: "MIT"}, |
| 32 | {rolescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#role.: operatorTokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/operatorToken., valuescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#value.: "AND"}, |
| 33 | {rolescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#role.: licenseTokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/licenseToken., valuescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#value.: "Apache-2.0"}, |
| 34 | }, nil}, |
| 35 | {"two licenses using OR inside paren", "(MIT OR Apache-2.0)", |
| 36 | []tokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#{ |
| 37 | {rolescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#role.: operatorTokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/operatorToken., valuescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#value.: "("}, |
| 38 | {rolescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#role.: licenseTokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/licenseToken., valuescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#value.: "MIT"}, |
| 39 | {rolescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#role.: operatorTokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/operatorToken., valuescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#value.: "OR"}, |
| 40 | {rolescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#role.: licenseTokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/licenseToken., valuescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#value.: "Apache-2.0"}, |
| 41 | {rolescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#role.: operatorTokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/operatorToken., valuescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#value.: ")"}, |
| 42 | }, nil}, |
| 43 | {"kitchen sink", " (MIT AND Apache-1.0+) OR DocumentRef-spdx-tool-1.2:LicenseRef-MIT-Style-2 OR (GPL-2.0 WITH Bison-exception-2.2)", |
| 44 | []tokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#{ |
| 45 | {rolescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#role.: operatorTokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/operatorToken., valuescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#value.: "("}, |
| 46 | {rolescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#role.: licenseTokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/licenseToken., valuescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#value.: "MIT"}, |
| 47 | {rolescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#role.: operatorTokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/operatorToken., valuescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#value.: "AND"}, |
| 48 | {rolescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#role.: licenseTokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/licenseToken., valuescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#value.: "Apache-1.0"}, |
| 49 | {rolescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#role.: operatorTokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/operatorToken., valuescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#value.: "+"}, |
| 50 | {rolescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#role.: operatorTokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/operatorToken., valuescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#value.: ")"}, |
| 51 | {rolescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#role.: operatorTokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/operatorToken., valuescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#value.: "OR"}, |
| 52 | {rolescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#role.: documentRefTokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/documentRefToken., valuescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#value.: "spdx-tool-1.2"}, |
| 53 | {rolescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#role.: operatorTokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/operatorToken., valuescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#value.: ":"}, |
| 54 | {rolescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#role.: licenseRefTokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/licenseRefToken., valuescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#value.: "MIT-Style-2"}, |
| 55 | {rolescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#role.: operatorTokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/operatorToken., valuescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#value.: "OR"}, |
| 56 | {rolescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#role.: operatorTokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/operatorToken., valuescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#value.: "("}, |
| 57 | {rolescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#role.: licenseTokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/licenseToken., valuescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#value.: "GPL-2.0"}, |
| 58 | {rolescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#role.: operatorTokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/operatorToken., valuescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#value.: "WITH"}, |
| 59 | {rolescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#role.: exceptionTokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/exceptionToken., valuescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#value.: "Bison-exception-2.2"}, |
| 60 | {rolescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#role.: operatorTokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/operatorToken., valuescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#value.: ")"}, |
| 61 | }, nil}, |
| 62 | } |
| 63 | |
| 64 | for _, test := range tests { |
| 65 | test := test |
| 66 | t.Runscip-go gomod github.com/golang/go/src go1.24 testing/T#Run().(test.name, func(t *testingscip-go gomod github.com/golang/go/src go1.24 testing/.Tscip-go gomod github.com/golang/go/src go1.24 testing/T#) { |
| 67 | tokens, err := scanscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/scan().(test.expression) |
| 68 | |
| 69 | requirescip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/require`/Equal().(t, test.err, err) |
| 70 | assertscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/Equal().(t, test.tokens, tokens) |
| 71 | }) |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | func TestHasMoreSourcescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/TestHasMoreSource().(t *testingscip-go gomod github.com/golang/go/src go1.24 testing/.Tscip-go gomod github.com/golang/go/src go1.24 testing/T#) { |
| 76 | tests := []struct { |
| 77 | name string |
| 78 | exp *expressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream# |
| 79 | result bool |
| 80 | }{ |
| 81 | {"at start", getExpressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/getExpressionStream().("MIT OR Apache-2.0", 0), true}, |
| 82 | {"at middle", getExpressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/getExpressionStream().("MIT OR Apache-2.0", 3), true}, |
| 83 | {"at end", getExpressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/getExpressionStream().("MIT OR Apache-2.0", len("MIT OR Apache-2.0")), false}, |
| 84 | {"past end", getExpressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/getExpressionStream().("MIT OR Apache-2.0", 50), false}, |
| 85 | } |
| 86 | |
| 87 | for _, test := range tests { |
| 88 | test := test |
| 89 | t.Runscip-go gomod github.com/golang/go/src go1.24 testing/T#Run().(test.name, func(t *testingscip-go gomod github.com/golang/go/src go1.24 testing/.Tscip-go gomod github.com/golang/go/src go1.24 testing/T#) { |
| 90 | assertscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/Equal().(t, test.result, test.exp.hasMorescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#hasMore().()) |
| 91 | }) |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | func TestParseTokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/TestParseToken().(t *testingscip-go gomod github.com/golang/go/src go1.24 testing/.Tscip-go gomod github.com/golang/go/src go1.24 testing/T#) { |
| 96 | tests := []struct { |
| 97 | name string |
| 98 | exp *expressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream# |
| 99 | token *tokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token# |
| 100 | newIndex int |
| 101 | err error |
| 102 | }{ |
| 103 | {"operator found", getExpressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/getExpressionStream().("MIT AND Apache-2.0", 4), |
| 104 | &tokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#{rolescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#role.: operatorTokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/operatorToken., valuescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#value.: "AND"}, 7, nil}, |
| 105 | {"operator error", getExpressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/getExpressionStream().("Apache-1.0 + OR MIT", 11), |
| 106 | nil, 11, errorsscip-go gomod github.com/golang/go/src go1.24 errors/.Newscip-go gomod github.com/golang/go/src go1.24 errors/New().("unexpected space before +")}, |
| 107 | {"document ref found", getExpressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/getExpressionStream().("DocumentRef-spdx-tool-1.2:LicenseRef-MIT-Style-2", 0), |
| 108 | &tokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#{rolescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#role.: documentRefTokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/documentRefToken., valuescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#value.: "spdx-tool-1.2"}, 25, nil}, |
| 109 | {"document ref error", getExpressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/getExpressionStream().("DocumentRef-!23", 0), |
| 110 | nil, 12, errorsscip-go gomod github.com/golang/go/src go1.24 errors/.Newscip-go gomod github.com/golang/go/src go1.24 errors/New().("expected id at offset 12")}, |
| 111 | {"license ref found", getExpressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/getExpressionStream().("DocumentRef-spdx-tool-1.2:LicenseRef-MIT-Style-2", 26), |
| 112 | &tokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#{rolescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#role.: licenseRefTokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/licenseRefToken., valuescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#value.: "MIT-Style-2"}, 48, nil}, |
| 113 | {"license ref error", getExpressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/getExpressionStream().("LicenseRef-!23", 0), |
| 114 | nil, 11, errorsscip-go gomod github.com/golang/go/src go1.24 errors/.Newscip-go gomod github.com/golang/go/src go1.24 errors/New().("expected id at offset 11")}, |
| 115 | {"identifier found", getExpressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/getExpressionStream().("MIT AND Apache-2.0", 8), |
| 116 | &tokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#{rolescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#role.: licenseTokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/licenseToken., valuescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#value.: "Apache-2.0"}, 18, nil}, |
| 117 | {"identifier error", getExpressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/getExpressionStream().("NON-EXISTENT-LICENSE", 0), |
| 118 | nil, 0, errorsscip-go gomod github.com/golang/go/src go1.24 errors/.Newscip-go gomod github.com/golang/go/src go1.24 errors/New().("unknown license 'NON-EXISTENT-LICENSE' at offset 0")}, |
| 119 | } |
| 120 | |
| 121 | for _, test := range tests { |
| 122 | test := test |
| 123 | t.Runscip-go gomod github.com/golang/go/src go1.24 testing/T#Run().(test.name, func(t *testingscip-go gomod github.com/golang/go/src go1.24 testing/.Tscip-go gomod github.com/golang/go/src go1.24 testing/T#) { |
| 124 | tokn := test.exp.parseTokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#parseToken().() |
| 125 | assertscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/Equal().(t, test.newIndex, test.exp.indexscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#index.) |
| 126 | |
| 127 | requirescip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/require`/Equal().(t, test.err, test.exp.errscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#err.) |
| 128 | if test.err != nil { |
| 129 | // token is nil when error occurs or token is not recognized |
| 130 | var nilToken *tokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token# |
| 131 | assertscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/Equal().(t, nilToken, tokn) |
| 132 | return |
| 133 | } |
| 134 | |
| 135 | // token recognized, check token value |
| 136 | assertscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/Equal().(t, test.token, tokn) |
| 137 | }) |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | func TestReadRegexscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/TestReadRegex().(t *testingscip-go gomod github.com/golang/go/src go1.24 testing/.Tscip-go gomod github.com/golang/go/src go1.24 testing/T#) { |
| 142 | tests := []struct { |
| 143 | name string |
| 144 | exp *expressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream# |
| 145 | pattern string |
| 146 | match string |
| 147 | newIndex int |
| 148 | }{ |
| 149 | {"regex to skip leading blank in middle", getExpressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/getExpressionStream().("MIT OR Apache-2.0", 3), |
| 150 | "[ ]*", " ", 4}, |
| 151 | {"regex for id", getExpressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/getExpressionStream().("LicenseRef-MIT-Style-1", 11), |
| 152 | "[A-Za-z0-9-.]+", "MIT-Style-1", 22}, |
| 153 | } |
| 154 | |
| 155 | for _, test := range tests { |
| 156 | test := test |
| 157 | t.Runscip-go gomod github.com/golang/go/src go1.24 testing/T#Run().(test.name, func(t *testingscip-go gomod github.com/golang/go/src go1.24 testing/.Tscip-go gomod github.com/golang/go/src go1.24 testing/T#) { |
| 158 | match := test.exp.readRegexscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#readRegex().(test.pattern) |
| 159 | assertscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/Equal().(t, test.match, match) |
| 160 | assertscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/Equal().(t, test.newIndex, test.exp.indexscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#index.) |
| 161 | }) |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | func TestReadscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/TestRead().(t *testingscip-go gomod github.com/golang/go/src go1.24 testing/.Tscip-go gomod github.com/golang/go/src go1.24 testing/T#) { |
| 166 | tests := []struct { |
| 167 | name string |
| 168 | exp *expressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream# |
| 169 | next string |
| 170 | match string |
| 171 | newIndex int |
| 172 | }{ |
| 173 | {"at first - match word", getExpressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/getExpressionStream().("MIT OR Apache-2.0", 0), "MIT", "MIT", 3}, |
| 174 | {"at middle - match operator", getExpressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/getExpressionStream().("MIT OR Apache-2.0", 4), "OR", "OR", 6}, |
| 175 | {"at middle - match last word", getExpressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/getExpressionStream().("MIT OR Apache-2.0", 7), "Apache-2.0", "Apache-2.0", 17}, |
| 176 | {"at first - no match", getExpressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/getExpressionStream().("MIT OR Apache-2.0", 0), "GPL", "", 0}, |
| 177 | {"at middle - no match for operator", getExpressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/getExpressionStream().("MIT OR Apache-2.0", 4), "AND", "", 4}, |
| 178 | {"at middle - no match last word", getExpressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/getExpressionStream().("MIT OR Apache-2.0", 7), "GPL", "", 7}, |
| 179 | } |
| 180 | |
| 181 | for _, test := range tests { |
| 182 | test := test |
| 183 | t.Runscip-go gomod github.com/golang/go/src go1.24 testing/T#Run().(test.name, func(t *testingscip-go gomod github.com/golang/go/src go1.24 testing/.Tscip-go gomod github.com/golang/go/src go1.24 testing/T#) { |
| 184 | match := test.exp.readscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#read().(test.next) |
| 185 | assertscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/Equal().(t, test.match, match) |
| 186 | assertscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/Equal().(t, test.newIndex, test.exp.indexscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#index.) |
| 187 | }) |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | func TestSkipWhitespacescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/TestSkipWhitespace().(t *testingscip-go gomod github.com/golang/go/src go1.24 testing/.Tscip-go gomod github.com/golang/go/src go1.24 testing/T#) { |
| 192 | tests := []struct { |
| 193 | name string |
| 194 | exp *expressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream# |
| 195 | newIndex int |
| 196 | }{ |
| 197 | {"at first - no blanks", getExpressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/getExpressionStream().("MIT OR Apache-2.0", 0), 0}, |
| 198 | {"at first - with blanks", getExpressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/getExpressionStream().(" MIT OR Apache-2 .0", 0), 2}, |
| 199 | {"at middle - no blanks", getExpressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/getExpressionStream().("MIT OR Apache-2.0", 4), 4}, |
| 200 | {"at middle - with blanks", getExpressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/getExpressionStream().("MIT OR Apache-2.0", 3), 4}, |
| 201 | {"at end - no blanks", getExpressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/getExpressionStream().("MIT OR GPL", 10), 10}, |
| 202 | {"at end - with blanks", getExpressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/getExpressionStream().("MIT OR GPL ", 10), 12}, |
| 203 | } |
| 204 | |
| 205 | for _, test := range tests { |
| 206 | test := test |
| 207 | t.Runscip-go gomod github.com/golang/go/src go1.24 testing/T#Run().(test.name, func(t *testingscip-go gomod github.com/golang/go/src go1.24 testing/.Tscip-go gomod github.com/golang/go/src go1.24 testing/T#) { |
| 208 | test.exp.skipWhitespacescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#skipWhitespace().() |
| 209 | assertscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/Equal().(t, test.newIndex, test.exp.indexscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#index.) |
| 210 | }) |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | func TestReadOperatorscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/TestReadOperator().(t *testingscip-go gomod github.com/golang/go/src go1.24 testing/.Tscip-go gomod github.com/golang/go/src go1.24 testing/T#) { |
| 215 | tests := []struct { |
| 216 | name string |
| 217 | exp *expressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream# |
| 218 | operator *tokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token# |
| 219 | newIndex int |
| 220 | err error |
| 221 | }{ |
| 222 | {"WITH operator", getExpressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/getExpressionStream().("MIT WITH Bison-exception-2.2", 4), |
| 223 | &tokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#{rolescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#role.: operatorTokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/operatorToken., valuescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#value.: "WITH"}, 8, nil}, |
| 224 | {"AND operator", getExpressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/getExpressionStream().("MIT AND Apache-2.0", 4), |
| 225 | &tokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#{rolescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#role.: operatorTokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/operatorToken., valuescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#value.: "AND"}, 7, nil}, |
| 226 | {"OR operator", getExpressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/getExpressionStream().("MIT OR Apache-2.0", 4), |
| 227 | &tokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#{rolescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#role.: operatorTokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/operatorToken., valuescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#value.: "OR"}, 6, nil}, |
| 228 | {"( operator", getExpressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/getExpressionStream().("(MIT OR Apache-2.0)", 0), |
| 229 | &tokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#{rolescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#role.: operatorTokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/operatorToken., valuescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#value.: "("}, 1, nil}, |
| 230 | {") operator", getExpressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/getExpressionStream().("(MIT OR Apache-2.0)", 18), |
| 231 | &tokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#{rolescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#role.: operatorTokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/operatorToken., valuescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#value.: ")"}, 19, nil}, |
| 232 | {": operator", getExpressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/getExpressionStream().("DocumentRef-spdx-tool-1.2:LicenseRef-MIT-Style-2", 25), |
| 233 | &tokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#{rolescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#role.: operatorTokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/operatorToken., valuescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#value.: ":"}, 26, nil}, |
| 234 | {"plus operator - correctly used", getExpressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/getExpressionStream().("Apache-1.0+ OR MIT", 10), |
| 235 | &tokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#{rolescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#role.: operatorTokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/operatorToken., valuescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#value.: "+"}, 11, nil}, |
| 236 | {"plus operator - with preceding space", getExpressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/getExpressionStream().("Apache-1.0 + OR MIT", 11), |
| 237 | nil, 11, errorsscip-go gomod github.com/golang/go/src go1.24 errors/.Newscip-go gomod github.com/golang/go/src go1.24 errors/New().("unexpected space before +")}, |
| 238 | {"operator not found", getExpressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/getExpressionStream().("MIT AND Apache-2.0", 8), |
| 239 | nil, 8, nil}, |
| 240 | } |
| 241 | |
| 242 | for _, test := range tests { |
| 243 | test := test |
| 244 | t.Runscip-go gomod github.com/golang/go/src go1.24 testing/T#Run().(test.name, func(t *testingscip-go gomod github.com/golang/go/src go1.24 testing/.Tscip-go gomod github.com/golang/go/src go1.24 testing/T#) { |
| 245 | operator := test.exp.readOperatorscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#readOperator().() |
| 246 | assertscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/Equal().(t, test.newIndex, test.exp.indexscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#index.) |
| 247 | requirescip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/require`/Equal().(t, test.err, test.exp.errscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#err.) |
| 248 | assertscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/Equal().(t, test.operator, operator) |
| 249 | }) |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | func TestReadIdscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/TestReadId().(t *testingscip-go gomod github.com/golang/go/src go1.24 testing/.Tscip-go gomod github.com/golang/go/src go1.24 testing/T#) { |
| 254 | tests := []struct { |
| 255 | name string |
| 256 | exp *expressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream# |
| 257 | id string |
| 258 | newIndex int |
| 259 | }{ |
| 260 | {"valid numeric id", getExpressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/getExpressionStream().("LicenseRef-23", 11), "23", 13}, |
| 261 | {"valid id with dashes", getExpressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/getExpressionStream().("LicenseRef-MIT-Style-1", 11), "MIT-Style-1", 22}, |
| 262 | {"valid id with period", getExpressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/getExpressionStream().("DocumentRef-spdx-tool-1.2:LicenseRef-MIT-Style-2", 12), "spdx-tool-1.2", 25}, |
| 263 | {"invalid starts with non-supported character", getExpressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/getExpressionStream().("LicenseRef-!23", 11), "", 11}, |
| 264 | {"invalid non-supported character in middle", getExpressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/getExpressionStream().("LicenseRef-2!3", 11), "2", 12}, |
| 265 | {"invalid ends with non-supported character", getExpressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/getExpressionStream().("LicenseRef-23!", 11), "23", 13}, |
| 266 | } |
| 267 | |
| 268 | for _, test := range tests { |
| 269 | test := test |
| 270 | t.Runscip-go gomod github.com/golang/go/src go1.24 testing/T#Run().(test.name, func(t *testingscip-go gomod github.com/golang/go/src go1.24 testing/.Tscip-go gomod github.com/golang/go/src go1.24 testing/T#) { |
| 271 | id := test.exp.readIDscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#readID().() |
| 272 | // check values if there isn't an error |
| 273 | assertscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/Equal().(t, test.id, id) |
| 274 | assertscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/Equal().(t, test.newIndex, test.exp.indexscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#index.) |
| 275 | }) |
| 276 | } |
| 277 | } |
| 278 | |
| 279 | func TestReadDocumentRefscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/TestReadDocumentRef().(t *testingscip-go gomod github.com/golang/go/src go1.24 testing/.Tscip-go gomod github.com/golang/go/src go1.24 testing/T#) { |
| 280 | tests := []struct { |
| 281 | name string |
| 282 | exp *expressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream# |
| 283 | ref *tokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token# |
| 284 | newIndex int |
| 285 | err error |
| 286 | }{ |
| 287 | {"valid document ref with id", getExpressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/getExpressionStream().("DocumentRef-spdx-tool-1.2:LicenseRef-MIT-Style-2", 0), &tokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#{rolescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#role.: documentRefTokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/documentRefToken., valuescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#value.: "spdx-tool-1.2"}, 25, nil}, |
| 288 | {"document ref not found", getExpressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/getExpressionStream().("DocumentRef-spdx-tool-1.2:LicenseRef-MIT-Style-2", 26), nil, 26, nil}, |
| 289 | {"invalid document ref with bad id", getExpressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/getExpressionStream().("DocumentRef-!23", 0), nil, 12, errorsscip-go gomod github.com/golang/go/src go1.24 errors/.Newscip-go gomod github.com/golang/go/src go1.24 errors/New().("expected id at offset 12")}, |
| 290 | } |
| 291 | |
| 292 | for _, test := range tests { |
| 293 | test := test |
| 294 | t.Runscip-go gomod github.com/golang/go/src go1.24 testing/T#Run().(test.name, func(t *testingscip-go gomod github.com/golang/go/src go1.24 testing/.Tscip-go gomod github.com/golang/go/src go1.24 testing/T#) { |
| 295 | ref := test.exp.readDocumentRefscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#readDocumentRef().() |
| 296 | assertscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/Equal().(t, test.newIndex, test.exp.indexscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#index.) |
| 297 | |
| 298 | requirescip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/require`/Equal().(t, test.err, test.exp.errscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#err.) |
| 299 | if test.err != nil { |
| 300 | // ref should be nil when error occurs or a ref is not found |
| 301 | var nilToken *tokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token# |
| 302 | assertscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/Equal().(t, nilToken, ref, "Expected nil token when error occurs.") |
| 303 | return |
| 304 | } |
| 305 | |
| 306 | // ref found, check ref value |
| 307 | assertscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/Equal().(t, test.ref, ref) |
| 308 | }) |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | func TestReadLicenseRefscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/TestReadLicenseRef().(t *testingscip-go gomod github.com/golang/go/src go1.24 testing/.Tscip-go gomod github.com/golang/go/src go1.24 testing/T#) { |
| 313 | tests := []struct { |
| 314 | name string |
| 315 | exp *expressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream# |
| 316 | ref *tokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token# |
| 317 | newIndex int |
| 318 | err error |
| 319 | }{ |
| 320 | {"valid license ref with id", getExpressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/getExpressionStream().("DocumentRef-spdx-tool-1.2:LicenseRef-MIT-Style-2", 26), &tokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#{rolescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#role.: licenseRefTokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/licenseRefToken., valuescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#value.: "MIT-Style-2"}, 48, nil}, |
| 321 | {"license ref not found", getExpressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/getExpressionStream().("DocumentRef-spdx-tool-1.2:LicenseRef-MIT-Style-2", 0), nil, 0, nil}, |
| 322 | {"invalid license ref with bad id", getExpressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/getExpressionStream().("LicenseRef-!23", 0), nil, 11, errorsscip-go gomod github.com/golang/go/src go1.24 errors/.Newscip-go gomod github.com/golang/go/src go1.24 errors/New().("expected id at offset 11")}, |
| 323 | } |
| 324 | |
| 325 | for _, test := range tests { |
| 326 | test := test |
| 327 | t.Runscip-go gomod github.com/golang/go/src go1.24 testing/T#Run().(test.name, func(t *testingscip-go gomod github.com/golang/go/src go1.24 testing/.Tscip-go gomod github.com/golang/go/src go1.24 testing/T#) { |
| 328 | ref := test.exp.readLicenseRefscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#readLicenseRef().() |
| 329 | assertscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/Equal().(t, test.newIndex, test.exp.indexscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#index.) |
| 330 | |
| 331 | requirescip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/require`/Equal().(t, test.err, test.exp.errscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#err.) |
| 332 | if test.err != nil { |
| 333 | // ref should be nil when error occurs or a ref is not found |
| 334 | var nilToken *tokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token# |
| 335 | assertscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/Equal().(t, nilToken, ref) |
| 336 | return |
| 337 | } |
| 338 | |
| 339 | // ref found, check ref value |
| 340 | assertscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/Equal().(t, test.ref, ref) |
| 341 | }) |
| 342 | } |
| 343 | } |
| 344 | |
| 345 | func TestReadLicensescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/TestReadLicense().(t *testingscip-go gomod github.com/golang/go/src go1.24 testing/.Tscip-go gomod github.com/golang/go/src go1.24 testing/T#) { |
| 346 | tests := []struct { |
| 347 | name string |
| 348 | exp *expressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream# |
| 349 | license *tokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token# |
| 350 | newExpression string |
| 351 | newIndex int |
| 352 | err error |
| 353 | }{ |
| 354 | {"active license", getExpressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/getExpressionStream().("MIT", 0), &tokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#{rolescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#role.: licenseTokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/licenseToken., valuescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#value.: "MIT"}, "MIT", 3, nil}, |
| 355 | {"active -or-later", getExpressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/getExpressionStream().("AGPL-1.0-or-later", 0), &tokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#{rolescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#role.: licenseTokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/licenseToken., valuescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#value.: "AGPL-1.0-or-later"}, "AGPL-1.0-or-later", 17, nil}, |
| 356 | {"active -or-later using +", getExpressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/getExpressionStream().("AGPL-1.0+", 0), &tokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#{rolescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#role.: licenseTokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/licenseToken., valuescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#value.: "AGPL-1.0-or-later"}, "AGPL-1.0+", 9, nil}, // no valid example for this; all that include -or-later have the base as a deprecated license |
| 357 | {"active -or-later not in list", getExpressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/getExpressionStream().("Apache-1.0-or-later", 0), &tokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#{rolescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#role.: licenseTokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/licenseToken., valuescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#value.: "Apache-1.0"}, "Apache-1.0+", 10, nil}, |
| 358 | {"active -only", getExpressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/getExpressionStream().("GPL-2.0-only", 0), &tokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#{rolescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#role.: licenseTokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/licenseToken., valuescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#value.: "GPL-2.0-only"}, "GPL-2.0-only", 12, nil}, |
| 359 | {"active -only not in list", getExpressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/getExpressionStream().("ECL-1.0-only", 0), &tokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#{rolescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#role.: licenseTokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/licenseToken., valuescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#value.: "ECL-1.0"}, "ECL-1.0-only", 12, nil}, |
| 360 | {"deprecated license", getExpressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/getExpressionStream().("LGPL-2.1", 0), &tokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#{rolescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#role.: licenseTokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/licenseToken., valuescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#value.: "LGPL-2.1"}, "LGPL-2.1", 8, nil}, |
| 361 | {"exception license", getExpressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/getExpressionStream().("GPL-CC-1.0", 0), &tokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#{rolescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#role.: exceptionTokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/exceptionToken., valuescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token#value.: "GPL-CC-1.0"}, "GPL-CC-1.0", 10, nil}, |
| 362 | {"invalid license", getExpressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/getExpressionStream().("NON-EXISTENT-LICENSE", 0), nil, "NON-EXISTENT-LICENSE", 0, errorsscip-go gomod github.com/golang/go/src go1.24 errors/.Newscip-go gomod github.com/golang/go/src go1.24 errors/New().("unknown license 'NON-EXISTENT-LICENSE' at offset 0")}, |
| 363 | } |
| 364 | |
| 365 | for _, test := range tests { |
| 366 | test := test |
| 367 | t.Runscip-go gomod github.com/golang/go/src go1.24 testing/T#Run().(test.name, func(t *testingscip-go gomod github.com/golang/go/src go1.24 testing/.Tscip-go gomod github.com/golang/go/src go1.24 testing/T#) { |
| 368 | license := test.exp.readLicensescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#readLicense().() |
| 369 | assertscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/Equal().(t, test.newIndex, test.exp.indexscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#index.) |
| 370 | |
| 371 | requirescip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/require`/Equal().(t, test.err, test.exp.errscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#err.) |
| 372 | if test.err != nil { |
| 373 | // license should be nil when error occurs or a license is not found |
| 374 | var nilToken *tokenscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/token# |
| 375 | assertscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/Equal().(t, nilToken, license) |
| 376 | return |
| 377 | } |
| 378 | |
| 379 | // license found, check license value |
| 380 | assertscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/Equal().(t, test.license, license) |
| 381 | assertscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/Equal().(t, test.newExpression, test.exp.expressionscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#expression.) |
| 382 | }) |
| 383 | } |
| 384 | } |
| 385 | |
| 386 | func getExpressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/getExpressionStream().(expression string, index int) *expressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream# { |
| 387 | return &expressionStreamscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#{ |
| 388 | expressionscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#expression.: expression, |
| 389 | indexscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#index.: index, |
| 390 | errscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionStream#err.: nil, |
| 391 | } |
| 392 | } |