]>
Commit | Line | Data |
---|---|---|
9336e296 MG |
1 | #!/usr/bin/perl |
2 | use strict; | |
3 | use warnings; | |
4 | ||
0babca11 MG |
5 | use Test::More tests => 16; |
6 | use Test::Exception; | |
9336e296 MG |
7 | BEGIN { use_ok('Data::Dump::Sexp') }; |
8 | ||
9 | use Data::SExpression; | |
0babca11 MG |
10 | use lib 't'; |
11 | use Opaque; | |
9336e296 | 12 | |
0babca11 MG |
13 | is dump_sexp(undef), '()'; |
14 | is dump_sexp([Opaque->new, 1, Opaque->new]), '(<opaque> 1 <opaque>)'; | |
9336e296 MG |
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 | ||
0babca11 MG |
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 | ||
9336e296 MG |
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); | |
0babca11 | 31 | is dump_sexp($parsed), $sexp, "roundtrip: $sexp"; |
9336e296 MG |
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)'; |