From 9a596f94ede4760c16615a4d4276639a8f59242f Mon Sep 17 00:00:00 2001 From: Dan Scott Date: Fri, 7 Apr 2017 14:19:22 -0400 Subject: [PATCH] LP#1680312 Ensure oils_i18n_gettext keys are unique To avoid inadvertent introduction of duplicate oils_18n_gettext() keys in the data seed SQL, which will then prevent translated strings from being able to be loaded, add a regression test. Signed-off-by: Dan Scott Signed-off-by: Ben Shum --- .../src/perlmods/t/24-sql-gettext-unique.t | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 Open-ILS/src/perlmods/t/24-sql-gettext-unique.t diff --git a/Open-ILS/src/perlmods/t/24-sql-gettext-unique.t b/Open-ILS/src/perlmods/t/24-sql-gettext-unique.t new file mode 100644 index 0000000000..5df76ce08d --- /dev/null +++ b/Open-ILS/src/perlmods/t/24-sql-gettext-unique.t @@ -0,0 +1,37 @@ +use strict; +use warnings; +use Test::More; +use Test::Output; + +my $num_tests = 0; + +my $data; +{ + open(my $fh, "<", "../sql/Pg/950.data.seed-values.sql") + or die "Can't open 950.data.seed-values.sql: $!"; + local $/ = undef; + $data = <$fh>; +} + +my $findi18n = qr/oils_i18n_gettext\((.*?)\'\s*\)/; +my $intkey = qr/\s*(\d+)\s*,\s*E?\'(.+?)\',\s*\'(.+?)\',\s*\'(.+?)$/; +my $textkey = qr/\s*\'(.*?)\'\s*,\s*E?\'(.+?)\',\s*\'(.+?)\',\s*\'(.+?)$/; + +my %found; +my @caps = $data =~ m/$findi18n/gms; +foreach my $cap (@caps) { + my $unique; + my @matches = $cap =~ m/$intkey/gms; + if (length($matches[0])) { + $unique = join('', $matches[0], $matches[2], $matches[3]); + } else { + @matches = $cap =~ m/$textkey/gms; + $unique = join('', $matches[0], $matches[2], $matches[3]); + } + isnt(exists($found{$unique}), 1, "oils_18n_gettext duplicate key: $cap'"); + $found{"$unique"} = 1; + $num_tests++; + #print "$cap \n"; +} + +done_testing($num_tests); -- 2.43.2