]> iEval git - data-dump-sexp.git/blob - t/Data-Dump-Sexp.t
Bump version and update Changes
[data-dump-sexp.git] / t / Data-Dump-Sexp.t
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4
5 use Test::More tests => 16;
6 use Test::Exception;
7 BEGIN { use_ok('Data::Dump::Sexp') };
8
9 use Data::SExpression;
10 use lib 't';
11 use Opaque;
12
13 is dump_sexp(undef), '()';
14 is dump_sexp([Opaque->new, 1, Opaque->new]), '(<opaque> 1 <opaque>)';
15 is dump_sexp(5), 5;
16 is dump_sexp('yes'), '"yes"';
17 is dump_sexp('"ha\\ha\\ha"'), '"\\"ha\\\\ha\\\\ha\\""';
18 is dump_sexp([1, "yes", 2]), '(1 "yes" 2)';
19 is dump_sexp({b => 5, a => "yes"}), '(("a" . "yes") ("b" . 5))';
20
21 is dump_sexp(\42), 42;
22 is dump_sexp(\\\\"aaaa"), '"aaaa"';
23 is dump_sexp(\substr "abcd", 1, 2), '"bc"';
24
25 throws_ok { dump_sexp {key => sub{}} } qr/Cannot dump value of type CODE as sexp/;
26
27 sub roundtrip_test {
28 my ($sexp) = @_;
29 my $ds = Data::SExpression->new({use_symbol_class => 1, fold_lists => 0});
30 my $parsed = $ds->read($sexp);
31 is dump_sexp($parsed), $sexp, "roundtrip: $sexp";
32 }
33
34 roundtrip_test 'symbol';
35 roundtrip_test '(HA-HA 111 "text")';
36 roundtrip_test '(cons . cell)';
37 roundtrip_test '(1 2 3 . 4)';
This page took 0.045505 seconds and 4 git commands to generate.