[Rt-commit] r3734 - in Data-ICal: . lib/Data t
alexmv at bestpractical.com
alexmv at bestpractical.com
Tue Aug 30 01:40:17 EDT 2005
Author: alexmv
Date: Tue Aug 30 01:40:17 2005
New Revision: 3734
Added:
Data-ICal/t/07.roundtrip.t
Modified:
Data-ICal/ (props changed)
Data-ICal/lib/Data/ICal.pm
Log:
r6153 at zoq-fot-pik: chmrr | 2005-08-30 01:40:02 -0400
* Fix parsing so it round trips correctly; Text::vFile doesn't want
trailing newlines
Modified: Data-ICal/lib/Data/ICal.pm
==============================================================================
--- Data-ICal/lib/Data/ICal.pm (original)
+++ Data-ICal/lib/Data/ICal.pm Tue Aug 30 01:40:17 2005
@@ -106,17 +106,15 @@
my @lines;
+ # open the file (checking as we go, like good little Perl mongers)
if ( defined $args{filename} ) {
open my $fh, '<', $args{filename} or return;
- @lines = <$fh>;
+ @lines = map {chomp; $_} <$fh>;
} else {
-
- # This regexp splits after newlines, but keeps them in the string, kind
- # of like <$fh> does.
- @lines = split /^/m, $args{data};
+ @lines = split /\n/, $args{data};
}
- # open the file (checking as we go, like good little Perl mongers)
+ # Parse the lines; Text::vFile doesn't want trailing newlines
my $cal = Text::vFile::asData->new->parse_lines(@lines);
return unless $cal and exists $cal->{objects};
Added: Data-ICal/t/07.roundtrip.t
==============================================================================
--- (empty file)
+++ Data-ICal/t/07.roundtrip.t Tue Aug 30 01:40:17 2005
@@ -0,0 +1,32 @@
+#!/usr/bin/perl -w
+
+use warnings;
+use strict;
+
+use Test::More tests => 7;
+use Test::LongString;
+use Test::NoWarnings; # this catches our warnings like setting unknown properties
+
+BEGIN { use_ok('Data::ICal'); }
+BEGIN { use_ok('Data::ICal::Entry::Todo'); }
+
+my $cal = Data::ICal->new();
+my $vtodo = Data::ICal::Entry::Todo->new();
+$vtodo->add_properties(
+ summary => "Some summary",
+ url => "http://example.com/todo",
+ status => "INCOMPLETE",
+);
+$cal->add_entry($vtodo);
+my $before = $cal->as_string;
+
+$cal = Data::ICal->new( data => $before );
+is($cal->as_string, $before, "Round trip works through string");
+
+ok(open(ICS, ">t/ics/roundtrip.ics"), "Wrote t/ics/roundtrip.ics");
+print ICS $before;
+close ICS;
+
+$cal = Data::ICal->new( filename => "t/ics/roundtrip.ics" );
+is($cal->as_string, $before, "Round trip works through file");
+ok(unlink("t/ics/roundtrip.ics"), "File t/ics/roundtrip.ics removed");
More information about the Rt-commit
mailing list