blob: c790a68543e801a05a95c17efad94ca491b78e94 [file] [log] [blame]
Colin Cross41955e82019-05-29 14:40:35 -07001// Copyright 2015 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 android
16
17import "testing"
18
19func TestSrcIsModule(t *testing.T) {
20 type args struct {
21 s string
22 }
23 tests := []struct {
24 name string
25 args args
26 wantModule string
27 }{
28 {
29 name: "file",
30 args: args{
31 s: "foo",
32 },
33 wantModule: "",
34 },
35 {
36 name: "module",
37 args: args{
38 s: ":foo",
39 },
40 wantModule: "foo",
41 },
42 {
43 name: "tag",
44 args: args{
45 s: ":foo{.bar}",
46 },
47 wantModule: "foo{.bar}",
48 },
49 {
50 name: "extra colon",
51 args: args{
52 s: ":foo:bar",
53 },
54 wantModule: "foo:bar",
55 },
56 }
57 for _, tt := range tests {
58 t.Run(tt.name, func(t *testing.T) {
59 if gotModule := SrcIsModule(tt.args.s); gotModule != tt.wantModule {
60 t.Errorf("SrcIsModule() = %v, want %v", gotModule, tt.wantModule)
61 }
62 })
63 }
64}
65
66func TestSrcIsModuleWithTag(t *testing.T) {
67 type args struct {
68 s string
69 }
70 tests := []struct {
71 name string
72 args args
73 wantModule string
74 wantTag string
75 }{
76 {
77 name: "file",
78 args: args{
79 s: "foo",
80 },
81 wantModule: "",
82 wantTag: "",
83 },
84 {
85 name: "module",
86 args: args{
87 s: ":foo",
88 },
89 wantModule: "foo",
90 wantTag: "",
91 },
92 {
93 name: "tag",
94 args: args{
95 s: ":foo{.bar}",
96 },
97 wantModule: "foo",
98 wantTag: ".bar",
99 },
100 {
101 name: "empty tag",
102 args: args{
103 s: ":foo{}",
104 },
105 wantModule: "foo",
106 wantTag: "",
107 },
108 {
109 name: "extra colon",
110 args: args{
111 s: ":foo:bar",
112 },
113 wantModule: "foo:bar",
114 },
115 {
116 name: "invalid tag",
117 args: args{
118 s: ":foo{.bar",
119 },
120 wantModule: "foo{.bar",
121 },
122 {
123 name: "invalid tag 2",
124 args: args{
125 s: ":foo.bar}",
126 },
127 wantModule: "foo.bar}",
128 },
129 }
130 for _, tt := range tests {
131 t.Run(tt.name, func(t *testing.T) {
132 gotModule, gotTag := SrcIsModuleWithTag(tt.args.s)
133 if gotModule != tt.wantModule {
134 t.Errorf("SrcIsModuleWithTag() gotModule = %v, want %v", gotModule, tt.wantModule)
135 }
136 if gotTag != tt.wantTag {
137 t.Errorf("SrcIsModuleWithTag() gotTag = %v, want %v", gotTag, tt.wantTag)
138 }
139 })
140 }
141}