<?php

namespace nur\data\types;

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

class KeyTypeTest extends TestCase {
  function testWith() {
    $type = new KeyType();
    self::assertSame(false, $type->with(false));
    self::assertSame(null, $type->with(null));
    self::assertSame("", $type->with(""));
    self::assertSame(" ", $type->with(" "));
    self::assertSame( " abc ", $type->with(" abc "));
    self::assertSame("abc", $type->with("abc"));
    self::assertSame(-1, $type->with(-1));
    self::assertSame(0, $type->with(0));
    self::assertSame(1, $type->with(1));
    self::assertException(ValueException::class, [$type, "with"], []);
    self::assertException(ValueException::class, [$type, "with"], ["x"]);
    self::assertException(ValueException::class, [$type, "with"], 1.2);
    self::assertException(ValueException::class, [$type, "with"], true);
    self::assertException(ValueException::class, [$type, "with"], new stdClass());
  }
}
