<?php
namespace nulib\schema\types;

use nulib\schema\Schema;
use nur\t\TestCase;

class arrayTest extends TestCase {
  function testSchema() {
    $value = "   first    second   ";
    Schema::nw($value, null, "array");
    self::assertSame(["first", "second"], $value);

    $value = "   first    second   ";
    Schema::nw($value, null, [
      "array", "sep" => "spaces",
    ]);
    self::assertSame(["first", "second"], $value);

    $value = "   first    second   ";
    Schema::nw($value, null, [
      "array",
      "sep" => "spaces", "trim" => false,
    ]);
    self::assertSame(["", "first", "second", ""], $value);

    $value = "   first    second   ";
    Schema::nw($value, null, [
      "array",
      "sep" => "line",
    ]);
    self::assertSame(["   first    second   "], $value);

    $value = "   first    second   ";
    Schema::nw($value, null, [
      "array",
      "sep" => "line", "trim" => true,
    ]);
    self::assertSame(["first    second"], $value);
  }

  function testxxx() {
    $value = "   first    second   ";
    Schema::nw($value, null, [
      "array", "sep" => "spaces",
    ]);
    self::assertSame(["first", "second"], $value);

    # équivalent à...
    $value = "   first    second   ";
    Schema::nw($value, null, [
      "type" => ["array" => [["sep" => "spaces"]]],
      "" => ["scalar"],
    ]);
    self::assertSame(["first", "second"], $value);
  }
}
