aboutsummaryrefslogtreecommitdiffstats
path: root/yamlishwriter-php-v0.0.1/t
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
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')
-rw-r--r--yamlishwriter-php-v0.0.1/t/00-load.php9
-rw-r--r--yamlishwriter-php-v0.0.1/t/10-writer.php180
-rw-r--r--yamlishwriter-php-v0.0.1/t/harness.t29
-rw-r--r--yamlishwriter-php-v0.0.1/t/lib/TestLite.php79
4 files changed, 297 insertions, 0 deletions
diff --git a/yamlishwriter-php-v0.0.1/t/00-load.php b/yamlishwriter-php-v0.0.1/t/00-load.php
new file mode 100644
index 0000000..afe3000
--- /dev/null
+++ b/yamlishwriter-php-v0.0.1/t/00-load.php
@@ -0,0 +1,9 @@
+<?php
+
+ error_reporting(E_ALL);
+
+ include_once('./t/lib/TestLite.php');
+
+ plan(1);
+ ok(@include_once('./lib/yamlishwriter.php'), 'include library');
+?>
diff --git a/yamlishwriter-php-v0.0.1/t/10-writer.php b/yamlishwriter-php-v0.0.1/t/10-writer.php
new file mode 100644
index 0000000..146b356
--- /dev/null
+++ b/yamlishwriter-php-v0.0.1/t/10-writer.php
@@ -0,0 +1,180 @@
+<?php
+
+ error_reporting(E_ALL);
+
+ include_once('./t/lib/TestLite.php');
+
+ $schedule = array(
+ array(
+ 'name' => 'Simple scalar',
+ 'in' => 1,
+ 'out' => array(
+ '--- 1',
+ '...',
+ ),
+ ),
+ array(
+ 'name' => 'Undef',
+ 'in' => null,
+ 'out' => array(
+ '--- ~',
+ '...',
+ ),
+ ),
+ array(
+ 'name' => 'Unprintable',
+ 'in' => "\x01\n\t",
+ 'out' => array(
+ '--- "\x01\n\t"',
+ '...',
+ ),
+ ),
+ array(
+ 'name' => 'Simple array',
+ 'in' => array( 1, 2, 3 ),
+ 'out' => array(
+ '---',
+ '- 1',
+ '- 2',
+ '- 3',
+ '...',
+ ),
+ ),
+ array(
+ 'name' => 'Array, two elements, null',
+ 'in' => array( null, null ),
+ 'out' => array(
+ '---',
+ '- ~',
+ '- ~',
+ '...',
+ ),
+ ),
+ array(
+ 'name' => 'Nested array',
+ 'in' => array( 1, 2, array( 3, 4 ), 5 ),
+ 'out' => array(
+ '---',
+ '- 1',
+ '- 2',
+ '-',
+ ' - 3',
+ ' - 4',
+ '- 5',
+ '...',
+ ),
+ ),
+ array(
+ 'name' => 'Simple hash',
+ 'in' => array( 'one' => '1', 'two' => '2', 'three' => '3' ),
+ 'out' => array(
+ '---',
+ 'one: 1',
+ 'two: 2',
+ 'three: 3',
+ '...',
+ ),
+ ),
+ array(
+ 'name' => 'Nested hash',
+ 'in' => array(
+ 'one' => '1', 'two' => '2', 'more' => array( 'three' => '3', 'four' => '4' )
+ ),
+ 'out' => array(
+ '---',
+ 'one: 1',
+ 'two: 2',
+ 'more:',
+ ' three: 3',
+ ' four: 4',
+ '...',
+ ),
+ ),
+ array(
+ 'name' => 'Unprintable key',
+ 'in' => array( 'one' => '1', "\x02" => '2', 'three' => '3' ),
+ 'out' => array(
+ '---',
+ 'one: 1',
+ '"\x02": 2',
+ 'three: 3',
+ '...',
+ ),
+ ),
+ array(
+ 'name' => 'Complex',
+ 'in' => array(
+ 'bill-to' => array(
+ 'given' => 'Chris',
+ 'address' => array(
+ 'city' => 'Royal Oak',
+ 'postal' => '48046',
+ 'lines' => "458 Walkman Dr.\nSuite #292\n",
+ 'state' => 'MI'
+ ),
+ 'family' => 'Dumars'
+ ),
+ 'invoice' => '34843',
+ 'date' => '2001-01-23',
+ 'tax' => '251.42',
+ 'product' => array(
+ array(
+ 'sku' => 'BL394D',
+ 'quantity' => '4',
+ 'price' => '450.00',
+ 'description' => 'Basketball'
+ ),
+ array(
+ 'sku' => 'BL4438H',
+ 'quantity' => '1',
+ 'price' => '2392.00',
+ 'description' => 'Super Hoop'
+ )
+ ),
+ 'comments' =>
+ "Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338\n",
+ 'total' => '4443.52'
+ ),
+ 'out' => array(
+ "---",
+ "bill-to:",
+ " given: Chris",
+ " address:",
+ " city: 'Royal Oak'",
+ " postal: 48046",
+ " lines: \"458 Walkman Dr.\\nSuite #292\\n\"",
+ " state: MI",
+ " family: Dumars",
+ "invoice: 34843",
+ "date: 2001-01-23",
+ "tax: 251.42",
+ "product:",
+ " -",
+ " sku: BL394D",
+ " quantity: 4",
+ " price: 450.00",
+ " description: Basketball",
+ " -",
+ " sku: BL4438H",
+ " quantity: 1",
+ " price: 2392.00",
+ " description: 'Super Hoop'",
+ "comments: \"Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338\\n\"",
+ "total: 4443.52",
+ "...",
+ ),
+ ),
+ );
+
+ plan( count($schedule) * 1 );
+
+ include_once('./lib/yamlishwriter.php');
+
+ foreach ($schedule as $test) {
+ $name = $test['name'];
+ $writer = new YAMLishWriter;
+ $got = $writer->write($test['in']);
+ is_deeply_array($got, $test['out'], "$name: output matches");
+ }
+
+?>
diff --git a/yamlishwriter-php-v0.0.1/t/harness.t b/yamlishwriter-php-v0.0.1/t/harness.t
new file mode 100644
index 0000000..abc51f8
--- /dev/null
+++ b/yamlishwriter-php-v0.0.1/t/harness.t
@@ -0,0 +1,29 @@
+use strict;
+use warnings;
+
+my $php = $ENV{PHP} || 'php';
+
+my $TESTS = 't/*.php';
+
+my $planned = 0;
+
+for my $test ( glob( $TESTS ) ) {
+ warn "# $test\n";
+ my $offset = $planned;
+ my @command = ( $php, $test );
+ open my $th, '-|', @command or die "Can't run $test ($?)\n";
+ while ( defined( my $line = <$th> ) ) {
+ chomp $line;
+ if ( $line =~ /^1..(\d+)/ ) {
+ $planned += $1;
+ }
+ else {
+ $line =~ s/^((?:not\s+)?ok\s+)(\d+)/$1 . ($2 + $offset)/e;
+ print "$line\n";
+ }
+ }
+ close $th or die "Can't run $test ($?)\n";
+}
+
+# Trailing plan
+print "1..$planned\n";
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);
+ }
+ }
+
+?>