File: 25_for_tu.t

package info (click to toggle)
libxml-tmx-perl 0.39-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 304 kB
  • sloc: perl: 1,712; xml: 115; makefile: 2
file content (58 lines) | stat: -rw-r--r-- 1,296 bytes parent folder | download | duplicates (6)
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
# -*- cperl -*-
use Data::Dumper;
use Test::More tests => 9;

BEGIN {
  use_ok(XML::TMX::Reader);
};

my $reader;

$reader = XML::TMX::Reader->new('t/sample.tmx');
ok($reader, "reading sample.tmx");

my $count = 0;
$reader->for_tu( sub {
		   my $tu = shift;
		   $count++;
		 });
is($count, 7, "counting tu's with for_tu");

$count = 0;
$reader->for_tu( {output => "t/_tmp.tmx", proc_tu => 6 },
                  sub {
		   my $tu = shift;
                   $tu->{-prop}={number => ++$count};
                   $tu;
		 });

ok( -f "t/_tmp.tmx");
#unlink( "t/_tmp.tmx");

$reader = XML::TMX::Reader->new('t/_tmp.tmx');
ok($reader,"loadind t/_tmp.tmx");

$count = 0;
$reader->for_tu( sub {
		   my $tu = shift;
		   $count++;
		 });
is($count, 6, "counting tu's with for_tu");

$reader->for_tu( {output => "t/_tmp2.tmx", gen_tu=>2},
                  sub {
                   my $tu = shift;
                   if($tu->{-prop}{number} % 2 == 0) { return undef }
                   else { $tu->{-note}[0]="This one is even";
                          return $tu;}
                 });

my @langs = $reader->languages;

is(@langs, 2 , "languages".join(",",@langs));

ok(grep { $_ eq "EN-GB" } @langs, "en");
ok(grep { $_ eq "PT-PT" } @langs, "pt");
unlink( "t/_tmp.tmx");
unlink( "t/_tmp2.tmx");