nulib/php/tests/strTest.php

57 lines
2.1 KiB
PHP

<?php
namespace nulib;
use nulib\tests\TestCase;
class strTest extends TestCase {
function testSplit_pair() {
self::assertSame([null, null], str::split_pair(null));
self::assertSame(["", null], str::split_pair(""));
self::assertSame(["first", null], str::split_pair("first"));
self::assertSame(["first", ""], str::split_pair("first:"));
self::assertSame(["first", "second"], str::split_pair("first:second"));
self::assertSame(["first", "second:third"], str::split_pair("first:second:third"));
}
function testXxxSuffix() {
$s = "blahSUF";
self::assertTrue(str::del_suffix($s, "SUF"));
self::assertSame("blah", $s);
self::assertFalse(str::del_suffix($s, "SUF"));
self::assertTrue(str::add_suffix($s, "SUF"));
self::assertSame("blahSUF", $s);
self::assertFalse(str::add_suffix($s, "SUF"));
}
function testXxxPrefix() {
$s = "PREblah";
self::assertTrue(str::del_prefix($s, "PRE"));
self::assertSame("blah", $s);
self::assertFalse(str::del_prefix($s, "PRE"));
self::assertTrue(str::add_prefix($s, "PRE"));
self::assertSame("PREblah", $s);
self::assertFalse(str::add_prefix($s, "PRE"));
}
function testUs2camel() {
# avec délimiteur
self::assertSame("myCamel", str::us2camel("my_camel"));
self::assertSame("myCamel", str::us2camel("MY_CAMEL"));
self::assertSame("myCamel", str::us2camel("My_Camel"));
self::assertSame("myCamel", str::us2camel("mY_cAMEL"));
self::assertSame("myCamel", str::us2camel("my-camel"));
self::assertSame("myCamel", str::us2camel("my camel"));
self::assertSame("myCamel", str::us2camel("my\tcamel"));
self::assertSame("myCamel", str::us2camel("my\rcamel"));
self::assertSame("myCamel", str::us2camel("my\ncamel"));
self::assertSame("myCamel", str::us2camel("my\fcamel"));
self::assertSame("myCamel", str::us2camel("my\vcamel"));
# sans délimiteur
self::assertSame("myCamel", str::us2camel("myCamel"));
self::assertSame("MyCamel", str::us2camel("MyCamel"));
self::assertSame("MyCaMEL", str::us2camel("MyCaMEL"));
}
}