48 lines
1.6 KiB
PHP
48 lines
1.6 KiB
PHP
<?php
|
|
namespace nur;
|
|
|
|
use nur\t\TestCase;
|
|
|
|
class strTest extends TestCase {
|
|
function testSplit_pair() {
|
|
self::assertSame([null, null], str::split_pair(null));
|
|
self::assertSame([null, null], str::split_pair(false));
|
|
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 testSplit_nl() {
|
|
self::assertSame([], str::split_nl(null));
|
|
self::assertSame([], str::split_nl(false));
|
|
self::assertSame([], str::split_nl(""));
|
|
self::assertSame(["first"], str::split_nl("first"));
|
|
self::assertSame(["first"], str::split_nl("first\n"));
|
|
self::assertSame(["first", "second"], str::split_nl("first\nsecond"));
|
|
}
|
|
|
|
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"));
|
|
}
|
|
}
|