Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 43010559

Von Bernd Bleßmann vor fast 11 Jahren hinzugefügt

  • ID 4301055997c4d0cd963758acdb7a04ba325fa8bc
  • Vorgänger 7ec8b55e
  • Nachfolger de4b1e97

Anpassungen nach merge/rebase

Testanzahl angepasst, Schreibfehler, emacs happy

Unterschiede anzeigen:

t/helper/csv.t
1
use Test::More tests => 58;
1
use Test::More tests => 64;
2 2

  
3 3
use lib 't';
4 4
use utf8;
......
28 28
$::myconfig{dateformat} = 'dd.mm.yyyy';
29 29

  
30 30
$csv = SL::Helper::Csv->new(
31
  file    => \"Kaffee;0.12;12,2;1,5234\n",
31
  file    => \"Kaffee;0.12;12,2;1,5234\n",            # " # make emacs happy
32 32
  header  => [[ 'description', 'sellprice', 'lastcost_as_number', 'listprice' ]],
33 33
  profile => [{profile => { listprice => 'listprice_as_number' },
34 34
               class   => 'SL::DB::Part',}],
......
106 106
Kaffee;;0.12;1,221.52
107 107
Beer;1123245;0.12;1.5234
108 108
EOL
109
# " # make emacs happy
109 110
  numberformat => '1,000.00',
110 111
  profile => [{class  => 'SL::DB::Part'}],
111 112
);
......
119 120
"Kaf"fee";;0.12;1,221.52
120 121
Beer;1123245;0.12;1.5234
121 122
EOL
123
# " # make emacs happy
122 124
  numberformat => '1,000.00',
123 125
  profile => [{class  => 'SL::DB::Part'}],
124 126
);
......
270 272
#####
271 273

  
272 274
$csv = SL::Helper::Csv->new(
273
  file   => \"Kaffee",
275
  file   => \"Kaffee",       # " # make emacs happy
274 276
  header =>  [[ 'description' ]],
275 277
  profile => [{class  => 'SL::DB::Part'}],
276 278
);
......
280 282
#####
281 283

  
282 284
$csv = SL::Helper::Csv->new(
283
  file   => \"Description\nKaffee",
285
  file   => \"Description\nKaffee",        # " # make emacs happy
284 286
  case_insensitive_header => 1,
285
  profile => [ {profile => { description => 'description' }, class  => 'SL::DB::Part'} ],
287
  profile => [{
288
    profile => { description => 'description' },
289
    class  => 'SL::DB::Part'
290
  }],
286 291
);
287 292
$csv->parse;
288 293
is_deeply $csv->get_data, [ { description => 'Kaffee' } ], 'case insensitive header from csv works';
......
290 295
#####
291 296

  
292 297
$csv = SL::Helper::Csv->new(
293
  file   => \"Kaffee",
298
  file   => \"Kaffee",          # " # make emacs happy
294 299
  header =>  [[ 'Description' ]],
295
  profile => [{profile => { description => 'description' }, {class  => 'SL::DB::Part'}],
300
  case_insensitive_header => 1,
301
  profile => [{
302
    profile => { description => 'description' },
303
    class  => 'SL::DB::Part'
304
  }],
296 305
);
297 306
$csv->parse;
298 307
is_deeply $csv->get_data, [ { description => 'Kaffee' } ], 'case insensitive header as param works';
......
300 309
#####
301 310

  
302 311
$csv = SL::Helper::Csv->new(
303
  file   => \"\x{EF}\x{BB}\x{BF}description\nKaffee",
312
  file   => \"\x{EF}\x{BB}\x{BF}description\nKaffee",           # " # make emacs happy
304 313
  profile => [{class  => 'SL::DB::Part'}],
305 314
  encoding => 'utf8',
306 315
);
......
310 319
#####
311 320

  
312 321
$csv = SL::Helper::Csv->new(
313
  file   => \"Kaffee",
322
  file   => \"Kaffee",            # " # make emacs happy
314 323
  header => [[ 'Description' ]],
315 324
  profile => [{class  => 'SL::DB::Part'}],
316 325
);
317 326
$csv->parse;
318 327
is_deeply $csv->get_data, undef, 'case insensitive header without flag ignores';
319 328

  
329
#####
330

  
331
$csv = SL::Helper::Csv->new(
332
  file   => \"Kaffee",            # " # make emacs happy
333
  header => [[ 'foo' ]],
334
  profile => [{
335
    profile => { foo => '' },
336
    class  => 'SL::DB::Part',
337
  }],
338
);
339
$csv->parse;
340

  
341
is_deeply $csv->get_data, [ { foo => 'Kaffee' } ], 'empty path still gets parsed into data';
342
ok $csv->get_objects->[0], 'empty path gets ignored in object creation';
343

  
344
#####
345

  
346
$csv = SL::Helper::Csv->new(
347
  file   => \"Kaffee",            # " # make emacs happy
348
  header => [[ 'foo' ]],
349
  strict_profile => 1,
350
  profile => [{
351
    profile => { foo => '' },
352
    class  => 'SL::DB::Part',
353
  }],
354
);
355
$csv->parse;
356

  
357
is_deeply $csv->get_data, [ { foo => 'Kaffee' } ], 'empty path still gets parsed into data (strict profile)';
358
ok $csv->get_objects->[0], 'empty path gets ignored in object creation (strict profile)';
359

  
360
$csv = SL::Helper::Csv->new(
361
  file   => \"Phil",            # " # make emacs happy
362
  header => [[ 'CVAR_grOUnDHog' ]],
363
  strict_profile => 1,
364
  case_insensitive_header => 1,
365
  profile => [{
366
    profile => { cvar_Groundhog => '' },
367
    class  => 'SL::DB::Part',
368
  }],
369

  
370
);
371
$csv->parse;
372

  
373
is_deeply $csv->get_data, [ { cvar_Groundhog => 'Phil' } ], 'using empty path to get cvars working';
374
ok $csv->get_objects->[0], '...and not destorying the objects';
375

  
376
#####
377

  
378
$csv = SL::Helper::Csv->new(
379
  file   => \"description\nKaffee",            # " # make emacs happy
380
);
381
$csv->parse;
382
is_deeply $csv->get_data, [ { description => 'Kaffee' } ], 'without profile and class works';
383

  
320 384
#####
321 385
$csv = SL::Helper::Csv->new(
322 386
  file    => \"Kaffee;1,50\nSchoke;0,89\n",
......
347 411
      row_ident => 'C' }
348 412
  ],
349 413
);
350
$csv->parse;
351 414

  
352 415
ok $csv->_check_multiplexed, 'multiplex check works on multiplexed data';
353 416
ok $csv->is_multiplexed, 'multiplexed data is recognized';
......
367 430
  ],
368 431
);
369 432

  
370
ok !$csv->_check_multiplexed, 'multiplex check works on multiplexed data an detects missing row_ident';
433
ok !$csv->_check_multiplexed, 'multiplex check works on multiplexed data and detects missing row_ident';
371 434

  
372 435
#####
373 436
$csv = SL::Helper::Csv->new(
......
383 446
      row_ident => 'C' }
384 447
  ],
385 448
);
386
$csv->parse;
387 449

  
388
ok !$csv->_check_multiplexed, 'multiplex check works on multiplexed data an detects missing class';
450
ok !$csv->_check_multiplexed, 'multiplex check works on multiplexed data and detects missing class';
389 451

  
390 452
#####
391 453
$csv = SL::Helper::Csv->new(
......
402 464
  ],
403 465
);
404 466

  
405
ok !$csv->_check_multiplexed, 'multiplex check works on multiplexed data an detects missing header';
467
ok !$csv->_check_multiplexed, 'multiplex check works on multiplexed data and detects missing header';
406 468

  
407 469
#####
408 470

  
......
421 483
  ],
422 484
  ignore_unknown_columns => 1,
423 485
);
486

  
424 487
$csv->parse;
425 488
is_deeply $csv->get_data,
426 489
    [ { datatype => 'P', description => 'Kaffee', listprice => '1,50' }, { datatype => 'C', name => 'Meier' } ],
......
444 507
);
445 508

  
446 509
$csv->parse;
447
is_deeply $csv->get_data, [ { description => 'Kaffee' } ], 'without profile and class works';
510
is scalar @{ $csv->get_objects }, 2, 'multiplex: auto header works';
511
is $csv->get_objects->[0]->description, 'Kaffee', 'multiplex: auto header first object';
512
is $csv->get_objects->[1]->name,        'Meier',  'multiplex: auto header second object';
448 513

  
449 514
######
450 515

  

Auch abrufbar als: Unified diff