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