Revision a54fc392
Von Sven Schöling vor etwa 12 Jahren hinzugefügt
t/helper/csv.t | ||
---|---|---|
1 |
use Test::More tests => 41;
|
|
1 |
use Test::More tests => 47;
|
|
2 | 2 |
|
3 | 3 |
use lib 't'; |
4 |
use utf8; |
|
4 | 5 |
|
5 | 6 |
use Data::Dumper; |
6 |
use utf8;
|
|
7 |
use Support::TestSetup;
|
|
7 | 8 |
|
8 |
use_ok 'Support::TestSetup'; |
|
9 | 9 |
use_ok 'SL::Helper::Csv'; |
10 | 10 |
|
11 | 11 |
Support::TestSetup::login(); |
... | ... | |
278 | 278 |
$csv = SL::Helper::Csv->new( |
279 | 279 |
file => \"Description\nKaffee", |
280 | 280 |
class => 'SL::DB::Part', |
281 |
case_insensitive_header => 1, |
|
282 |
profile => { description => 'description' }, |
|
281 | 283 |
); |
282 | 284 |
$csv->parse; |
283 | 285 |
is_deeply $csv->get_data, [ { description => 'Kaffee' } ], 'case insensitive header from csv works'; |
... | ... | |
285 | 287 |
##### |
286 | 288 |
|
287 | 289 |
$csv = SL::Helper::Csv->new( |
288 |
file => \"Kaffee", |
|
289 |
header => [ 'Description' ], |
|
290 |
class => 'SL::DB::Part', |
|
290 |
file => \"Kaffee", |
|
291 |
header => [ 'Description' ], |
|
292 |
class => 'SL::DB::Part', |
|
293 |
case_insensitive_header => 1, |
|
294 |
profile => { description => 'description' }, |
|
291 | 295 |
); |
292 | 296 |
$csv->parse; |
293 | 297 |
is_deeply $csv->get_data, [ { description => 'Kaffee' } ], 'case insensitive header as param works'; |
... | ... | |
302 | 306 |
$csv->parse; |
303 | 307 |
is_deeply $csv->get_data, [ { description => 'Kaffee' } ], 'utf8 BOM works (bug 1872)'; |
304 | 308 |
|
309 |
##### |
|
310 |
|
|
311 |
$csv = SL::Helper::Csv->new( |
|
312 |
file => \"Kaffee", |
|
313 |
header => [ 'Description' ], |
|
314 |
class => 'SL::DB::Part', |
|
315 |
); |
|
316 |
$csv->parse; |
|
317 |
is_deeply $csv->get_data, undef, 'case insensitive header without flag ignores'; |
|
318 |
|
|
319 |
##### |
|
320 |
|
|
321 |
$csv = SL::Helper::Csv->new( |
|
322 |
file => \"Kaffee", |
|
323 |
header => [ 'foo' ], |
|
324 |
class => 'SL::DB::Part', |
|
325 |
profile => { foo => '' }, |
|
326 |
); |
|
327 |
$csv->parse; |
|
328 |
|
|
329 |
is_deeply $csv->get_data, [ { foo => 'Kaffee' } ], 'empty path still gets parsed into data'; |
|
330 |
ok $csv->get_objects->[0], 'empty path gets ignored in object creation'; |
|
331 |
|
|
332 |
##### |
|
333 |
|
|
334 |
$csv = SL::Helper::Csv->new( |
|
335 |
file => \"Kaffee", |
|
336 |
header => [ 'foo' ], |
|
337 |
class => 'SL::DB::Part', |
|
338 |
strict_profile => 1, |
|
339 |
profile => { foo => '' }, |
|
340 |
); |
|
341 |
$csv->parse; |
|
342 |
|
|
343 |
is_deeply $csv->get_data, [ { foo => 'Kaffee' } ], 'empty path still gets parsed into data (strict profile)'; |
|
344 |
ok $csv->get_objects->[0], 'empty path gets ignored in object creation (strict profile)'; |
|
345 |
|
|
346 |
$csv = SL::Helper::Csv->new( |
|
347 |
file => \"Phil", |
|
348 |
header => [ 'CVAR_grOUnDHog' ], |
|
349 |
class => 'SL::DB::Part', |
|
350 |
strict_profile => 1, |
|
351 |
case_insensitive_header => 1, |
|
352 |
profile => { cvar_Groundhog => '' }, |
|
353 |
); |
|
354 |
$csv->parse; |
|
355 |
|
|
356 |
is_deeply $csv->get_data, [ { cvar_Groundhog => 'Phil' } ], 'using empty path to get cvars working'; |
|
357 |
ok $csv->get_objects->[0], '...and not destorying the objects'; |
|
358 |
|
|
305 | 359 |
# vim: ft=perl |
Auch abrufbar als: Unified diff
Helper::Csv: Support für leere profile.path Angaben und case_insensitive_header