|
13 | 13 | // limitations under the License.
|
14 | 14 |
|
15 | 15 | import { describe, expect, test } from "@jest/globals";
|
16 |
| -import { |
17 |
| - safeObjectProperty, |
18 |
| - protoCamelCase, |
19 |
| - localName, |
20 |
| -} from "@bufbuild/protobuf/reflect"; |
21 |
| -import { compileEnum, compileField, compileService } from "../helpers.js"; |
22 |
| - |
23 |
| -describe("localName", () => { |
24 |
| - describe("with field", () => { |
25 |
| - test("applies protoCamelCase", async () => { |
26 |
| - const field = await compileField(` |
27 |
| - syntax="proto3"; |
28 |
| - message M { |
29 |
| - int32 __proto__ = 1; |
30 |
| - } |
31 |
| - `); |
32 |
| - expect(localName(field)).toBe("Proto"); |
33 |
| - }); |
34 |
| - test("escapes reserved property name", async () => { |
35 |
| - const field = await compileField(` |
36 |
| - syntax="proto3"; |
37 |
| - message M { |
38 |
| - int32 constructor = 1; |
39 |
| - } |
40 |
| - `); |
41 |
| - expect(localName(field)).toBe("constructor$"); |
42 |
| - }); |
43 |
| - }); |
44 |
| - describe("with field in oneof", () => { |
45 |
| - test("applies protoCamelCase", async () => { |
46 |
| - const field = await compileField(` |
47 |
| - syntax="proto3"; |
48 |
| - message M { |
49 |
| - oneof kind { |
50 |
| - int32 __proto__ = 1; |
51 |
| - } |
52 |
| - } |
53 |
| - `); |
54 |
| - expect(field.oneof).toBeDefined(); |
55 |
| - expect(localName(field)).toBe("Proto"); |
56 |
| - }); |
57 |
| - test("does not escape reserved property name", async () => { |
58 |
| - const field = await compileField(` |
59 |
| - syntax="proto3"; |
60 |
| - message M { |
61 |
| - oneof kind { |
62 |
| - int32 constructor = 1; |
63 |
| - } |
64 |
| - } |
65 |
| - `); |
66 |
| - expect(field.oneof).toBeDefined(); |
67 |
| - expect(localName(field)).toBe("constructor"); |
68 |
| - }); |
69 |
| - }); |
70 |
| - describe("with enum value", () => { |
71 |
| - test("does not change case", async () => { |
72 |
| - const value = ( |
73 |
| - await compileEnum(` |
74 |
| - syntax="proto3"; |
75 |
| - enum E { |
76 |
| - FooBAR_baz_1 = 0; |
77 |
| - } |
78 |
| - `) |
79 |
| - ).values[0]; |
80 |
| - expect(localName(value)).toBe("FooBAR_baz_1"); |
81 |
| - }); |
82 |
| - test("drops prefix", async () => { |
83 |
| - const value = ( |
84 |
| - await compileEnum(` |
85 |
| - syntax="proto3"; |
86 |
| - enum PrefixEnum { |
87 |
| - PREFIX_ENUM_ZERO = 0; |
88 |
| - PREFIX_ENUM_ONE = 1; |
89 |
| - } |
90 |
| - `) |
91 |
| - ).values[0]; |
92 |
| - expect(localName(value)).toBe("ZERO"); |
93 |
| - }); |
94 |
| - test("escapes reserved property name", async () => { |
95 |
| - const value = ( |
96 |
| - await compileEnum(` |
97 |
| - syntax="proto3"; |
98 |
| - enum EnumBuiltIn { |
99 |
| - constructor = 0; |
100 |
| - } |
101 |
| - `) |
102 |
| - ).values[0]; |
103 |
| - expect(localName(value)).toBe("constructor$"); |
104 |
| - }); |
105 |
| - test("escapes reserved property name with dropped prefix", async () => { |
106 |
| - const value = ( |
107 |
| - await compileEnum(` |
108 |
| - syntax="proto3"; |
109 |
| - enum EnumBuiltInPrefixed { |
110 |
| - ENUM_BUILT_IN_PREFIXED_constructor = 0; |
111 |
| - } |
112 |
| - `) |
113 |
| - ).values[0]; |
114 |
| - expect(localName(value)).toBe("constructor$"); |
115 |
| - }); |
116 |
| - }); |
117 |
| - describe("with rpc", () => { |
118 |
| - test("makes first letter lowerCase", async () => { |
119 |
| - const rpc = ( |
120 |
| - await compileService(` |
121 |
| - syntax="proto3"; |
122 |
| - service Srv { |
123 |
| - rpc Foo_bar_BAZ(E) returns (E); |
124 |
| - } |
125 |
| - message E {} |
126 |
| - `) |
127 |
| - ).methods[0]; |
128 |
| - expect(localName(rpc)).toBe("foo_bar_BAZ"); |
129 |
| - }); |
130 |
| - test("escapes reserved property name", async () => { |
131 |
| - const rpc = ( |
132 |
| - await compileService(` |
133 |
| - syntax="proto3"; |
134 |
| - service Srv { |
135 |
| - rpc constructor(E) returns (E); |
136 |
| - } |
137 |
| - message E {} |
138 |
| - `) |
139 |
| - ).methods[0]; |
140 |
| - expect(localName(rpc)).toBe("constructor$"); |
141 |
| - }); |
142 |
| - }); |
143 |
| -}); |
| 16 | +import { safeObjectProperty, protoCamelCase } from "@bufbuild/protobuf/reflect"; |
| 17 | +import { compileField } from "../helpers.js"; |
144 | 18 |
|
145 | 19 | describe("safeObjectProperty", () => {
|
146 | 20 | test("escapes reserved object property names", () => {
|
|
0 commit comments