| 1 | package metadata |
| 2 | |
| 3 | import "testing" |
| 4 | |
| 5 | func TestValidationCSharpKeywords(t *testing.T) { |
| 6 | for key := range cSharpKeywords { |
| 7 | t.Logf("[DEBUG] Testing %q", key) |
| 8 | |
| 9 | err := Validate(map[string]string{ |
| 10 | key: "value", |
| 11 | }) |
| 12 | if err == nil { |
| 13 | t.Fatalf("Expected an error but didn't get one for %q", key) |
| 14 | } |
| 15 | } |
| 16 | } |
| 17 | |
| 18 | func TestValidation(t *testing.T) { |
| 19 | testData := []struct { |
| 20 | Input string |
| 21 | ShouldBeValid bool |
| 22 | }{ |
| 23 | { |
| 24 | Input: "", |
| 25 | ShouldBeValid: false, |
| 26 | }, |
| 27 | { |
| 28 | Input: "abc123", |
| 29 | ShouldBeValid: true, |
| 30 | }, |
| 31 | { |
| 32 | Input: "_abc123", |
| 33 | ShouldBeValid: true, |
| 34 | }, |
| 35 | { |
| 36 | Input: "123abc", |
| 37 | ShouldBeValid: false, |
| 38 | }, |
| 39 | { |
| 40 | Input: "a_123abc", |
| 41 | ShouldBeValid: true, |
| 42 | }, |
| 43 | { |
| 44 | Input: "abc_123", |
| 45 | ShouldBeValid: true, |
| 46 | }, |
| 47 | { |
| 48 | Input: "abc123_", |
| 49 | ShouldBeValid: true, |
| 50 | }, |
| 51 | { |
| 52 | Input: "ABC123", |
| 53 | ShouldBeValid: true, |
| 54 | }, |
| 55 | } |
| 56 | |
| 57 | for _, v := range testData { |
| 58 | t.Logf("[DEBUG] Testing %q", v.Input) |
| 59 | |
| 60 | err := Validate(map[string]string{ |
| 61 | v.Input: "value", |
| 62 | }) |
| 63 | actual := err == nil |
| 64 | if v.ShouldBeValid != actual { |
| 65 | t.Fatalf("Expected %t but got %t for %q", v.ShouldBeValid, actual, v.Input) |
| 66 | } |
| 67 | } |
| 68 | } |