| 224 | } |
| 225 | |
| 226 | func TestParsePackage(t *testing.T) { |
| 227 | tests := []struct { |
| 228 | name string |
| 229 | str string |
| 230 | want []ast.Decl |
| 231 | }{ |
| 232 | { |
| 233 | name: "Regular package", |
| 234 | str: "Package foo.bar!", |
| 235 | want: []ast.Decl{makeDecl(t, ast.NewAtom("Package"), []ast.Atom{ast.NewAtom("name", ast.String("foo.bar"))}, nil, nil)}, |
| 236 | }, |
| 237 | { |
| 238 | name: "White space allowed after identifier", |
| 239 | str: "Package foo.bar !", |
| 240 | want: []ast.Decl{makeDecl(t, ast.NewAtom("Package"), []ast.Atom{ast.NewAtom("name", ast.String("foo.bar"))}, nil, nil)}, |
| 241 | }, |
| 242 | { |
| 243 | name: "Package with atoms", |
| 244 | str: `Package foo [atom1("hello"), atom2()]!`, |
| 245 | want: []ast.Decl{makeDecl(t, ast.NewAtom("Package"), []ast.Atom{ast.NewAtom("name", ast.String("foo")), ast.NewAtom("atom1", ast.String("hello")), ast.NewAtom("atom2")}, nil, nil)}, |
| 246 | }, |
| 247 | } |
| 248 | for _, test := range tests { |
| 249 | t.Run(test.name, func(t *testing.T) { |
| 250 | got, err := Unit(strings.NewReader(test.str)) |
| 251 | if err != nil { |
| 252 | t.Fatalf("Unit(%v) failed with %v", test.str, err) |
| 253 | } |
| 254 | if diff := cmp.Diff(test.want, got.Decls, cmp.Comparer(equals)); diff != "" { |
| 255 | t.Errorf("Unit(%v) = %v want %v diff %v", test.str, got, test.want, diff) |
| 256 | } |
| 257 | }) |
| 258 | } |
| 259 | |
| 260 | } |
| 261 | |
| 262 | func TestParsePackageError(t *testing.T) { |
| 263 | tests := []struct { |