blob: a62a00436f41db2d63a24adee2423c29c9954faf [file] [log] [blame]
Joe Tsaidbc9a122018-08-03 17:13:23 -07001// Copyright 2018 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5package protoreflect
6
7import "testing"
8
9func TestNameIsValid(t *testing.T) {
10 tests := []struct {
11 in Name
12 want bool
13 }{
14 {"", false},
15 {"a", true},
16 {".", false},
17 {"_", true}, // odd, but permitted by protoc
18 {".foo", false},
19 {"foo.", false},
20 {"foo", true},
21 {"one1_two2_three3", true},
22 {"1one", false},
23 }
24
25 for _, tt := range tests {
26 if got := tt.in.IsValid(); got != tt.want {
27 t.Errorf("Name(%q).IsValid() = %v, want %v", tt.in, got, tt.want)
28 }
29 }
30}
31
32func TestFullNameIsValid(t *testing.T) {
33 tests := []struct {
34 in FullName
35 want bool
36 }{
37 {"", false},
38 {"a", true},
39 {"a.b", true},
40 {"a.b.c", true},
41 {".", false},
42 {"_._._", true}, // odd, but permitted by protoc
43 {".foo", false},
44 {"foo.", false},
45 {"foo", true},
46 {"one1_two2_three3", true},
47 {"one1.two2.three3", true},
48 {".one1.two2.three3", false},
49 {"one1.two2.three3.", false},
50 {"foo.1one", false},
51 }
52
53 for _, tt := range tests {
54 if got := tt.in.IsValid(); got != tt.want {
55 t.Errorf("Name(%q).IsValid() = %v, want %v", tt.in, got, tt.want)
56 }
57 }
58}
59
60func TestNameAppend(t *testing.T) {
61 tests := []FullName{
62 "",
63 "a",
64 "a.b",
65 "a.b.c",
66 "one1.two2.three3",
67 }
68
69 for _, tt := range tests {
70 if got := tt.Parent().Append(tt.Name()); got != tt {
71 t.Errorf("FullName.Parent().Append(FullName.Name()) = %q, want %q", got, tt)
72 }
73 }
74}