From: Marius Gavrilescu Date: Sat, 21 Apr 2018 11:41:01 +0000 (+0300) Subject: Better tests X-Git-Tag: 0.002~1 X-Git-Url: http://git.ieval.ro/?a=commitdiff_plain;h=0babca1182d0e16d60b96aa118a7f7c0f4d976fd;p=data-dump-sexp.git Better tests --- diff --git a/MANIFEST b/MANIFEST index 6ffc16d..9588e1c 100644 --- a/MANIFEST +++ b/MANIFEST @@ -3,4 +3,5 @@ Makefile.PL MANIFEST README t/Data-Dump-Sexp.t +t/Opaque.pm lib/Data/Dump/Sexp.pm diff --git a/Makefile.PL b/Makefile.PL index 83ebfa4..fdeef64 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -13,6 +13,9 @@ WriteMakefile( PREREQ_PM => { qw/Data::SExpression 0.41/, }, + TEST_REQUIRES => { + qw/Test::Exception 0/, + }, META_ADD => { dynamic_config => 0, resources => { diff --git a/lib/Data/Dump/Sexp.pm b/lib/Data/Dump/Sexp.pm index ad2045c..98cf565 100644 --- a/lib/Data/Dump/Sexp.pm +++ b/lib/Data/Dump/Sexp.pm @@ -153,8 +153,8 @@ procedure is restarted. =item 10 -Anything else (regexp, filehandle, format, glob, version string) -causes an exception to be raised +Anything else (coderef, regexp, filehandle, format, globref, version +string) causes an exception to be raised =back diff --git a/t/Data-Dump-Sexp.t b/t/Data-Dump-Sexp.t index 50e1b84..2fea642 100644 --- a/t/Data-Dump-Sexp.t +++ b/t/Data-Dump-Sexp.t @@ -2,22 +2,33 @@ use strict; use warnings; -use Test::More tests => 10; +use Test::More tests => 16; +use Test::Exception; BEGIN { use_ok('Data::Dump::Sexp') }; use Data::SExpression; +use lib 't'; +use Opaque; +is dump_sexp(undef), '()'; +is dump_sexp([Opaque->new, 1, Opaque->new]), '( 1 )'; is dump_sexp(5), 5; is dump_sexp('yes'), '"yes"'; is dump_sexp('"ha\\ha\\ha"'), '"\\"ha\\\\ha\\\\ha\\""'; is dump_sexp([1, "yes", 2]), '(1 "yes" 2)'; is dump_sexp({b => 5, a => "yes"}), '(("a" . "yes") ("b" . 5))'; +is dump_sexp(\42), 42; +is dump_sexp(\\\\"aaaa"), '"aaaa"'; +is dump_sexp(\substr "abcd", 1, 2), '"bc"'; + +throws_ok { dump_sexp {key => sub{}} } qr/Cannot dump value of type CODE as sexp/; + sub roundtrip_test { my ($sexp) = @_; my $ds = Data::SExpression->new({use_symbol_class => 1, fold_lists => 0}); my $parsed = $ds->read($sexp); - is dump_sexp($parsed), $sexp + is dump_sexp($parsed), $sexp, "roundtrip: $sexp"; } roundtrip_test 'symbol'; diff --git a/t/Opaque.pm b/t/Opaque.pm new file mode 100644 index 0000000..9cff7a1 --- /dev/null +++ b/t/Opaque.pm @@ -0,0 +1,7 @@ +package Opaque; + +sub new { bless {}, shift } + +sub to_sexp { Data::SExpression::Symbol->new('') } + +1