1// Copyright 2020 Google LLC
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 generator
16
17import "testing"
18
19func TestHasPrefix(t *testing.T) {
20	tests := []struct {
21		s        string
22		prefixes []string
23		want     bool
24	}{
25		{
26			s:        "abc",
27			prefixes: []string{"a"},
28			want:     true,
29		},
30		{
31			s:        "abc",
32			prefixes: []string{"ab"},
33			want:     true,
34		},
35		{
36			s:        "abc",
37			prefixes: []string{"abc"},
38			want:     true,
39		},
40		{
41			s:        "google.golang.org/genproto/googleapis/ads/googleads/v1/common",
42			prefixes: []string{"google.golang.org/genproto/googleapis/ads"},
43			want:     true,
44		},
45		{
46			s:        "abc",
47			prefixes: []string{"zzz"},
48			want:     false,
49		},
50		{
51			s:        "",
52			prefixes: []string{"zzz"},
53			want:     false,
54		},
55		{
56			s:    "abc",
57			want: false,
58		},
59	}
60	for _, test := range tests {
61		if got := hasPrefix(test.s, test.prefixes); got != test.want {
62			t.Errorf("hasPrefix(%q, %q) got %v, want %v", test.s, test.prefixes, got, test.want)
63		}
64	}
65}
66