(t *testing.T)
| 677 | } |
| 678 | |
| 679 | func TestNameFuns(t *testing.T) { |
| 680 | tests := []struct { |
| 681 | name string |
| 682 | expr ast.ApplyFn |
| 683 | want ast.Constant |
| 684 | }{ |
| 685 | { |
| 686 | name: "name root single part", |
| 687 | expr: ast.ApplyFn{symbols.NameRoot, []ast.BaseTerm{name("/a")}}, |
| 688 | want: name("/a"), |
| 689 | }, |
| 690 | { |
| 691 | name: "name root", |
| 692 | expr: ast.ApplyFn{symbols.NameRoot, []ast.BaseTerm{name("/a/b/c")}}, |
| 693 | want: name("/a"), |
| 694 | }, |
| 695 | { |
| 696 | name: "name list single part", |
| 697 | expr: ast.ApplyFn{symbols.NameList, []ast.BaseTerm{name("/a")}}, |
| 698 | want: ast.List([]ast.Constant{name("/a")}), |
| 699 | }, |
| 700 | { |
| 701 | name: "name list", |
| 702 | expr: ast.ApplyFn{symbols.NameList, []ast.BaseTerm{name("/a/b/c")}}, |
| 703 | want: ast.List([]ast.Constant{name("/a"), name("/b"), name("/c")}), |
| 704 | }, |
| 705 | { |
| 706 | name: "name tip", |
| 707 | expr: ast.ApplyFn{symbols.NameTip, []ast.BaseTerm{name("/a/b/c")}}, |
| 708 | want: name("/c"), |
| 709 | }, |
| 710 | { |
| 711 | name: "name tip single part", |
| 712 | expr: ast.ApplyFn{symbols.NameTip, []ast.BaseTerm{name("/c")}}, |
| 713 | want: name("/c"), |
| 714 | }, |
| 715 | } |
| 716 | for _, test := range tests { |
| 717 | t.Run(test.name, func(t *testing.T) { |
| 718 | got, err := EvalApplyFn(test.expr, ast.ConstSubstMap{}) |
| 719 | if err != nil { |
| 720 | t.Fatalf("EvalApplyFn(%v) failed with %v", test.expr, err) |
| 721 | } |
| 722 | if !got.Equals(test.want) { |
| 723 | t.Errorf("EvalApplyFn(%v) = %v want %v", test.expr, got, test.want) |
| 724 | } |
| 725 | }) |
| 726 | } |
| 727 | } |
| 728 | |
| 729 | func TestNameToString(t *testing.T) { |
| 730 | name, err := ast.Name("/named/constant") |
nothing calls this directly
no test coverage detected