Better tests
authorMarius Gavrilescu <marius@ieval.ro>
Sat, 21 Apr 2018 11:41:01 +0000 (14:41 +0300)
committerMarius Gavrilescu <marius@ieval.ro>
Sat, 21 Apr 2018 11:41:01 +0000 (14:41 +0300)
MANIFEST
Makefile.PL
lib/Data/Dump/Sexp.pm
t/Data-Dump-Sexp.t
t/Opaque.pm [new file with mode: 0644]

index 6ffc16dfa1976c7467b97e60e92bca89e86d8430..9588e1cc6552cb1fe00754faa9c4561faa74a586 100644 (file)
--- 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
index 83ebfa413f52ec4b3171cc5d78b7640da29e0b04..fdeef64fd29d7f32efef8c8558e8c89e0622f2d5 100644 (file)
@@ -13,6 +13,9 @@ WriteMakefile(
        PREREQ_PM         => {
                qw/Data::SExpression 0.41/,
        },
+       TEST_REQUIRES     => {
+               qw/Test::Exception 0/,
+       },
        META_ADD          => {
                dynamic_config => 0,
                resources      => {
index ad2045c9a2749444785d22dde5c7f8e5d9039aec..98cf565e289f7775cd1dc6942c5978d84660b5b2 100644 (file)
@@ -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
 
index 50e1b84b68e4e7e8be39b55bf9c3ada712998b77..2fea642af57d1344d1f1fcee0dd70ae146b93317 100644 (file)
@@ -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]), '(<opaque> 1 <opaque>)';
 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 (file)
index 0000000..9cff7a1
--- /dev/null
@@ -0,0 +1,7 @@
+package Opaque;
+
+sub new { bless {}, shift }
+
+sub to_sexp { Data::SExpression::Symbol->new('<opaque>') }
+
+1
This page took 0.014151 seconds and 4 git commands to generate.