use minijinja::Environment;
static TEMPLATES: &[(&str, &str)] = &[
(
"kotlin/not_empty_assertion.kt.jinja",
include_str!("templates/kotlin/not_empty_assertion.kt.jinja"),
),
(
"kotlin/is_empty_assertion.kt.jinja",
include_str!("templates/kotlin/is_empty_assertion.kt.jinja"),
),
(
"swift/not_empty_assertion.swift.jinja",
include_str!("templates/swift/not_empty_assertion.swift.jinja"),
),
(
"swift/void_not_error_sync.jinja",
include_str!("templates/swift/void_not_error_sync.jinja"),
),
(
"swift/void_not_error_async.jinja",
include_str!("templates/swift/void_not_error_async.jinja"),
),
(
"kotlin_android/excluded_fixtures.kt.jinja",
include_str!("templates/kotlin_android/excluded_fixtures.kt.jinja"),
),
(
"gradle/guarded_working_dir.kt.jinja",
include_str!("templates/gradle/guarded_working_dir.kt.jinja"),
),
(
"python/snippet_body.py.jinja",
include_str!("templates/python/snippet_body.py.jinja"),
),
(
"python/docs_file_expression.py.jinja",
include_str!("templates/python/docs_file_expression.py.jinja"),
),
(
"python/call_statement.py.jinja",
include_str!("templates/python/call_statement.py.jinja"),
),
(
"rust/snippet_body.rs.jinja",
include_str!("templates/rust/snippet_body.rs.jinja"),
),
(
"rust/docs_file_read.rs.jinja",
include_str!("templates/rust/docs_file_read.rs.jinja"),
),
(
"rust/docs_json_file.rs.jinja",
include_str!("templates/rust/docs_json_file.rs.jinja"),
),
(
"rust/mock_server_fixture.rs.jinja",
include_str!("templates/rust/mock_server_fixture.rs.jinja"),
),
(
"typescript/typed_binding.jinja",
include_str!("templates/typescript/typed_binding.jinja"),
),
(
"typescript/docs_file_expression.jinja",
include_str!("templates/typescript/docs_file_expression.jinja"),
),
(
"typescript/docs_file_assignment.jinja",
include_str!("templates/typescript/docs_file_assignment.jinja"),
),
(
"typescript/builder_iife.jinja",
include_str!("templates/typescript/builder_iife.jinja"),
),
(
"snippets/file.md.jinja",
include_str!("templates/snippets/file.md.jinja"),
),
(
"snippets/docs_only_file.md.jinja",
include_str!("templates/snippets/docs_only_file.md.jinja"),
),
("brew/harness.sh.jinja", include_str!("templates/brew/harness.sh.jinja")),
(
"brew/snippet_body.jinja",
include_str!("templates/brew/snippet_body.jinja"),
),
("c/snippet_body.jinja", include_str!("templates/c/snippet_body.jinja")),
(
"c/trait_bridge_snippet.jinja",
include_str!("templates/c/trait_bridge_snippet.jinja"),
),
(
"c/test_skip_if_env_missing.jinja",
include_str!("templates/c/test_skip_if_env_missing.jinja"),
),
(
"c/test_pass_if_null.jinja",
include_str!("templates/c/test_pass_if_null.jinja"),
),
("c/typed_handle.jinja", include_str!("templates/c/typed_handle.jinja")),
(
"c/managed_handle_create.jinja",
include_str!("templates/c/managed_handle_create.jinja"),
),
(
"c/typed_handle_free.jinja",
include_str!("templates/c/typed_handle_free.jinja"),
),
(
"c/snippet_void_call.jinja",
include_str!("templates/c/snippet_void_call.jinja"),
),
(
"c/snippet_status_call.jinja",
include_str!("templates/c/snippet_status_call.jinja"),
),
(
"python/pyproject.toml.jinja",
include_str!("templates/python/pyproject.toml.jinja"),
),
(
"python/conftest.py.jinja",
include_str!("templates/python/conftest.py.jinja"),
),
(
"python/assertion.jinja",
include_str!("templates/python/assertion.jinja"),
),
(
"python/visitor_method.jinja",
include_str!("templates/python/visitor_method.jinja"),
),
(
"python/visitor_context_probe.jinja",
include_str!("templates/python/visitor_context_probe.jinja"),
),
(
"python/visitor_context_assertions.jinja",
include_str!("templates/python/visitor_context_assertions.jinja"),
),
(
"python/test_file.jinja",
include_str!("templates/python/test_file.jinja"),
),
(
"python/test_function.jinja",
include_str!("templates/python/test_function.jinja"),
),
(
"python/test_smoke.py.jinja",
include_str!("templates/python/test_smoke.py.jinja"),
),
("ruby/Gemfile.jinja", include_str!("templates/ruby/Gemfile.jinja")),
(
"ruby/snippet_body.jinja",
include_str!("templates/ruby/snippet_body.jinja"),
),
(
"ruby/http_snippet.jinja",
include_str!("templates/ruby/http_snippet.jinja"),
),
(
"ruby/rubocop.yml.jinja",
include_str!("templates/ruby/rubocop.yml.jinja"),
),
("ruby/assertion.jinja", include_str!("templates/ruby/assertion.jinja")),
(
"ruby/visitor_method.jinja",
include_str!("templates/ruby/visitor_method.jinja"),
),
("ruby/test_file.jinja", include_str!("templates/ruby/test_file.jinja")),
(
"ruby/test_function.jinja",
include_str!("templates/ruby/test_function.jinja"),
),
("ruby/http_test.jinja", include_str!("templates/ruby/http_test.jinja")),
(
"ruby/http_test_close.jinja",
include_str!("templates/ruby/http_test_close.jinja"),
),
(
"ruby/http_request.jinja",
include_str!("templates/ruby/http_request.jinja"),
),
(
"ruby/http_test_body.jinja",
include_str!("templates/ruby/http_test_body.jinja"),
),
(
"ruby/http_101_skip.jinja",
include_str!("templates/ruby/http_101_skip.jinja"),
),
(
"ruby/app_harness.rb.jinja",
include_str!("templates/ruby/app_harness.rb.jinja"),
),
(
"ruby/http_test_sut.jinja",
include_str!("templates/ruby/http_test_sut.jinja"),
),
(
"ruby/spec_helper_mock_server.rb.jinja",
include_str!("templates/ruby/spec_helper_mock_server.rb.jinja"),
),
("r/description.jinja", include_str!("templates/r/description.jinja")),
("r/snippet_body.jinja", include_str!("templates/r/snippet_body.jinja")),
(
"r/visitor_method.jinja",
include_str!("templates/r/visitor_method.jinja"),
),
("r/test_runner.jinja", include_str!("templates/r/test_runner.jinja")),
("r/test_case.jinja", include_str!("templates/r/test_case.jinja")),
("r/test_file.jinja", include_str!("templates/r/test_file.jinja")),
(
"r/setup_fixtures.jinja",
include_str!("templates/r/setup_fixtures.jinja"),
),
(
"r/synthetic_assertion.jinja",
include_str!("templates/r/synthetic_assertion.jinja"),
),
(
"php/composer.json.jinja",
include_str!("templates/php/composer.json.jinja"),
),
("php/phpunit.xml.jinja", include_str!("templates/php/phpunit.xml.jinja")),
(
"php/http_snippet.jinja",
include_str!("templates/php/http_snippet.jinja"),
),
(
"php/bootstrap.php.jinja",
include_str!("templates/php/bootstrap.php.jinja"),
),
("php/assertion.jinja", include_str!("templates/php/assertion.jinja")),
("php/test_file.jinja", include_str!("templates/php/test_file.jinja")),
(
"php/snippet_body.jinja",
include_str!("templates/php/snippet_body.jinja"),
),
("php/typed_dto.jinja", include_str!("templates/php/typed_dto.jinja")),
("php/test_method.jinja", include_str!("templates/php/test_method.jinja")),
(
"php/visitor_method.jinja",
include_str!("templates/php/visitor_method.jinja"),
),
(
"php/http_test_open.jinja",
include_str!("templates/php/http_test_open.jinja"),
),
(
"php/http_test_close.jinja",
include_str!("templates/php/http_test_close.jinja"),
),
(
"php/http_request.jinja",
include_str!("templates/php/http_request.jinja"),
),
(
"php/http_assertions.jinja",
include_str!("templates/php/http_assertions.jinja"),
),
(
"php/http_test_skip_101.jinja",
include_str!("templates/php/http_test_skip_101.jinja"),
),
(
"php/synthetic_assertion.jinja",
include_str!("templates/php/synthetic_assertion.jinja"),
),
(
"php/app_harness.php.jinja",
include_str!("templates/php/app_harness.php.jinja"),
),
("csharp/csproj.jinja", include_str!("templates/csharp/csproj.jinja")),
(
"csharp/assertion.jinja",
include_str!("templates/csharp/assertion.jinja"),
),
(
"csharp/visitor_method.jinja",
include_str!("templates/csharp/visitor_method.jinja"),
),
(
"csharp/test_file.jinja",
include_str!("templates/csharp/test_file.jinja"),
),
(
"csharp/test_method.jinja",
include_str!("templates/csharp/test_method.jinja"),
),
(
"csharp/http_test_open.jinja",
include_str!("templates/csharp/http_test_open.jinja"),
),
(
"csharp/http_test_close.jinja",
include_str!("templates/csharp/http_test_close.jinja"),
),
(
"csharp/http_request.jinja",
include_str!("templates/csharp/http_request.jinja"),
),
(
"csharp/http_test_body.jinja",
include_str!("templates/csharp/http_test_body.jinja"),
),
(
"csharp/app_harness.cs.jinja",
include_str!("templates/csharp/app_harness.cs.jinja"),
),
(
"csharp/test_setup_mock_server.cs.jinja",
include_str!("templates/csharp/test_setup_mock_server.cs.jinja"),
),
(
"csharp/snippet_body.jinja",
include_str!("templates/csharp/snippet_body.jinja"),
),
(
"csharp/wrapped_collection_literal.jinja",
include_str!("templates/csharp/wrapped_collection_literal.jinja"),
),
(
"kotlin/snippet_body.jinja",
include_str!("templates/kotlin/snippet_body.jinja"),
),
(
"kotlin/docs_file_read.jinja",
include_str!("templates/kotlin/docs_file_read.jinja"),
),
(
"kotlin/snippet_json_object_setup.jinja",
include_str!("templates/kotlin/snippet_json_object_setup.jinja"),
),
(
"kotlin/test_imports.kt.jinja",
include_str!("templates/kotlin/test_imports.kt.jinja"),
),
(
"ruby/docs_file_read.jinja",
include_str!("templates/ruby/docs_file_read.jinja"),
),
(
"elixir/docs_file_read.jinja",
include_str!("templates/elixir/docs_file_read.jinja"),
),
(
"r/docs_file_read.jinja",
include_str!("templates/r/docs_file_read.jinja"),
),
(
"swift/docs_file_read.jinja",
include_str!("templates/swift/docs_file_read.jinja"),
),
(
"swift/docs_file_json.jinja",
include_str!("templates/swift/docs_file_json.jinja"),
),
(
"zig/docs_file_read.jinja",
include_str!("templates/zig/docs_file_read.jinja"),
),
(
"zig/docs_file_json.jinja",
include_str!("templates/zig/docs_file_json.jinja"),
),
(
"zig/docs_json_replace.jinja",
include_str!("templates/zig/docs_json_replace.jinja"),
),
(
"c/docs_json_base.jinja",
include_str!("templates/c/docs_json_base.jinja"),
),
(
"c/docs_file_replace.jinja",
include_str!("templates/c/docs_file_replace.jinja"),
),
(
"c/docs_json_cleanup.jinja",
include_str!("templates/c/docs_json_cleanup.jinja"),
),
(
"c/wildcard_collection_assertion.jinja",
include_str!("templates/c/wildcard_collection_assertion.jinja"),
),
(
"c/scalar_or_collection_empty.jinja",
include_str!("templates/c/scalar_or_collection_empty.jinja"),
),
("java/pom.xml.jinja", include_str!("templates/java/pom.xml.jinja")),
("java/test_file.jinja", include_str!("templates/java/test_file.jinja")),
(
"java/test_method.jinja",
include_str!("templates/java/test_method.jinja"),
),
("java/assertion.jinja", include_str!("templates/java/assertion.jinja")),
(
"java/visitor_method.jinja",
include_str!("templates/java/visitor_method.jinja"),
),
(
"java/http_test_open.jinja",
include_str!("templates/java/http_test_open.jinja"),
),
(
"java/http_test_close.jinja",
include_str!("templates/java/http_test_close.jinja"),
),
(
"java/http_request.jinja",
include_str!("templates/java/http_request.jinja"),
),
(
"java/http_assertions.jinja",
include_str!("templates/java/http_assertions.jinja"),
),
(
"java/http_test_skip_101.jinja",
include_str!("templates/java/http_test_skip_101.jinja"),
),
(
"java/synthetic_assertion.jinja",
include_str!("templates/java/synthetic_assertion.jinja"),
),
(
"java/harness_main.jinja",
include_str!("templates/java/harness_main.jinja"),
),
(
"java/snippet_body.jinja",
include_str!("templates/java/snippet_body.jinja"),
),
(
"java/snippet_json_object_setup.jinja",
include_str!("templates/java/snippet_json_object_setup.jinja"),
),
(
"java/MockServerListener.java.jinja",
include_str!("templates/java/MockServerListener.java.jinja"),
),
(
"typescript/package.json.jinja",
include_str!("templates/typescript/package.json.jinja"),
),
(
"typescript/tsconfig.jinja",
include_str!("templates/typescript/tsconfig.jinja"),
),
(
"typescript/vitest.config.ts.jinja",
include_str!("templates/typescript/vitest.config.ts.jinja"),
),
(
"typescript/setup.ts.jinja",
include_str!("templates/typescript/setup.ts.jinja"),
),
(
"typescript/globalSetup.ts.jinja",
include_str!("templates/typescript/globalSetup.ts.jinja"),
),
(
"typescript/assertion.jinja",
include_str!("templates/typescript/assertion.jinja"),
),
(
"typescript/wildcard_assertion.jinja",
include_str!("templates/typescript/wildcard_assertion.jinja"),
),
(
"typescript/wasm_enum_assertion.jinja",
include_str!("templates/typescript/wasm_enum_assertion.jinja"),
),
(
"typescript/synthetic_assertion.jinja",
include_str!("templates/typescript/synthetic_assertion.jinja"),
),
(
"typescript/visitor_method.jinja",
include_str!("templates/typescript/visitor_method.jinja"),
),
(
"typescript/test_file.jinja",
include_str!("templates/typescript/test_file.jinja"),
),
(
"typescript/test_function.jinja",
include_str!("templates/typescript/test_function.jinja"),
),
(
"typescript/snippet_body.jinja",
include_str!("templates/typescript/snippet_body.jinja"),
),
(
"typescript/helpers.jinja",
include_str!("templates/typescript/helpers.jinja"),
),
(
"typescript/http_test.jinja",
include_str!("templates/typescript/http_test.jinja"),
),
(
"typescript/cache_isolation_setup.jinja",
include_str!("templates/typescript/cache_isolation_setup.jinja"),
),
(
"typescript/http_test_skip_101.jinja",
include_str!("templates/typescript/http_test_skip_101.jinja"),
),
(
"typescript/app_harness.mjs.jinja",
include_str!("templates/typescript/app_harness.mjs.jinja"),
),
(
"typescript/globalSetup_server.ts.jinja",
include_str!("templates/typescript/globalSetup_server.ts.jinja"),
),
("go/snippet_body.jinja", include_str!("templates/go/snippet_body.jinja")),
("go/dto_literal.jinja", include_str!("templates/go/dto_literal.jinja")),
(
"go/read_file_helper.jinja",
include_str!("templates/go/read_file_helper.jinja"),
),
(
"go/empty_dto_literal.jinja",
include_str!("templates/go/empty_dto_literal.jinja"),
),
(
"python/http_test.jinja",
include_str!("templates/python/http_test.jinja"),
),
(
"python/http_101_skip.jinja",
include_str!("templates/python/http_101_skip.jinja"),
),
(
"python/app_harness.py.jinja",
include_str!("templates/python/app_harness.py.jinja"),
),
(
"elixir/app_harness.exs.jinja",
include_str!("templates/elixir/app_harness.exs.jinja"),
),
(
"elixir/snippet_body.jinja",
include_str!("templates/elixir/snippet_body.jinja"),
),
(
"elixir/http_snippet.jinja",
include_str!("templates/elixir/http_snippet.jinja"),
),
(
"elixir/test_helper_server.exs.jinja",
include_str!("templates/elixir/test_helper_server.exs.jinja"),
),
(
"elixir/test_helper_mock_server.exs.jinja",
include_str!("templates/elixir/test_helper_mock_server.exs.jinja"),
),
(
"dart/app_harness.dart.jinja",
include_str!("templates/dart/app_harness.dart.jinja"),
),
(
"dart/snippet_body.jinja",
include_str!("templates/dart/snippet_body.jinja"),
),
("dart/typed_dto.jinja", include_str!("templates/dart/typed_dto.jinja")),
(
"dart/http_snippet.jinja",
include_str!("templates/dart/http_snippet.jinja"),
),
(
"dart/void_not_error_call.jinja",
include_str!("templates/dart/void_not_error_call.jinja"),
),
(
"swift/app_harness.swift.jinja",
include_str!("templates/swift/app_harness.swift.jinja"),
),
(
"swift/snippet_body.jinja",
include_str!("templates/swift/snippet_body.jinja"),
),
(
"wasm/package.json.jinja",
include_str!("templates/wasm/package.json.jinja"),
),
(
"wasm/vitest.config.ts.jinja",
include_str!("templates/wasm/vitest.config.ts.jinja"),
),
(
"wasm/globalSetup.ts.jinja",
include_str!("templates/wasm/globalSetup.ts.jinja"),
),
("wasm/tsconfig.jinja", include_str!("templates/wasm/tsconfig.jinja")),
(
"wasm/visitor_method.jinja",
include_str!("templates/wasm/visitor_method.jinja"),
),
(
"c/stream_exhausted_branch.jinja",
include_str!("templates/c/stream_exhausted_branch.jinja"),
),
(
"zig/json_assertion.jinja",
include_str!("templates/zig/json_assertion.jinja"),
),
(
"zig/snippet_body.jinja",
include_str!("templates/zig/snippet_body.jinja"),
),
(
"zig/declared_error_branch.jinja",
include_str!("templates/zig/declared_error_branch.jinja"),
),
(
"zig/guarded_set_cwd.zig.jinja",
include_str!("templates/zig/guarded_set_cwd.zig.jinja"),
),
];
pub(crate) fn make_env() -> Environment<'static> {
let mut env = Environment::new();
env.set_trim_blocks(true);
env.set_lstrip_blocks(true);
env.set_keep_trailing_newline(true);
for (name, src) in TEMPLATES {
env.add_template(name, src).expect("built-in template is valid");
}
env
}
pub(crate) fn render(template_name: &str, ctx: minijinja::Value) -> String {
let rendered = make_env()
.get_template(template_name)
.unwrap_or_else(|_| panic!("template {template_name} not found"))
.render(ctx)
.unwrap_or_else(|e| panic!("template {template_name} failed to render: {e}"));
crate::core::keep_marker::strip_keep_markers(&rendered)
}
#[cfg(test)]
mod tests;