| 77 | } |
| 78 | |
| 79 | func TestCheckDeclExternal(t *testing.T) { |
| 80 | testCases := []struct { |
| 81 | desc string |
| 82 | source string |
| 83 | wantErr bool |
| 84 | }{ |
| 85 | { |
| 86 | desc: "valid external decl", |
| 87 | source: ` |
| 88 | Decl testExt(X, Y) |
| 89 | descr [ |
| 90 | external(), |
| 91 | mode('+', '-'), |
| 92 | ] |
| 93 | bound [ /number, /string ] |
| 94 | .`, |
| 95 | wantErr: false, |
| 96 | }, |
| 97 | { |
| 98 | desc: "external decl with no modes", |
| 99 | source: ` |
| 100 | Decl testExt(X, Y) |
| 101 | descr [ |
| 102 | external() |
| 103 | ] |
| 104 | bound [ /number, /string ] |
| 105 | .`, |
| 106 | wantErr: true, |
| 107 | }, |
| 108 | { |
| 109 | desc: "external decl with two modes", |
| 110 | source: ` |
| 111 | Decl testExt(X, Y) |
| 112 | descr [ |
| 113 | external(), |
| 114 | mode('+', '-'), |
| 115 | mode('-', '+') |
| 116 | ] |
| 117 | bound [ /number, /string ] |
| 118 | .`, |
| 119 | wantErr: true, |
| 120 | }, |
| 121 | } |
| 122 | |
| 123 | for _, tc := range testCases { |
| 124 | t.Run(tc.desc, func(t *testing.T) { |
| 125 | unit, err := parse.Unit(strings.NewReader(tc.source)) |
| 126 | if err != nil { |
| 127 | t.Fatalf("parse.Unit(%q) failed: %v", tc.source, err) |
| 128 | } |
| 129 | if len(unit.Decls) != 2 { // package decl + test decl |
| 130 | t.Fatalf("expected 1 decl, got %d", len(unit.Decls)) |
| 131 | } |
| 132 | decl := unit.Decls[1] |
| 133 | errs := CheckDecl(decl) |
| 134 | if (len(errs) > 0) != tc.wantErr { |
| 135 | t.Errorf("CheckDecl() returned errors %v, wantErr=%v", errs, tc.wantErr) |
| 136 | } |