File: 30_leakcheck.t

package info (click to toggle)
libcommonmark-perl 0.310100-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 220 kB
  • sloc: perl: 291; makefile: 3
file content (80 lines) | stat: -rw-r--r-- 1,819 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
use strict;
use warnings;

use constant HAS_LEAKTRACE => eval{ require Test::LeakTrace };
use Test::More HAS_LEAKTRACE ?
    (tests => 1) :
    (skip_all => 'require Test::LeakTrace');
use Test::LeakTrace;

use CommonMark qw(:node :event);

my $md = <<EOF;
normal, *emph*, **strong**
EOF

sub tree_manip {
    my $doc       = CommonMark->parse_document($md);
    my $paragraph = $doc->first_child;
    my $text      = $paragraph->first_child;
    my $emph      = $text->next;
    my $strong    = $paragraph->last_child;
    my $space     = $strong->previous;

    $doc = undef;

    my $result = CommonMark::Node->new(NODE_DOCUMENT);
    $text->unlink;
    $strong->unlink;
    $result->append_child($paragraph);
    $emph->insert_before($text);
    $space->insert_after($strong);
    $emph->replace($strong);
    $space->unlink;
}

sub iterate_list_context {
    my $doc  = CommonMark->parse_document($md);
    my $iter = $doc->iterator;
    my $sum  = 0;
    while (my ($ev_type, $node) = $iter->next) {
        $sum += $ev_type;
    }
    return $sum;
}

sub iterate_scalar_context {
    my $doc  = CommonMark->parse_document($md);
    my $iter = $doc->iterator;
    my $sum  = 0;
    while ((my $ev_type = $iter->next) != EVENT_DONE) {
        $sum += $ev_type;
    }
    return $sum;
}

sub aborted_iteration {
    my $doc  = CommonMark->parse_document($md);
    my $iter = $doc->iterator;
    my ($ev_type, $node);
    $ev_type = $iter->next;
    ($ev_type, $node) = $iter->next;
    $ev_type = $iter->next;
    ($ev_type, $node) = $iter->next;
}

sub parser {
    my $parser = CommonMark::Parser->new;
    $parser->feed("paragraph\n\n")
        for 1..5;
    $parser->finish;
}

no_leaks_ok {
    tree_manip();
    iterate_list_context();
    iterate_scalar_context();
    aborted_iteration();
    parser();
};