-
Notifications
You must be signed in to change notification settings - Fork 155
Expand file tree
/
Copy pathrust_keywords_test.go
More file actions
100 lines (96 loc) · 2.62 KB
/
Copy pathrust_keywords_test.go
File metadata and controls
100 lines (96 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package protoc
import (
"testing"
"github.com/google/go-cmp/cmp"
)
func TestRustKeywordEscapeMappings(t *testing.T) {
for name, tc := range map[string]struct {
pkg string
outputs []string
want map[string]string
}{
"empty package": {
pkg: "",
outputs: []string{"foo.rs"},
want: nil,
},
"empty outputs": {
pkg: "google.type",
outputs: nil,
want: nil,
},
"no keywords": {
pkg: "google.api",
outputs: []string{"google.api.rs", "google.api.serde.rs"},
want: nil,
},
"type keyword": {
pkg: "google.type",
outputs: []string{"google.type.rs", "google.type.serde.rs"},
want: map[string]string{
"google.type.rs": "google/r#type/google.type.rs",
"google.type.serde.rs": "google/r#type/google.type.serde.rs",
},
},
"keyword at start": {
pkg: "type.example",
outputs: []string{"type.example.rs"},
want: map[string]string{
"type.example.rs": "r#type/example/type.example.rs",
},
},
"multiple keywords": {
pkg: "self.type",
outputs: []string{"self.type.rs"},
want: map[string]string{
"self.type.rs": "r#self/r#type/self.type.rs",
},
},
"single segment keyword": {
pkg: "type",
outputs: []string{"type.rs"},
want: map[string]string{
"type.rs": "r#type/type.rs",
},
},
"single segment no keyword": {
pkg: "example",
outputs: []string{"example.rs"},
want: nil,
},
"full path outputs": {
pkg: "google.type",
outputs: []string{"google/type/google.type.rs", "google/type/google.type.serde.rs"},
want: map[string]string{
"google.type.rs": "google/r#type/google.type.rs",
"google.type.serde.rs": "google/r#type/google.type.serde.rs",
},
},
} {
t.Run(name, func(t *testing.T) {
got := RustKeywordEscapeMappings(tc.pkg, tc.outputs)
if diff := cmp.Diff(tc.want, got); diff != "" {
t.Errorf("(-want +got):\n%s", diff)
}
})
}
}
func TestRustCrateName(t *testing.T) {
for name, tc := range map[string]struct {
pkg string
want string
}{
"empty": {pkg: "", want: ""},
"single segment": {pkg: "foo", want: "foo"},
"trailing proto": {pkg: "trumid.common.utils.state.snapshot.proto", want: "trumid_common_utils_state_snapshot_proto"},
"sub-package": {pkg: "trumid.common.utils.state.snapshot.proto.example",
want: "trumid_common_utils_state_snapshot_proto_example"},
"keywords are not escaped here": {pkg: "google.type", want: "google_type"},
} {
t.Run(name, func(t *testing.T) {
if got := RustCrateName(tc.pkg); got != tc.want {
t.Errorf("RustCrateName(%q) = %q, want %q", tc.pkg, got, tc.want)
}
})
}
}