| 821 | } |
| 822 | |
| 823 | func TestAttributeExprHasTag(t *testing.T) { |
| 824 | var ( |
| 825 | tag = "view" |
| 826 | ) |
| 827 | cases := map[string]struct { |
| 828 | attribute *AttributeExpr |
| 829 | tag string |
| 830 | expected bool |
| 831 | }{ |
| 832 | "has tag": { |
| 833 | attribute: &AttributeExpr{ |
| 834 | Type: &Object{ |
| 835 | &NamedAttributeExpr{ |
| 836 | Name: "foo", |
| 837 | Attribute: &AttributeExpr{ |
| 838 | Meta: MetaExpr{ |
| 839 | tag: []string{"default"}, |
| 840 | }, |
| 841 | }, |
| 842 | }, |
| 843 | }, |
| 844 | }, |
| 845 | tag: tag, |
| 846 | expected: true, |
| 847 | }, |
| 848 | "attribute expr is nil": { |
| 849 | attribute: nil, |
| 850 | tag: tag, |
| 851 | expected: false, |
| 852 | }, |
| 853 | "not object": { |
| 854 | attribute: &AttributeExpr{ |
| 855 | Type: String, |
| 856 | }, |
| 857 | tag: tag, |
| 858 | expected: false, |
| 859 | }, |
| 860 | "object but has no tag": { |
| 861 | attribute: &AttributeExpr{ |
| 862 | Type: &Object{ |
| 863 | &NamedAttributeExpr{ |
| 864 | Name: "foo", |
| 865 | Attribute: &AttributeExpr{}, |
| 866 | }, |
| 867 | }, |
| 868 | }, |
| 869 | tag: tag, |
| 870 | }, |
| 871 | } |
| 872 | |
| 873 | for k, tc := range cases { |
| 874 | if actual := tc.attribute.HasTag(tc.tag); tc.expected != actual { |
| 875 | t.Errorf("%s: got %#v, expected %#v", k, actual, tc.expected) |
| 876 | } |
| 877 | } |
| 878 | } |
| 879 | |
| 880 | func TestAttributeExprHasTagPrefix(t *testing.T) { |