File: by_condition.t

package info (click to toggle)
liblatex-tom-perl 1.06-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 304 kB
  • sloc: perl: 1,787; makefile: 2
file content (39 lines) | stat: -rwxr-xr-x 709 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/perl

use strict;
use warnings;

use LaTeX::TOM;
use Test::More tests => 1;

my $parser = LaTeX::TOM->new;

my $tex = do { local $/; <DATA> };

my $tree = $parser->parse($tex);

my $nodes = $tree->getNodesByCondition(sub {
    my $node = shift;
    return (
      $node->getNodeType    eq 'COMMAND'
   && $node->getCommandName =~ /section$/
   );
});

my $count = 3;

my $ok = (
    @$nodes == $count
    && (grep { $_->getNodeType    eq 'COMMAND'  } @$nodes) == $count
    && (grep { $_->getCommandName =~ /section$/ } @$nodes) == $count
);

ok($ok, 'getNodesByCondition');

__DATA__
\documentclass[10pt]{article}
\begin{document}
\section{abc}
\subsection{def}
\subsubsection{ghi}
\end{document}