[Bps-public-commit] r11079 - in Shipwright/trunk/t: .

sunnavy at bestpractical.com sunnavy at bestpractical.com
Mon Mar 17 10:44:50 EDT 2008


Author: sunnavy
Date: Mon Mar 17 10:44:18 2008
New Revision: 11079

Added:
   Shipwright/trunk/t/20.parse.t
   Shipwright/trunk/t/parse/
   Shipwright/trunk/t/parse/flags1.yml
   Shipwright/trunk/t/parse/flags2.yml
   Shipwright/trunk/t/parse/order1.yml
   Shipwright/trunk/t/parse/order2.yml

Log:
added tests for our own simple parser for yaml

Added: Shipwright/trunk/t/20.parse.t
==============================================================================
--- (empty file)
+++ Shipwright/trunk/t/20.parse.t	Mon Mar 17 10:44:18 2008
@@ -0,0 +1,71 @@
+use strict;
+use warnings;
+
+use Test::More tests => 8;    # last test to print
+
+# we don't want to include YAML lib in vessel, so we reinvent some simple
+# parsers for yaml files we use in vessel. Fortunately, what we use in vessel
+# are very simple yamls ;)
+
+use Data::Dumper;
+use Shipwright::Util;
+
+my %map = (
+    't/parse/order1.yml' => [qw/foo bar/],
+    't/parse/order2.yml' => [],
+);
+
+for my $file ( keys %map ) {
+    my $a = parse_order($file);
+    my $b = Shipwright::Util::LoadFile($file) || [];
+    is_deeply( $a, $map{$file}, 'parse_order returns right' );
+    is_deeply( $a, $b, 'parse_order returns the same as YAML' );
+}
+
+%map = (
+    't/parse/flags1.yml' => {
+        foo => [qw/a bc/],
+        bar => [qw/abc/],
+        baz => ['c'],
+    },
+
+    't/parse/flags2.yml' => {},
+);
+
+for my $file ( keys %map ) {
+    my $a = parse_flags($file);
+    my $b = Shipwright::Util::LoadFile($file) || {};
+    is_deeply( $a, $map{$file}, 'parse_order returns right' );
+    is_deeply( $a, $b, 'parse_order returns the same as YAML' );
+}
+
+sub parse_order {
+    my $file  = shift;
+    my $order = [];
+    open my $fh, '<', $file or die $!;
+    while (<$fh>) {
+        if (/^- (\S+)/) {
+            push @$order, $1;
+        }
+    }
+    return $order;
+}
+
+sub parse_flags {
+    my $file  = shift;
+    my $flags = {};
+    open my $fh, '<', $file or die $!;
+    my $dist;
+
+    while (<$fh>) {
+        if (/^(\S+):/) {
+            $dist = $1;
+            $flags->{$dist} = undef;
+        }
+        elsif (/\s+- (\S+)/) {
+            push @{ $flags->{$dist} }, $1;
+        }
+    }
+    return $flags;
+}
+

Added: Shipwright/trunk/t/parse/flags1.yml
==============================================================================
--- (empty file)
+++ Shipwright/trunk/t/parse/flags1.yml	Mon Mar 17 10:44:18 2008
@@ -0,0 +1,7 @@
+foo:
+  - a
+  - bc
+bar:
+  - abc
+baz:
+  - c

Added: Shipwright/trunk/t/parse/flags2.yml
==============================================================================

Added: Shipwright/trunk/t/parse/order1.yml
==============================================================================
--- (empty file)
+++ Shipwright/trunk/t/parse/order1.yml	Mon Mar 17 10:44:18 2008
@@ -0,0 +1,2 @@
+- foo
+- bar

Added: Shipwright/trunk/t/parse/order2.yml
==============================================================================



More information about the Bps-public-commit mailing list