File: 10_writer.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 (71 lines) | stat: -rw-r--r-- 1,574 bytes parent folder | download | duplicates (4)
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
# -*- cperl -*-

use Test::More tests => 4;


use XML::TMX::Writer;
ok 1;

my $tmx = new XML::TMX::Writer();

isa_ok($tmx, "XML::TMX::Writer");

$tmx->start_tmx(id => "foobar",
                -prop => {
                          prop1 => 'val1',
                          prop2 => 'val2',
                         },
                -note => [
                          'note1', 'note2', 'note3'
                         ],
                -output => "_${$}_");

$tmx->add_tu(srclang => 'en',
             -note => ['snote1', 'snote2', 'snote3'],
             -prop => { sprop1 => 'sval1',
                        sprop2 => 'sval2' },
	     'en' => {-prop => { a=>'b',c=>'d'},
                      -note => [qw,a b c d,],
                      -seg  =>'some text', },
	     'pt' => 'algum texto');

$tmx->end_tmx();

ok(-f "_${$}_");

ok file_contents_almost_identical("t/writer1.xml", "_${$}_");

unlink "_${$}_";


sub file_contents_almost_identical {
  my ($file1, $file2) = @_;

  return 0 unless -f $file1;
  return 0 unless -f $file2;

  open F1, $file1 or die;
  open F2, $file2 or die;

  my ($l1,$l2);

  while (defined($l1 = <F1>) && defined($l2 = <F2>)) {

      s/>\s*</></g           for ($l1, $l2);
      s/(^\s*|\s*$)//g       for ($l1, $l2);
      s/"\d+T\d+Z"/"000"/    for ($l1, $l2);
      s/version="\d+\.\d+"// for ($l1, $l2);

      if ($l1 ne $l2) {
          chomp $l1;
          chomp $l2;
          print STDERR "lines differ:\nexpected {$l1}\ngot {$l2}\n";
          return 0;
      }
  }

  return 0 if <F1>;
  return 0 if <F2>;

  return 1;
}