<?php
namespace nur\data\types;

use nur\b\ValueException;
use nur\t\TestCase;

class RawStringTypeTest extends TestCase {
  function testAllowedValues() {
    $t = new RawStringType(["allowed_values" => ["first", "second"]]);

    self::assertTrue($t->isInstance(null));
    self::assertFalse($t->isInstance(false));
    self::assertFalse($t->isInstance(true));
    self::assertTrue($t->isInstance("first"));
    self::assertTrue($t->isInstance("second"));
    self::assertFalse($t->isInstance("third"));

    self::assertNull($t->with(null));
    self::assertFalse($t->with(false));
    self::assertException(ValueException::class, [$t, "with"], true);
    self::assertException(ValueException::class, [$t, "with"], "  first  ");
    self::assertException(ValueException::class, [$t, "with"], "  second  ");
    self::assertException(ValueException::class, [$t, "with"], "  third  ");
  }

  function testArrayToString() {
    $t = new RawStringType();

    self::assertSame("one", $t->with("one"));
    self::assertSame("one two", $t->with(["one", "two"]));
    self::assertSame("one three", $t->with(["one", "two" => false, "three" => true]));
  }
}
