<?php
namespace nur\mapper\fsv;

use nur\t\TestCase;

class Fsv2AssocMapperTest extends TestCase {
  function testMapper() {
    $source = [
      "Clain     Jephte    29061975001500000153",
      "          Francoise 29051959",
    ];
    $schema = [
      "nom" => [10, "string"],
      "prenom" => [10, "string"],
      "date_nai" => [8, "date"],
      "exact" => [6, "number", 2],
      "approx" => [6, "number"],
    ];

    $mapper = new Fsv2AssocMapper($schema, $source);
    $result = iterator_to_array($mapper);
    self::assertSame([
      [
        "nom" => "Clain",
        "prenom" => "Jephte",
        "date_nai" => "29/06/1975",
        "exact" => 15.0,
        "approx" => 153,
      ],
      [
        "nom" => "",
        "prenom" => "Francoise",
        "date_nai" => "29/05/1959",
        "exact" => false,
        "approx" => false,
      ],
    ], $result);

    $mapper = new Fsv2AssocMapper($schema, $source);
    $mapper->setOutputSeq(true);
    $result = iterator_to_array($mapper);
    self::assertSame([
      ["nom", "prenom", "date_nai", "exact", "approx"],
      ["Clain", "Jephte", "29/06/1975", 15.0, 153],
      ["", "Francoise", "29/05/1959", false, false],
    ], $result);
  }
}
