1// Copyright 2019 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package bpdoc
16
17import (
18	"reflect"
19	"testing"
20)
21
22func TestExcludeByTag(t *testing.T) {
23	r := NewReader(pkgFiles)
24	ps, err := r.PropertyStruct(pkgPath, "tagTestProps", reflect.ValueOf(tagTestProps{}))
25	if err != nil {
26		t.Fatal(err)
27	}
28
29	ps.ExcludeByTag("tag1", "a")
30
31	expected := []string{"c"}
32	actual := []string{}
33	for _, p := range ps.Properties {
34		actual = append(actual, p.Name)
35	}
36	if !reflect.DeepEqual(expected, actual) {
37		t.Errorf("unexpected ExcludeByTag result, expected: %q, actual: %q", expected, actual)
38	}
39}
40
41func TestIncludeByTag(t *testing.T) {
42	r := NewReader(pkgFiles)
43	ps, err := r.PropertyStruct(pkgPath, "tagTestProps", reflect.ValueOf(tagTestProps{A: "B"}))
44	if err != nil {
45		t.Fatal(err)
46	}
47
48	ps.IncludeByTag("tag1", "c")
49
50	expected := []string{"b", "c"}
51	actual := []string{}
52	for _, p := range ps.Properties {
53		actual = append(actual, p.Name)
54	}
55	if !reflect.DeepEqual(expected, actual) {
56		t.Errorf("unexpected IncludeByTag result, expected: %q, actual: %q", expected, actual)
57	}
58}
59