]> iEval git - data-dump-sexp.git/blame - t/Data-Dump-Sexp.t
Better tests
[data-dump-sexp.git] / t / Data-Dump-Sexp.t
CommitLineData
9336e296
MG
1#!/usr/bin/perl
2use strict;
3use warnings;
4
0babca11
MG
5use Test::More tests => 16;
6use Test::Exception;
9336e296
MG
7BEGIN { use_ok('Data::Dump::Sexp') };
8
9use Data::SExpression;
0babca11
MG
10use lib 't';
11use Opaque;
9336e296 12
0babca11
MG
13is dump_sexp(undef), '()';
14is dump_sexp([Opaque->new, 1, Opaque->new]), '(<opaque> 1 <opaque>)';
9336e296
MG
15is dump_sexp(5), 5;
16is dump_sexp('yes'), '"yes"';
17is dump_sexp('"ha\\ha\\ha"'), '"\\"ha\\\\ha\\\\ha\\""';
18is dump_sexp([1, "yes", 2]), '(1 "yes" 2)';
19is dump_sexp({b => 5, a => "yes"}), '(("a" . "yes") ("b" . 5))';
20
0babca11
MG
21is dump_sexp(\42), 42;
22is dump_sexp(\\\\"aaaa"), '"aaaa"';
23is dump_sexp(\substr "abcd", 1, 2), '"bc"';
24
25throws_ok { dump_sexp {key => sub{}} } qr/Cannot dump value of type CODE as sexp/;
26
9336e296
MG
27sub 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
34roundtrip_test 'symbol';
35roundtrip_test '(HA-HA 111 "text")';
36roundtrip_test '(cons . cell)';
37roundtrip_test '(1 2 3 . 4)';
This page took 0.021903 seconds and 4 git commands to generate.