1use minijinja::Environment;
2
3static TEMPLATES: &[(&str, &str)] = &[
4 (
5 "python/pyproject.toml.jinja",
6 include_str!("../templates/python/pyproject.toml.jinja"),
7 ),
8 (
9 "python/conftest.py.jinja",
10 include_str!("../templates/python/conftest.py.jinja"),
11 ),
12 (
13 "python/assertion.jinja",
14 include_str!("../templates/python/assertion.jinja"),
15 ),
16 (
17 "python/visitor_method.jinja",
18 include_str!("../templates/python/visitor_method.jinja"),
19 ),
20 (
21 "python/test_file.jinja",
22 include_str!("../templates/python/test_file.jinja"),
23 ),
24 (
25 "python/test_function.jinja",
26 include_str!("../templates/python/test_function.jinja"),
27 ),
28 ("ruby/Gemfile.jinja", include_str!("../templates/ruby/Gemfile.jinja")),
29 (
30 "ruby/rubocop.yml.jinja",
31 include_str!("../templates/ruby/rubocop.yml.jinja"),
32 ),
33 (
34 "ruby/assertion.jinja",
35 include_str!("../templates/ruby/assertion.jinja"),
36 ),
37 (
38 "ruby/visitor_method.jinja",
39 include_str!("../templates/ruby/visitor_method.jinja"),
40 ),
41 (
42 "ruby/test_file.jinja",
43 include_str!("../templates/ruby/test_file.jinja"),
44 ),
45 (
46 "ruby/test_function.jinja",
47 include_str!("../templates/ruby/test_function.jinja"),
48 ),
49 (
50 "ruby/http_test.jinja",
51 include_str!("../templates/ruby/http_test.jinja"),
52 ),
53 (
54 "ruby/http_test_close.jinja",
55 include_str!("../templates/ruby/http_test_close.jinja"),
56 ),
57 (
58 "ruby/http_request.jinja",
59 include_str!("../templates/ruby/http_request.jinja"),
60 ),
61 (
62 "ruby/http_test_body.jinja",
63 include_str!("../templates/ruby/http_test_body.jinja"),
64 ),
65 (
66 "ruby/http_101_skip.jinja",
67 include_str!("../templates/ruby/http_101_skip.jinja"),
68 ),
69 ("r/description.jinja", include_str!("../templates/r/description.jinja")),
70 ("r/assertion.jinja", include_str!("../templates/r/assertion.jinja")),
71 (
72 "r/visitor_method.jinja",
73 include_str!("../templates/r/visitor_method.jinja"),
74 ),
75 ("r/test_runner.jinja", include_str!("../templates/r/test_runner.jinja")),
76 ("r/test_case.jinja", include_str!("../templates/r/test_case.jinja")),
77 ("r/test_file.jinja", include_str!("../templates/r/test_file.jinja")),
78 (
79 "r/setup_fixtures.jinja",
80 include_str!("../templates/r/setup_fixtures.jinja"),
81 ),
82 (
83 "r/synthetic_assertion.jinja",
84 include_str!("../templates/r/synthetic_assertion.jinja"),
85 ),
86 (
87 "php/composer.json.jinja",
88 include_str!("../templates/php/composer.json.jinja"),
89 ),
90 (
91 "php/phpunit.xml.jinja",
92 include_str!("../templates/php/phpunit.xml.jinja"),
93 ),
94 (
95 "php/bootstrap.php.jinja",
96 include_str!("../templates/php/bootstrap.php.jinja"),
97 ),
98 ("php/assertion.jinja", include_str!("../templates/php/assertion.jinja")),
99 ("php/test_file.jinja", include_str!("../templates/php/test_file.jinja")),
100 (
101 "php/test_method.jinja",
102 include_str!("../templates/php/test_method.jinja"),
103 ),
104 (
105 "php/visitor_method.jinja",
106 include_str!("../templates/php/visitor_method.jinja"),
107 ),
108 (
109 "php/http_test_open.jinja",
110 include_str!("../templates/php/http_test_open.jinja"),
111 ),
112 (
113 "php/http_test_close.jinja",
114 include_str!("../templates/php/http_test_close.jinja"),
115 ),
116 (
117 "php/http_request.jinja",
118 include_str!("../templates/php/http_request.jinja"),
119 ),
120 (
121 "php/http_assertions.jinja",
122 include_str!("../templates/php/http_assertions.jinja"),
123 ),
124 (
125 "php/http_test_skip_101.jinja",
126 include_str!("../templates/php/http_test_skip_101.jinja"),
127 ),
128 (
129 "php/synthetic_assertion.jinja",
130 include_str!("../templates/php/synthetic_assertion.jinja"),
131 ),
132 ("csharp/csproj.jinja", include_str!("../templates/csharp/csproj.jinja")),
133 (
134 "csharp/assertion.jinja",
135 include_str!("../templates/csharp/assertion.jinja"),
136 ),
137 (
138 "csharp/visitor_method.jinja",
139 include_str!("../templates/csharp/visitor_method.jinja"),
140 ),
141 (
142 "csharp/test_file.jinja",
143 include_str!("../templates/csharp/test_file.jinja"),
144 ),
145 (
146 "csharp/test_method.jinja",
147 include_str!("../templates/csharp/test_method.jinja"),
148 ),
149 (
150 "csharp/http_test_open.jinja",
151 include_str!("../templates/csharp/http_test_open.jinja"),
152 ),
153 (
154 "csharp/http_test_close.jinja",
155 include_str!("../templates/csharp/http_test_close.jinja"),
156 ),
157 (
158 "csharp/http_request.jinja",
159 include_str!("../templates/csharp/http_request.jinja"),
160 ),
161 (
162 "csharp/http_test_body.jinja",
163 include_str!("../templates/csharp/http_test_body.jinja"),
164 ),
165 ("java/pom.xml.jinja", include_str!("../templates/java/pom.xml.jinja")),
166 (
167 "java/test_file.jinja",
168 include_str!("../templates/java/test_file.jinja"),
169 ),
170 (
171 "java/test_method.jinja",
172 include_str!("../templates/java/test_method.jinja"),
173 ),
174 (
175 "java/assertion.jinja",
176 include_str!("../templates/java/assertion.jinja"),
177 ),
178 (
179 "java/visitor_method.jinja",
180 include_str!("../templates/java/visitor_method.jinja"),
181 ),
182 (
183 "java/http_test_open.jinja",
184 include_str!("../templates/java/http_test_open.jinja"),
185 ),
186 (
187 "java/http_test_close.jinja",
188 include_str!("../templates/java/http_test_close.jinja"),
189 ),
190 (
191 "java/http_request.jinja",
192 include_str!("../templates/java/http_request.jinja"),
193 ),
194 (
195 "java/http_assertions.jinja",
196 include_str!("../templates/java/http_assertions.jinja"),
197 ),
198 (
199 "java/http_test_skip_101.jinja",
200 include_str!("../templates/java/http_test_skip_101.jinja"),
201 ),
202 (
203 "java/synthetic_assertion.jinja",
204 include_str!("../templates/java/synthetic_assertion.jinja"),
205 ),
206 (
207 "typescript/package.json.jinja",
208 include_str!("../templates/typescript/package.json.jinja"),
209 ),
210 (
211 "typescript/tsconfig.jinja",
212 include_str!("../templates/typescript/tsconfig.jinja"),
213 ),
214 (
215 "typescript/vitest.config.ts.jinja",
216 include_str!("../templates/typescript/vitest.config.ts.jinja"),
217 ),
218 (
219 "typescript/setup.ts.jinja",
220 include_str!("../templates/typescript/setup.ts.jinja"),
221 ),
222 (
223 "typescript/globalSetup.ts.jinja",
224 include_str!("../templates/typescript/globalSetup.ts.jinja"),
225 ),
226 (
227 "typescript/assertion.jinja",
228 include_str!("../templates/typescript/assertion.jinja"),
229 ),
230 (
231 "typescript/synthetic_assertion.jinja",
232 include_str!("../templates/typescript/synthetic_assertion.jinja"),
233 ),
234 (
235 "typescript/visitor_method.jinja",
236 include_str!("../templates/typescript/visitor_method.jinja"),
237 ),
238 (
239 "typescript/test_file.jinja",
240 include_str!("../templates/typescript/test_file.jinja"),
241 ),
242 (
243 "typescript/test_function.jinja",
244 include_str!("../templates/typescript/test_function.jinja"),
245 ),
246 (
247 "typescript/helpers.jinja",
248 include_str!("../templates/typescript/helpers.jinja"),
249 ),
250 (
251 "typescript/http_test.jinja",
252 include_str!("../templates/typescript/http_test.jinja"),
253 ),
254 (
255 "typescript/cache_isolation_setup.jinja",
256 include_str!("../templates/typescript/cache_isolation_setup.jinja"),
257 ),
258 (
259 "typescript/http_test_skip_101.jinja",
260 include_str!("../templates/typescript/http_test_skip_101.jinja"),
261 ),
262 (
263 "python/http_test.jinja",
264 include_str!("../templates/python/http_test.jinja"),
265 ),
266 (
267 "python/http_101_skip.jinja",
268 include_str!("../templates/python/http_101_skip.jinja"),
269 ),
270 (
271 "wasm/package.json.jinja",
272 include_str!("../templates/wasm/package.json.jinja"),
273 ),
274 (
275 "wasm/vitest.config.ts.jinja",
276 include_str!("../templates/wasm/vitest.config.ts.jinja"),
277 ),
278 (
279 "wasm/globalSetup.ts.jinja",
280 include_str!("../templates/wasm/globalSetup.ts.jinja"),
281 ),
282 ("wasm/tsconfig.jinja", include_str!("../templates/wasm/tsconfig.jinja")),
283 (
284 "wasm/assertion.jinja",
285 include_str!("../templates/wasm/assertion.jinja"),
286 ),
287 (
288 "wasm/visitor_method.jinja",
289 include_str!("../templates/wasm/visitor_method.jinja"),
290 ),
291];
292
293pub(crate) fn make_env() -> Environment<'static> {
294 let mut env = Environment::new();
295 env.set_trim_blocks(true);
296 env.set_lstrip_blocks(true);
297 env.set_keep_trailing_newline(true);
298 for (name, src) in TEMPLATES {
299 env.add_template(name, src).expect("built-in template is valid");
300 }
301 env
302}
303
304pub(crate) fn render(template_name: &str, ctx: minijinja::Value) -> String {
305 make_env()
306 .get_template(template_name)
307 .unwrap_or_else(|_| panic!("template {template_name} not found"))
308 .render(ctx)
309 .unwrap_or_else(|e| panic!("template {template_name} failed to render: {e}"))
310}