From 73466b2dce087837107c6ad6fcc076bd71ff091c Mon Sep 17 00:00:00 2001 From: Joel Natividad <1980690+jqnatividad@users.noreply.github.com> Date: Tue, 26 Nov 2024 08:18:11 -0500 Subject: [PATCH] test: lookup case sensitivity tests --- tests/test_template.rs | 47 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/tests/test_template.rs b/tests/test_template.rs index 8c531998f..f6e4d989d 100644 --- a/tests/test_template.rs +++ b/tests/test_template.rs @@ -874,3 +874,50 @@ fn template_lookup_register_errors() { nonexistent.csv:" )); } +#[test] +fn template_lookup_case_sensitivity() { + let wrk = Workdir::new("template_lookup_case"); + + // Create lookup table with mixed case values + wrk.create( + "lookup.csv", + vec![ + svec!["code", "value"], + svec!["ABC", "first"], + svec!["def", "second"], + svec!["GHI", "third"], + ], + ); + + // Create input data with different cases + wrk.create( + "data.csv", + vec![svec!["code"], svec!["abc"], svec!["DEF"], svec!["ghi"]], + ); + + // Test case-sensitive lookup (default) + let mut cmd = wrk.command("template"); + cmd.arg("--template") + .arg(concat!( + "{% if register_lookup('codes', 'lookup.csv') %}\n", + "{{code|lookup('codes', 'code', 'value')}}\n", + "{% endif %}" + )) + .arg("data.csv"); + + let got: String = wrk.stdout(&mut cmd); + assert_eq!(got, "NOT_FOUND\nNOT_FOUND\nNOT_FOUND\n"); + + // Test case-insensitive lookup + let mut cmd = wrk.command("template"); + cmd.arg("--template") + .arg(concat!( + "{% if register_lookup('codes', 'lookup.csv') %}", + "{{code|lookup('codes', 'code', 'value', false)}}\n", + "{% endif %}" + )) + .arg("data.csv"); + + let got: String = wrk.stdout(&mut cmd); + assert_eq!(got, "first\nsecond\nthird"); +}