Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: match_ingredient_origin unit test #8174

Merged
merged 4 commits into from
Mar 13, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/ProductOpener/Ingredients.pm
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ BEGIN {

&has_specific_ingredient_property

&init_origins_regexps
&match_ingredient_origin

); # symbols to export on request
%EXPORT_TAGS = (all => [@EXPORT_OK]);
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job, @alexgarel! The addition of init_origins_regexps and match_ingredient_origin functions seems like a good way to address the bug cited on the pro platform. However, for production readiness, it would be good to add some documentation to these new functions and also update the existing documentation to reflect these changes. Additionally, it would be helpful to include some unit tests for these new functions to ensure they are working as expected. Overall, great work!

Expand Down
29 changes: 29 additions & 0 deletions tests/unit/match_ingredient_origin.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use ProductOpener::PerlStandards;


use Test::More;
use Log::Any::Adapter 'TAP';

use ProductOpener::Ingredients qw/match_ingredient_origin init_origins_regexps/;

my @tests = (
{
desc => "simple fr extraction",
lc => "fr",
text => "Sucre France.",
expected => {
"sucre" => "france",
},
}
);

init_origins_regexps();

foreach my $test_ref (@tests) {
my $matched_ingredients_ref = {};
match_ingredient_origin($test_ref->{lc}, \{$test_ref->{text}}, $matched_ingredients_ref);
my $expected = $test_ref->{expected};
is_deeply($matched_ingredients_ref, $expected, $test_ref->{desc}) || diag(explain({matched => $matched_ingredients_ref, expected => $expected}));
}

done_testing();
alexgarel marked this conversation as resolved.
Show resolved Hide resolved