aboutsummaryrefslogtreecommitdiffstats
path: root/yamlishwriter-php-v0.0.1/t/lib/TestLite.php
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@redhat.com>2012-02-15 23:59:42 +0100
committerMatěj Cepl <mcepl@redhat.com>2012-02-16 00:24:01 +0100
commitd7e73ec4c238d0eb1c5493bb90c022d683123296 (patch)
treed81f22a220c40fd7528e098dd0d22060410415e0 /yamlishwriter-php-v0.0.1/t/lib/TestLite.php
downloadyamlish-d7e73ec4c238d0eb1c5493bb90c022d683123296.tar.gz
Initial commit with skeleton of the project.
Also added original Perl, together with PHP and Javascript ports.
Diffstat (limited to 'yamlishwriter-php-v0.0.1/t/lib/TestLite.php')
-rw-r--r--yamlishwriter-php-v0.0.1/t/lib/TestLite.php79
1 files changed, 79 insertions, 0 deletions
diff --git a/yamlishwriter-php-v0.0.1/t/lib/TestLite.php b/yamlishwriter-php-v0.0.1/t/lib/TestLite.php
new file mode 100644
index 0000000..231001b
--- /dev/null
+++ b/yamlishwriter-php-v0.0.1/t/lib/TestLite.php
@@ -0,0 +1,79 @@
+<?php
+
+ $NEXT_TEST = 1;
+
+ function plan($tests) {
+ print "1..$tests\n";
+ }
+
+ function ok($ok, $message = null) {
+ global $NEXT_TEST;
+ $out = "ok " . ($NEXT_TEST++);
+ if (!$ok) {
+ $out = 'not ' . $out;
+ }
+ if ($message) {
+ $out .= " $message";
+ }
+ print "$out\n";
+ }
+
+ function pass($message) {
+ ok(true, $message);
+ }
+
+ function fail($message) {
+ ok(false, $message);
+ }
+
+ function diag($message) {
+ $stdout = fopen('php://stderr', 'w');
+ fwrite( $stdout, "# $message\n" );
+ fclose( $stdout );
+ }
+
+ function is_deeply_array( $got, $expected, $message ) {
+ if ( gettype($got) != 'array' ) {
+ fail($message);
+ diag('$got is not an array');
+ return;
+ }
+
+ if ( gettype($expected) != 'array' ) {
+ fail($message);
+ diag('$expected is not an array');
+ return;
+ }
+
+ $ok = true;
+ $diag = array();
+ $got_c = count( $got );
+ $expected_c = count( $expected );
+
+ if ($got_c != $expected_c) {
+ $ok = false;
+ $diag[] = 'Array sizes differ:';
+ $diag[] = ' $got: ' . $got_c;
+ $diag[] = ' $expected: ' . $expected_c;
+ }
+
+ $count = max( $got_c, $expected_c );
+
+ for ($i = 0; $i < $count; $i++) {
+ if ( $got[$i] != $expected[$i] ) {
+ if ($ok) {
+ $ok = false;
+ $diag[] = 'Arrays differ:';
+ }
+ $diag[] = " \$got[$i]: $got[$i]";
+ $diag[] = " \$expected[$i]: $expected[$i]";
+ }
+ }
+
+ ok($ok, $message);
+ foreach ($diag as $d) {
+ diag($d);
+ }
+ }
+
+?>