Bob Badour | a99ac62 | 2021-10-25 16:21:00 -0700 | [diff] [blame] | 1 | // Copyright 2021 Google LLC |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package compliance |
| 16 | |
| 17 | import ( |
Bob Badour | a99ac62 | 2021-10-25 16:21:00 -0700 | [diff] [blame] | 18 | "testing" |
| 19 | ) |
| 20 | |
Bob Badour | 103eb0f | 2022-01-10 13:50:57 -0800 | [diff] [blame^] | 21 | func TestConditionSetHas(t *testing.T) { |
| 22 | impliesShare := ImpliesShared |
Bob Badour | a99ac62 | 2021-10-25 16:21:00 -0700 | [diff] [blame] | 23 | |
Bob Badour | 103eb0f | 2022-01-10 13:50:57 -0800 | [diff] [blame^] | 24 | t.Logf("testing with imliesShare=%04x", impliesShare) |
| 25 | |
| 26 | if impliesShare.HasAny(NoticeCondition) { |
| 27 | t.Errorf("impliesShare.HasAny(\"notice\"=%04x) got true, want false", NoticeCondition) |
Bob Badour | a99ac62 | 2021-10-25 16:21:00 -0700 | [diff] [blame] | 28 | } |
| 29 | |
Bob Badour | 103eb0f | 2022-01-10 13:50:57 -0800 | [diff] [blame^] | 30 | if !impliesShare.HasAny(RestrictedCondition) { |
| 31 | t.Errorf("impliesShare.HasAny(\"restricted\"=%04x) got false, want true", RestrictedCondition) |
Bob Badour | a99ac62 | 2021-10-25 16:21:00 -0700 | [diff] [blame] | 32 | } |
| 33 | |
Bob Badour | 103eb0f | 2022-01-10 13:50:57 -0800 | [diff] [blame^] | 34 | if !impliesShare.HasAny(ReciprocalCondition) { |
| 35 | t.Errorf("impliesShare.HasAny(\"reciprocal\"=%04x) got false, want true", ReciprocalCondition) |
Bob Badour | a99ac62 | 2021-10-25 16:21:00 -0700 | [diff] [blame] | 36 | } |
| 37 | |
Bob Badour | 103eb0f | 2022-01-10 13:50:57 -0800 | [diff] [blame^] | 38 | if impliesShare.HasAny(LicenseCondition(0x0000)) { |
| 39 | t.Errorf("impliesShare.HasAny(nil=%04x) got true, want false", LicenseCondition(0x0000)) |
Bob Badour | a99ac62 | 2021-10-25 16:21:00 -0700 | [diff] [blame] | 40 | } |
| 41 | } |
| 42 | |
Bob Badour | 103eb0f | 2022-01-10 13:50:57 -0800 | [diff] [blame^] | 43 | func TestConditionName(t *testing.T) { |
| 44 | for expected, condition := range RecognizedConditionNames { |
| 45 | actual := condition.Name() |
| 46 | if expected != actual { |
| 47 | t.Errorf("unexpected name for condition %04x: got %s, want %s", condition, actual, expected) |
| 48 | } |
Bob Badour | a99ac62 | 2021-10-25 16:21:00 -0700 | [diff] [blame] | 49 | } |
Bob Badour | 103eb0f | 2022-01-10 13:50:57 -0800 | [diff] [blame^] | 50 | } |
| 51 | |
| 52 | func TestConditionName_InvalidCondition(t *testing.T) { |
| 53 | panicked := false |
| 54 | var lc LicenseCondition |
| 55 | func() { |
| 56 | defer func() { |
| 57 | if err := recover(); err != nil { |
| 58 | panicked = true |
Bob Badour | a99ac62 | 2021-10-25 16:21:00 -0700 | [diff] [blame] | 59 | } |
Bob Badour | 103eb0f | 2022-01-10 13:50:57 -0800 | [diff] [blame^] | 60 | }() |
| 61 | name := lc.Name() |
| 62 | t.Errorf("invalid condition unexpected name: got %s, wanted panic", name) |
| 63 | }() |
| 64 | if !panicked { |
| 65 | t.Errorf("no expected panic for %04x.Name(): got no panic, wanted panic", lc) |
Bob Badour | a99ac62 | 2021-10-25 16:21:00 -0700 | [diff] [blame] | 66 | } |
| 67 | } |