| 345 | } |
| 346 | |
| 347 | func TestName(t *testing.T) { |
| 348 | tests := []struct { |
| 349 | str string |
| 350 | want BaseTerm // nil means: expect error |
| 351 | }{ |
| 352 | { |
| 353 | "/bar", |
| 354 | name("/bar"), |
| 355 | }, |
| 356 | { |
| 357 | "/bar/baz", |
| 358 | name("/bar/baz"), |
| 359 | }, |
| 360 | { |
| 361 | "/", |
| 362 | nil, |
| 363 | }, |
| 364 | { |
| 365 | "/bar/", |
| 366 | nil, |
| 367 | }, |
| 368 | { |
| 369 | "//bar/", |
| 370 | nil, |
| 371 | }, |
| 372 | } |
| 373 | for _, test := range tests { |
| 374 | c, err := Name(test.str) |
| 375 | if test.want != nil && err != nil { |
| 376 | t.Errorf("could not construct constant with %s got %v", test.str, err) |
| 377 | } else if test.want != nil && !c.Equals(test.want) { |
| 378 | t.Errorf("wanted %s got %s", test.want, c) |
| 379 | } else if test.want == nil && err == nil { |
| 380 | t.Errorf("expected error but got %s", c) |
| 381 | } |
| 382 | str, err := c.NameValue() |
| 383 | if err != nil { |
| 384 | t.Fatal(err) |
| 385 | } |
| 386 | if test.want != nil && str != test.str { |
| 387 | t.Errorf("want %q got %q", test.str, str) |
| 388 | } |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | func TestStringConstant(t *testing.T) { |
| 393 | tests := []struct { |