<?php
namespace nur;

use nur\t\TestCase;

class pathTest extends TestCase {
  function testSplit() {
    self::assertSame([false, false], path::split(false));
    self::assertSame([null, null], path::split(null));
    self::assertSame(["", ""], path::split(""));
    self::assertSame(["/", "a"], path::split("/a"));
    self::assertSame(["/a", ""], path::split("/a/"));
    self::assertSame(["/a", "b"], path::split("/a/b"));
    self::assertSame(["/a/b", "c"], path::split("/a/b/c"));
    self::assertSame(["", "a"], path::split("a"));
    self::assertSame(["a", ""], path::split("a/"));
    self::assertSame(["a", "b"], path::split("a/b"));
    self::assertSame(["a/b", "c"], path::split("a/b/c"));
  }

  function testJoin() {
    self::assertNull(path::join());
    self::assertNull(path::join(null));
    self::assertNull(path::join(false));
    self::assertNull(path::join(null, null));
    self::assertNull(path::join(null, false));
    self::assertSame(".", path::join(""));
    self::assertSame("a", path::join("a", ""));
    self::assertSame("a", path::join("", "a"));
    self::assertSame("a/b", path::join("a", "b"));
    self::assertSame("a/b", path::join("a/", "b"));
    self::assertSame("a/b", path::join("a", "/b"));
    self::assertSame("a/b", path::join("a/", "/b"));
  }

  function testReljoin() {
    self::assertNull(path::reljoin());
    self::assertNull(path::reljoin(null));
    self::assertNull(path::reljoin(false));
    self::assertNull(path::reljoin(null, null));
    self::assertNull(path::reljoin(null, false));
    self::assertSame(".", path::reljoin(""));
    self::assertSame("a", path::reljoin("a", ""));
    self::assertSame("a", path::reljoin("", "a"));
    self::assertSame("a/b", path::reljoin("a", "b"));
    self::assertSame("a/b", path::reljoin("a/", "b"));
    self::assertSame("/b", path::reljoin("a", "/b"));
    self::assertSame("/b", path::reljoin("a/", "/b"));
  }

  function testEnsure_ext() {
    # non strict
    self::assertSame("a", path::ensure_ext("a", "", null));
    self::assertSame("a.x", path::ensure_ext("a", ".x", null));
    self::assertSame("a.x", path::ensure_ext("a.x", ".x", null));
    self::assertSame("a.x", path::ensure_ext("a", ".x", ".y"));
    self::assertSame("a.x", path::ensure_ext("a.x", ".x", ".y"));
    self::assertSame("a.x", path::ensure_ext("a.y", ".x", ".y"));
    self::assertSame("a.x", path::ensure_ext("a", ".x", [".y", ".z"]));
    self::assertSame("a.x", path::ensure_ext("a.x", ".x", [".y", ".z"]));
    self::assertSame("a.x", path::ensure_ext("a.y", ".x", [".y", ".z"]));
    self::assertSame("a.x", path::ensure_ext("a.z", ".x", [".y", ".z"]));
    self::assertSame("a.x", path::ensure_ext("a", ".x",   [".x", ".y", ".z"]));
    self::assertSame("a.x", path::ensure_ext("a.x", ".x", [".x", ".y", ".z"]));
    self::assertSame("a.x", path::ensure_ext("a.y", ".x", [".x", ".y", ".z"]));
    self::assertSame("a.x", path::ensure_ext("a.z", ".x", [".x", ".y", ".z"]));

    # strict
    self::assertSame("a", path::ensure_ext("a", "", null, true));
    self::assertSame("a.x", path::ensure_ext("a", ".x", null, true));
    self::assertSame("a.x.x", path::ensure_ext("a.x", ".x", null, true));
    self::assertSame("a.x", path::ensure_ext("a", ".x", ".y", true));
    self::assertSame("a.x.x", path::ensure_ext("a.x", ".x", ".y", true));
    self::assertSame("a.x", path::ensure_ext("a.y", ".x", ".y", true));
    self::assertSame("a.x", path::ensure_ext("a", ".x", [".y", ".z"], true));
    self::assertSame("a.x.x", path::ensure_ext("a.x", ".x", [".y", ".z"], true));
    self::assertSame("a.x", path::ensure_ext("a.y", ".x", [".y", ".z"], true));
    self::assertSame("a.x", path::ensure_ext("a.z", ".x", [".y", ".z"], true));
    self::assertSame("a.x", path::ensure_ext("a", ".x",   [".x", ".y", ".z"], true));
    self::assertSame("a.x", path::ensure_ext("a.x", ".x", [".x", ".y", ".z"], true));
    self::assertSame("a.x", path::ensure_ext("a.y", ".x", [".x", ".y", ".z"], true));
    self::assertSame("a.x", path::ensure_ext("a.z", ".x", [".x", ".y", ".z"], true));
  }
}
