summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rwxr-xr-xtest/exec.t2
-rwxr-xr-xtest/getopt.t3
-rwxr-xr-xtest/it.t54
-rwxr-xr-xtest/it_dbi.t37
-rw-r--r--test/it_url.testserver.php2
-rwxr-xr-xtest/it_xml.t4
6 files changed, 75 insertions, 27 deletions
diff --git a/test/exec.t b/test/exec.t
index 09e16da..04850fc 100755
--- a/test/exec.t
+++ b/test/exec.t
@@ -70,7 +70,7 @@ foreach (["", "C", "de_CH", "de_CH.utf8"] as $locale)
setlocale(LC_ALL, $locale);
$arg = "preüpost";
if (it::match('utf8', $locale))
- $arg = utf8_encode($arg);
+ $arg = it::any2utf8($arg);
is(it::exec("echo " . $arg), $arg . "\n", "exec with umlaut (locale '$locale')");
is(it::exec("echo {arg}", ['arg' => $arg]), $arg . "\n", "exec with argument and umlaut (locale '$locale')");
}
diff --git a/test/getopt.t b/test/getopt.t
index 77e52ae..380d0fd 100755
--- a/test/getopt.t
+++ b/test/getopt.t
@@ -9,6 +9,7 @@ $GLOBALS['usage'] = "Usage: doesnotexist.php [OPTIONS] POSITIONAL [VARARGS]
-a,--argument=ARG the arg argument
-d,--default=ARG an argument with default [defäult]
-0,--zero testworthy shortarg
+ -c,--comma option with comma and, -minus in the description
";
function getopt_ok($argv, $exp, $name)
@@ -26,6 +27,7 @@ foreach (["" => "blah gnaber", " (umlaute)" => "pre üäpost"] as $variant => $t
getopt_ok([$testarg, "--argument=$testarg"], $exp, "Long version with equal" . $variant);
}
+getopt_ok(['posargs', '-c'], ['args' => [], 'positional' => 'posargs', 'comma' => true, 'default' => 'defäult'], "comma and minus in description doesn't break shortopt");
$exp = ['args' => [], 'positional' => 'posarg', 'zero' => true, 'default' => 'defäult'];
getopt_ok(['posarg', '-0'], $exp, 'short argument -0 without value');
getopt_ok(['posarg', '--zero'], $exp, 'long argument --zero without value');
@@ -33,6 +35,7 @@ getopt_ok(['posarg', '-0', 'vararg'], ['args' => ['vararg']] + $exp, "additional
getopt_ok(['posarg', '--zero', 'vararg'], ['args' => ['vararg']] + $exp, "additional value after long argument --zero");
fclose(STDERR);
+getopt_ok(['posargs', '-m'], false, "comma and minus in description doesn't break shortopt 2");
getopt_ok(['posarg', '--unknown'], false, "Unknown long named argument fails");
getopt_ok(['posarg', '-u'], false, "Unknown short named argument fails");
getopt_ok([], false, "Missing positional argument fails");
diff --git a/test/it.t b/test/it.t
index 7733c00..3003ccf 100755
--- a/test/it.t
+++ b/test/it.t
@@ -221,15 +221,15 @@ _match(
);
_match(
- utf8_decode('ö'), utf8_decode('Ö'),
- utf8_decode('Ö'),
+ it::utf8_decode('ö'), it::utf8_decode('Ö'),
+ it::utf8_decode('Ö'),
'match umlaute in de_CH.latin1 case insensitive',
['utf8' => false]
);
_match(
- utf8_decode('aöBÜ'), utf8_decode('AÖbü'),
- utf8_decode('AÖbü'),
+ it::utf8_decode('aöBÜ'), it::utf8_decode('AÖbü'),
+ it::utf8_decode('AÖbü'),
"match umlaute with non-utf-8 override in p",
['utf8' => false]
);
@@ -270,6 +270,12 @@ _match(
['all' => 1, 'pattern_order' => 1]
);
+_match(
+ preg_quote('a/b!c(d\\e{f$g^h|i??**++'), 'faa/b!c(d\\e{f$g^h|i??**++ar',
+ 'a/b!c(d\\e{f$g^h|i??**++',
+ 'match with preg_quote of special characters in pattern'
+);
+
ini_set('default_charset', 'iso-8859-1');
_match(
'aöBÜ', "AÖbü",
@@ -388,7 +394,19 @@ _time("152715", it::date('', '15:27:15'));
_time("yesterday", it::date('', 'yesterday'));
is(it::date('date', '2011-10-25'), '25.10.2011', 'parse date string with strtotime');
-is(it::date('date', '2011-10-25 + 3 days'), '28.10.2011', 'some date arithmetic');
+is(it::date('date', '2011-10-25 + 3 days'), '28.10.2011', 'date arithmetic (add)');
+is(it::date('date', '2011-10-25 - 3 days'), '22.10.2011', 'date arithmetic (subtract)');
+is(it::date('date', '2011-10-25 +-3 days'), '22.10.2011', 'date arithmetic (negative value)');
+is(it::date('date', '2011-10-25 --3 days'), '28.10.2011', 'date arithmetic (double negative)');
+is(it::date('date', '2011-10-25 ++ 3 days'), '28.10.2011', 'date arithmetic (double positive with space)');
+is(it::date('date', '2011-10-25 -+ 3 days'), '22.10.2011', 'date arithmetic (negative positive with space)');
+is(it::date('datetime', '2011-10-25 +12 hours +30 minutes'), '25.10.2011 12:30', 'datetime arithmetic (hours minutes)');
+is(it::date('datetime', '2011-10-25 +24 hours +30 minutes'), '26.10.2011 00:30', 'datetime arithmetic (hours minutes over midnight)');
+is(it::date('datetime', '2011-10-25 8:00 +10 minutes'), '25.10.2011 08:10', 'time arithmetic (add)');
+is(it::date('datetime', '2011-10-25 8:00 -10 minutes'), '25.10.2011 07:50', 'time arithmetic (subtract)');
+is(it::date('datetime', '2011-10-25 8:00 +-10 minutes'), '25.10.2011 07:50', 'time arithmetic (negative value)');
+is(it::date('datetime', '2011-10-25 8:00 --10 minutes'), '25.10.2011 08:10', 'time arithmetic (double negative)');
+is(it::date('datetime', '2011-10-25 --1 month --3 days 8:00 +- 4 hours +-10 minutes'), '28.11.2011 03:50', 'date and time arithmetic (multiple signs)');
is(it::date('datetime', it::time()), it::date('datetime'), 'recognize int as timestamp');
is(it::date('datetime', it::time()*1.0), it::date('datetime'), 'recognize float as timestamp');
is(it::date('datetime', it::time() . ''), it::date('datetime'), 'recognize digit string as timestamp');
@@ -419,32 +437,32 @@ is(grapheme_strlen("\xc1"), null, "need grapheme_strlen side effect for any2utf8
is(it::any2utf8('Meier'), 'Meier', "it::any2utf8 ascii input");
is(it::any2utf8('Müller'), 'Müller', "it::any2utf8 utf8 input");
is(it::any2utf8('Aslı'), 'Aslı', "it::any2utf8 utf8 non-latin1 input");
-is(it::any2utf8(utf8_decode('Müller')), 'Müller', "it::any2utf8 latin1 input");
+is(it::any2utf8(it::utf8_decode('Müller')), 'Müller', "it::any2utf8 latin1 input");
is(it::any2utf8(
' !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ ¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ'), # omit soft hyphen cause we filter it
' !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ ¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ',
"it::any2utf8 utf8 input (exhaustive alphabet)");
is(it::any2utf8(
- utf8_decode(' !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ ¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ')),
+ it::utf8_decode(' !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ ¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ')),
' !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ ¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ',
"it::any2utf8 latin1 input (exhaustive alphabet)");
-is(it::any2utf8(utf8_encode("ü")), "ü", "it::any2utf8 double encoding");
+is(it::any2utf8(it::utf8_encode("ü")), "ü", "it::any2utf8 double encoding");
is(it::any2utf8("Meier"), "Meier", "it::any2utf8 ascii");
is(it::any2utf8("Müller"), "Müller", "it::any2utf8 utf-8 latin1");
is(it::any2utf8("Aslı"), "Aslı", "it::any2utf8 utf-8 non-latin1");
is(it::any2utf8("é»"), "é»", "it::any2utf8 utf-8 latin1 special combination");
-is(it::any2utf8(utf8_encode("Müller")), "Müller", "it::any2utf8 doubly encoded utf8");
-is(it::any2utf8(utf8_encode(utf8_encode("Müller"))), "Müller", "it::any2utf8 triply encoded utf8");
-is(it::any2utf8(utf8_decode("Müller")), "Müller", "it::any2utf8 incorrectly encoded latin1");
+is(it::any2utf8(it::utf8_encode("Müller")), "Müller", "it::any2utf8 doubly encoded utf8");
+is(it::any2utf8(it::utf8_encode(it::utf8_encode("Müller"))), "Müller", "it::any2utf8 triply encoded utf8");
+is(it::any2utf8(it::utf8_decode("Müller")), "Müller", "it::any2utf8 incorrectly encoded latin1");
is(it::any2utf8("a💚b"), "a💚b", "it::any2utf8 correctly handles 4-byte utf-8 character GREEN HEART");
-is(it::any2utf8(["foo", utf8_decode("bär")]), ["foo", "bär"], "any2utf8 on arrays");
-is(it::any2utf8(["foo", [utf8_decode("bär")]]), ["foo", ["bär"]], "any2utf8 on recursive arrays");
+is(it::any2utf8(["foo", it::utf8_decode("bär")]), ["foo", "bär"], "any2utf8 on arrays");
+is(it::any2utf8(["foo", [it::utf8_decode("bär")]]), ["foo", ["bär"]], "any2utf8 on recursive arrays");
is(it::any2utf8([1, true, false, null]), [1, true, false, null], "any2utf8 should leave types alone");
-is(it::any2utf8([utf8_decode('Müller') => utf8_decode('Müller')]), ['Müller' => 'Müller'], "it::any2utf8 latin1 keys");
+is(it::any2utf8([it::utf8_decode('Müller') => it::utf8_decode('Müller')]), ['Müller' => 'Müller'], "it::any2utf8 latin1 keys");
is(it::any2utf8("\xc2\xad"), "", "it::any2utf8 remove soft hyphens");
@@ -532,10 +550,10 @@ it::file_put($tmpfile, "bb");
is(it::file_get($tmpfile), "bb");
unlink($tmpfile);
-requesturi(utf8_decode("lüönd"), "lüönd");
-requesturi(utf8_decode("ü").utf8_encode("ü"), "üü");
-requesturi(utf8_encode("müller"), "müller");
-requesturi(utf8_encode(utf8_encode("müller")), "müller");
+requesturi(it::utf8_decode("lüönd"), "lüönd");
+requesturi(it::utf8_decode("ü").it::utf8_encode("ü"), "üü");
+requesturi(it::utf8_encode("müller"), "müller");
+requesturi(it::utf8_encode(it::utf8_encode("müller")), "müller");
requesturi("I 💚 Nü York", "I 💚 Nü York");
function requesturi($teststring, $expect)
diff --git a/test/it_dbi.t b/test/it_dbi.t
index 2b5b0c5..2a601b6 100755
--- a/test/it_dbi.t
+++ b/test/it_dbi.t
@@ -27,6 +27,7 @@ $dbi->query("create temporary table it_dbi_test (
$autoid,
x int,
y float,
+ z bigint,
foo varchar(42),
flag boolean,
$dyncols,
@@ -44,9 +45,9 @@ try {
is(it::match('syntax', $e->getMessage()), 'syntax', "Syntax error triggers error");
}
-$record->insert(['x' => 42, 'y' => 0.0001, 'foo' => null, 'flag' => 1]);
-$record->insert(['foo' => "bar", 'y' => 1e-10, 'flag' => 0]);
-$record->insert(['x' => 64738, 'y' => 1, 'foo' => "q'uux"]);
+$record->insert(['x' => 42, 'y' => 0.0001, 'z' => 0, 'foo' => null, 'flag' => 1]);
+$record->insert(['foo' => "bar", 'y' => 1e-10, 'z' => 0, 'flag' => 0]);
+$record->insert(['x' => 64738, 'y' => 1, 'z' => 0, 'foo' => "q'uux"]);
is(
$record->ID,
@@ -192,6 +193,22 @@ is(
"update with function"
);
+$value = pow(2, 24) + 1;
+$record->update(['x' => $value]);
+is($record->x, $value, "update 32bit integer without float representation");
+is($record->select(['x' => $value]), 1, "select 32bit integer without float representation");
+
+$value = pow(2, 53) + 1;
+$record->update(['z' => $value]);
+is($record->z, $value, "update 64bit integer without double representation");
+is($record->select(['z' => $value]), 1, "select 64bit integer without double representation");
+
+$record->update(['foo' => "10", 'x' => 10]);
+is($record->select(['x <' => 9]), 0, "always use integer comparision for int field");
+is($record->select(['x <' => '9']), 0, "always use integer comparision for int field");
+is($record->select(['foo <' => 9]), 1, "always use string comparision for varchar field");
+is($record->select(['foo <' => '9']), 1, "always use string comparision for varchar field");
+
$record->update(['foo' => "00"]);
$rand = $record->x;
is (
@@ -253,6 +270,14 @@ foreach (new it_dbi_test as $id => $record)
is($count, 3, "Iterator without select");
$count = 0;
+foreach (new it_dbi($db + ['table' => 'it_dbi_test']) as $id => $record)
+{
+ $count++;
+ is($record->_key, $id, "Iterator id $id (it_dbi object)");
+}
+is($count, 3, "Iterator without select (it_dbi_object)");
+
+$count = 0;
foreach (new it_dbi_test(['foo <>' => ""]) as $id => $record)
{
$count++;
@@ -489,14 +514,14 @@ $record->delete(['WHERE TRUE' ]);
$record->upsert(['ID' => 1, 'x' => 42, 'y' => 2.5, 'foo' => ['value' => "a"], 'flag' => 0]);
$record->read(1);
is($record->x, 42, 'value of x after reading with _read_postprocess');
-is($record->_data, ["ID" => 1, "x" => 42, 'y' => 2.5, 'foo' => '{"value":"a"}', 'flag' => 0], 'data after reading with _read_postprocess');
+is($record->_data, ["ID" => 1, "x" => 42, 'y' => 2.5, 'z' => NULL, 'foo' => '{"value":"a"}', 'flag' => 0], 'data after reading with _read_postprocess');
is($record->foo, ['value' => "a"], 'field after reading with _read_postprocess');
$record2 = new it_dbi_test;
$record2->read(1);
is($record2->x, 43, 'raw value of x after writing with _write_preprocess');
-is($record2->_data, ["ID" => 1, "x" => 43, 'y' => 2.5, 'foo' => '{"value":"a"}', 'flag' => 0], 'raw data after writing with _write_preprocess');
+is($record2->_data, ["ID" => 1, "x" => 43, 'y' => 2.5, 'z' => NULL, 'foo' => '{"value":"a"}', 'flag' => 0], 'raw data after writing with _write_preprocess');
$record->update(['foo' => ['value' => "b"]]);
-is($record->_data, ["ID" => 1, "x" => 42, 'y' => 2.5, 'foo' => '{"value":"b"}', 'flag' => 0], 'raw data after updating with _write_preprocess');
+is($record->_data, ["ID" => 1, "x" => 42, 'y' => 2.5, 'z' => NULL, 'foo' => '{"value":"b"}', 'flag' => 0], 'raw data after updating with _write_preprocess');
is($record->foo, ['value' => "b"], 'field data after updating with _write_preprocess');
diff --git a/test/it_url.testserver.php b/test/it_url.testserver.php
index 2d1bca4..242ccf6 100644
--- a/test/it_url.testserver.php
+++ b/test/it_url.testserver.php
@@ -42,6 +42,8 @@ switch ($_SERVER['PHP_SELF'])
break;
case "/long_sleep":
+ echo "a\n";
+ flush();
sleep(6);
echo 'Testserver output after long sleep';
break;
diff --git a/test/it_xml.t b/test/it_xml.t
index e21f052..88a5cf4 100755
--- a/test/it_xml.t
+++ b/test/it_xml.t
@@ -63,7 +63,7 @@ _match(
_match(
'<foo>x &uuml; y</foo>',
- utf8_decode('foo Object ( [val] => x ü y ) '),
+ it::utf8_decode('foo Object ( [val] => x ü y ) '),
'Manual encoding override',
"",
['encoding' => "iso-8859-1"]
@@ -77,7 +77,7 @@ _match(
_match(
'<foo>&amp;amp; &lt;a&gt; &#38;amp; &#60;b&#62; &#x26;amp; &#x3C;c&#x3E; &#xFC;</foo>',
- utf8_decode('foo Object ( [val] => &amp; <a> &amp; <b> &amp; <c> ü ) '),
+ it::utf8_decode('foo Object ( [val] => &amp; <a> &amp; <b> &amp; <c> ü ) '),
'Predecode illegal entities while keeping properly encoded ones (iso-8859-1)',
"",
['encoding' => "iso-8859-1"]