Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 15851ea2

Von Bernd Blessmann vor etwa 11 Jahren hinzugefügt

  • ID 15851ea29423c8ae9557c6a340cf9220db8e9e0d
  • Vorgänger 4b84cde9
  • Nachfolger e87f225c

Bei Boolean-Tests von is ... auf ok ... gewechselt.

nicht immer ein "my" für ein neues Csv-Objekt (copy-paste-Fehler).

Unterschiede anzeigen:

t/helper/csv.t
282 282
$csv = SL::Helper::Csv->new(
283 283
  file   => \"Description\nKaffee",
284 284
  case_insensitive_header => 1,
285
  profile => {profile => { description => 'description' }, class  => 'SL::DB::Part'},
285
  profile => [ {profile => { description => 'description' }, class  => 'SL::DB::Part'} ],
286 286
);
287 287
$csv->parse;
288 288
is_deeply $csv->get_data, [ { description => 'Kaffee' } ], 'case insensitive header from csv works';
......
291 291

  
292 292
$csv = SL::Helper::Csv->new(
293 293
  file   => \"Kaffee",
294
  header => [ 'Description' ],
295
  case_insensitive_header => 1,
296
  profile => {profile => { description => 'description' }, class  => 'SL::DB::Part'},
294
  header =>  [[ 'Description' ]],
295
  profile => [{profile => { description => 'description' }, {class  => 'SL::DB::Part'}],
297 296
);
298 297
$csv->parse;
299 298
is_deeply $csv->get_data, [ { description => 'Kaffee' } ], 'case insensitive header as param works';
......
312 311

  
313 312
$csv = SL::Helper::Csv->new(
314 313
  file   => \"Kaffee",
315
  header => [ 'Description' ],
314
  header => [[ 'Description' ]],
316 315
  profile => [{class  => 'SL::DB::Part'}],
317 316
);
318 317
$csv->parse;
319 318
is_deeply $csv->get_data, undef, 'case insensitive header without flag ignores';
320 319

  
321 320
#####
321
$csv = SL::Helper::Csv->new(
322
  file    => \"Kaffee;1,50\nSchoke;0,89\n",
323
  header  => [
324
    [ 'datatype', 'description', 'sellprice' ],
325
  ],
326
  profile => [
327
    { profile   => { sellprice => 'sellprice_as_number' },
328
      class     => 'SL::DB::Part',}
329
  ],
330
);
331

  
332
ok $csv->_check_multiplexed, 'multiplex check works on not-multiplexed data';
333
ok !$csv->is_multiplexed, 'not-multiplexed data is recognized';
322 334

  
335
#####
323 336
$csv = SL::Helper::Csv->new(
324
  file   => \"Kaffee",
325
  header => [ 'foo' ],
326
  class  => 'SL::DB::Part',
327
  profile => { foo => '' },
337
  file    => \"P;Kaffee;1,50\nC;Meier\n",
338
  header  => [
339
    [ 'datatype', 'description', 'listprice' ],
340
    [ 'datatype', 'name' ],
341
  ],
342
  profile => [
343
    { profile   => { listprice => 'listprice_as_number' },
344
      class     => 'SL::DB::Part',
345
      row_ident => 'P' },
346
    { class  => 'SL::DB::Customer',
347
      row_ident => 'C' }
348
  ],
328 349
);
329 350
$csv->parse;
330 351

  
331
is_deeply $csv->get_data, [ { foo => 'Kaffee' } ], 'empty path still gets parsed into data';
332
ok $csv->get_objects->[0], 'empty path gets ignored in object creation';
352
ok $csv->_check_multiplexed, 'multiplex check works on multiplexed data';
353
ok $csv->is_multiplexed, 'multiplexed data is recognized';
333 354

  
334 355
#####
356
$csv = SL::Helper::Csv->new(
357
  file    => \"P;Kaffee;1,50\nC;Meier\n",
358
  header  => [
359
    [ 'datatype', 'description', 'listprice' ],
360
    [ 'datatype', 'name' ],
361
  ],
362
  profile => [
363
    { profile   => { listprice => 'listprice_as_number' },
364
      class     => 'SL::DB::Part', },
365
    { class  => 'SL::DB::Customer',
366
      row_ident => 'C' }
367
  ],
368
);
369

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

  
372
#####
336 373
$csv = SL::Helper::Csv->new(
337
  file   => \"Kaffee",
338
  header => [ 'foo' ],
339
  class  => 'SL::DB::Part',
340
  strict_profile => 1,
341
  profile => { foo => '' },
374
  file    => \"P;Kaffee;1,50\nC;Meier\n",
375
  header  => [
376
    [ 'datatype', 'description', 'listprice' ],
377
    [ 'datatype', 'name' ],
378
  ],
379
  profile => [
380
    { profile   => { listprice => 'listprice_as_number' },
381
      row_ident => 'P' },
382
    { class  => 'SL::DB::Customer',
383
      row_ident => 'C' }
384
  ],
342 385
);
343 386
$csv->parse;
344 387

  
345
is_deeply $csv->get_data, [ { foo => 'Kaffee' } ], 'empty path still gets parsed into data (strict profile)';
346
ok $csv->get_objects->[0], 'empty path gets ignored in object creation (strict profile)';
388
ok !$csv->_check_multiplexed, 'multiplex check works on multiplexed data an detects missing class';
347 389

  
390
#####
348 391
$csv = SL::Helper::Csv->new(
349
  file   => \"Phil",
350
  header => [ 'CVAR_grOUnDHog' ],
351
  class  => 'SL::DB::Part',
352
  strict_profile => 1,
353
  case_insensitive_header => 1,
354
  profile => { cvar_Groundhog => '' },
392
  file    => \"P;Kaffee;1,50\nC;Meier\n",  # " # make emacs happy
393
  header  => [
394
    [ 'datatype', 'description', 'listprice' ],
395
  ],
396
  profile => [
397
    { profile   => { listprice => 'listprice_as_number' },
398
      class     => 'SL::DB::Part',
399
      row_ident => 'P' },
400
    { class  => 'SL::DB::Customer',
401
      row_ident => 'C' }
402
  ],
403
);
404

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

  
407
#####
408

  
409
$csv = SL::Helper::Csv->new(
410
  file    => \"P;Kaffee;1,50\nC;Meier\n",  # " # make emacs happy
411
  header  => [
412
    [ 'datatype', 'description', 'listprice' ],
413
    [ 'datatype', 'name' ],
414
  ],
415
  profile => [
416
    { profile   => { listprice => 'listprice_as_number' },
417
      class     => 'SL::DB::Part',
418
      row_ident => 'P' },
419
    { class  => 'SL::DB::Customer',
420
      row_ident => 'C' }
421
  ],
422
  ignore_unknown_columns => 1,
355 423
);
356 424
$csv->parse;
425
is_deeply $csv->get_data,
426
    [ { datatype => 'P', description => 'Kaffee', listprice => '1,50' }, { datatype => 'C', name => 'Meier' } ],
427
    'multiplex: simple case works';
428
is scalar @{ $csv->get_objects }, 2, 'multiplex: multiple objects work';
429
is $csv->get_objects->[0]->description, 'Kaffee', 'multiplex: first object';
430
is $csv->get_objects->[1]->name,        'Meier',  'multiplex: second object';
357 431

  
358
is_deeply $csv->get_data, [ { cvar_Groundhog => 'Phil' } ], 'using empty path to get cvars working';
359
ok $csv->get_objects->[0], '...and not destorying the objects';
432
#####
360 433

  
361 434
$csv = SL::Helper::Csv->new(
362
  file   => \"description\nKaffee",
435
  file    => \"datatype;description;listprice\ndatatype;name\nP;Kaffee;1,50\nC;Meier\n",  # " # make emacs happy
436
  profile => [
437
    { profile   => { listprice => 'listprice_as_number' },
438
      class     => 'SL::DB::Part',
439
      row_ident => 'P' },
440
    { class  => 'SL::DB::Customer',
441
      row_ident => 'C' }
442
  ],
443
  ignore_unknown_columns => 1,
363 444
);
445

  
364 446
$csv->parse;
365 447
is_deeply $csv->get_data, [ { description => 'Kaffee' } ], 'without profile and class works';
366 448

  

Auch abrufbar als: Unified diff