blob: e427bdf244f4b0cb7efa190ab0147f9b25fca9a0 [file] [log] [blame]
Helge507dd232026-04-13 18:14:20 +02001use Mojo::Base -strict;
2use Test::More;
3use Test::Mojo;
4
5# Test 1: Default foundries (no configuration)
6subtest 'Default foundries' => sub {
7 my $t = Test::Mojo->new('Kalamar');
8
9 my $defaults = $t->app->defaults('hint_foundries');
10 is_deeply(
11 $defaults,
12 [qw(base corenlp dereko malt marmot opennlp spacy tt)],
13 'Default foundries are set correctly'
14 );
15
16 # Check that data-hint-foundries is rendered in HTML
17 $t->get_ok('/')
18 ->status_is(200)
19 ->attr_like('body', 'data-hint-foundries', qr/base/)
20 ->attr_like('body', 'data-hint-foundries', qr/corenlp/)
21 ->attr_like('body', 'data-hint-foundries', qr/spacy/);
22};
23
24
25# Test 2: Custom foundries via config (inclusions only)
26subtest 'Custom foundries via config' => sub {
27 my $t = Test::Mojo->new('Kalamar' => {
28 Kalamar => {
29 hint_foundries => ['base', 'marmot', 'tt']
30 }
31 });
32
33 my $defaults = $t->app->defaults('hint_foundries');
34 is_deeply(
35 $defaults,
36 ['base', 'marmot', 'tt'],
37 'Custom foundries are set correctly'
38 );
39
40 $t->get_ok('/')
41 ->status_is(200)
42 ->attr_like('body', 'data-hint-foundries', qr/base/)
43 ->attr_like('body', 'data-hint-foundries', qr/marmot/)
44 ->attr_like('body', 'data-hint-foundries', qr/tt/)
45 ->attr_unlike('body', 'data-hint-foundries', qr/corenlp/)
46 ->attr_unlike('body', 'data-hint-foundries', qr/spacy/);
47};
48
49
50# Test 3: Exclusions via config (e.g., -spacy, -corenlp)
51subtest 'Exclusions via config' => sub {
52 my $t = Test::Mojo->new('Kalamar' => {
53 Kalamar => {
54 hint_foundries => ['-spacy', '-corenlp']
55 }
56 });
57
58 my $defaults = $t->app->defaults('hint_foundries');
59
60 # Should contain all defaults except spacy and corenlp
61 ok((grep { $_ eq 'base' } @$defaults), 'Contains base');
62 ok((grep { $_ eq 'dereko' } @$defaults), 'Contains dereko');
63 ok((grep { $_ eq 'malt' } @$defaults), 'Contains malt');
64 ok((grep { $_ eq 'marmot' } @$defaults), 'Contains marmot');
65 ok((grep { $_ eq 'opennlp' } @$defaults), 'Contains opennlp');
66 ok((grep { $_ eq 'tt' } @$defaults), 'Contains tt');
67 ok(!(grep { $_ eq 'spacy' } @$defaults), 'Does not contain spacy');
68 ok(!(grep { $_ eq 'corenlp' } @$defaults), 'Does not contain corenlp');
69
70 $t->get_ok('/')
71 ->status_is(200)
72 ->attr_like('body', 'data-hint-foundries', qr/base/)
73 ->attr_unlike('body', 'data-hint-foundries', qr/spacy/)
74 ->attr_unlike('body', 'data-hint-foundries', qr/corenlp/);
75};
76
77
78# Test 4: Environment variable KALAMAR_HINT_FOUNDRIES
79subtest 'Environment variable' => sub {
80 local $ENV{KALAMAR_HINT_FOUNDRIES} = 'base,tt,marmot';
81
82 my $t = Test::Mojo->new('Kalamar');
83
84 my $defaults = $t->app->defaults('hint_foundries');
85 is_deeply(
86 $defaults,
87 ['base', 'tt', 'marmot'],
88 'Foundries from environment variable'
89 );
90
91 $t->get_ok('/')
92 ->status_is(200)
93 ->attr_like('body', 'data-hint-foundries', qr/base,tt,marmot/);
94};
95
96
97# Test 5: Environment variable with exclusions
98subtest 'Environment variable with exclusions' => sub {
99 local $ENV{KALAMAR_HINT_FOUNDRIES} = '-spacy,-opennlp';
100
101 my $t = Test::Mojo->new('Kalamar');
102
103 my $defaults = $t->app->defaults('hint_foundries');
104
105 ok((grep { $_ eq 'base' } @$defaults), 'Contains base');
106 ok((grep { $_ eq 'corenlp' } @$defaults), 'Contains corenlp');
107 ok(!(grep { $_ eq 'spacy' } @$defaults), 'Does not contain spacy');
108 ok(!(grep { $_ eq 'opennlp' } @$defaults), 'Does not contain opennlp');
109};
110
111
112# Test 6: Environment variable overrides config
113subtest 'Environment variable overrides config' => sub {
114 local $ENV{KALAMAR_HINT_FOUNDRIES} = 'base,tt';
115
116 my $t = Test::Mojo->new('Kalamar' => {
117 Kalamar => {
118 hint_foundries => ['corenlp', 'marmot', 'spacy']
119 }
120 });
121
122 my $defaults = $t->app->defaults('hint_foundries');
123 is_deeply(
124 $defaults,
125 ['base', 'tt'],
126 'Environment variable takes precedence over config'
127 );
128};
129
130
131# Test 7: Empty config foundries array uses defaults
132subtest 'Empty config uses defaults' => sub {
133 my $t = Test::Mojo->new('Kalamar' => {
134 Kalamar => {
135 hint_foundries => []
136 }
137 });
138
139 my $defaults = $t->app->defaults('hint_foundries');
140 is_deeply(
141 $defaults,
142 [qw(base corenlp dereko malt marmot opennlp spacy tt)],
143 'Empty array results in defaults'
144 );
145};
146
147
148# Test 8: Case insensitivity of exclusions
149subtest 'Case insensitive exclusions' => sub {
150 my $t = Test::Mojo->new('Kalamar' => {
151 Kalamar => {
152 hint_foundries => ['-SPACY', '-CoreNLP']
153 }
154 });
155
156 my $defaults = $t->app->defaults('hint_foundries');
157
158 ok(!(grep { lc($_) eq 'spacy' } @$defaults), 'Does not contain spacy (case insensitive)');
159 ok(!(grep { lc($_) eq 'corenlp' } @$defaults), 'Does not contain corenlp (case insensitive)');
160 ok((grep { $_ eq 'base' } @$defaults), 'Still contains base');
161};
162
163
164done_testing;
165__END__