summaryrefslogtreecommitdiff
path: root/lib/Locale/Maketext/t/04super.t
blob: 39df0bedbbf96a9f1d7eab2d855e5267595f3b0e (plain)
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

#sub Locale::Maketext::DEBUG () {10}
use Locale::Maketext;

use Test;
BEGIN { plan tests => 19 };

print "#\n# Testing non-tight insertion of super-ordinate language tags...\n#\n";

my @in = grep m/\S/, split /[\n\r]/, q{
 NIX => NIX
  sv => sv
  en => en
 hai => hai

          pt-br => pt-br pt
       pt-br fr => pt-br fr pt
    pt-br fr pt => pt-br fr pt pt
 pt-br fr pt de => pt-br fr pt de pt
 de pt-br fr pt => de pt-br fr pt pt
    de pt-br fr => de pt-br fr pt
   hai pt-br fr => hai pt-br fr  pt

# Now test multi-part complicateds:
   pt-br-janeiro fr => pt-br-janeiro fr pt-br pt 
pt-br-janeiro de fr => pt-br-janeiro de fr pt-br pt
pt-br-janeiro de pt fr => pt-br-janeiro de pt fr pt-br pt

ja    pt-br-janeiro fr => ja pt-br-janeiro fr pt-br pt 
ja pt-br-janeiro de fr => ja pt-br-janeiro de fr pt-br pt
ja pt-br-janeiro de pt fr => ja pt-br-janeiro de pt fr pt-br pt 

pt-br-janeiro de pt-br fr => pt-br-janeiro de pt-br fr pt-br pt pt
 # an odd case, since we don't filter for uniqueness in this sub
 
};

$Locale::Maketext::MATCH_SUPERS_TIGHTLY = 0;

foreach my $in (@in) {
  $in =~ s/^\s+//s;
  $in =~ s/\s+$//s;
  $in =~ s/#.+//s;
  next unless $in =~ m/\S/;
  
  my(@in, @should);
  {
    die "What kind of line is <$in>?!"
     unless $in =~ m/^(.+)=>(.+)$/s;
  
    my($i,$s) = ($1, $2);
    @in     = ($i =~ m/(\S+)/g);
    @should = ($s =~ m/(\S+)/g);
    #print "{@in}{@should}\n";
  }
  my @out = Locale::Maketext->_add_supers(
    ("@in" eq 'NIX') ? () : @in
  );
  #print "O: ", join(' ', map "<$_>", @out), "\n";
  @out = 'NIX' unless @out;

  
  if( @out == @should
      and lc( join "\e", @out ) eq lc( join "\e", @should )
  ) {
    print "#     Happily got [@out] from [$in]\n";
    ok 1;
  } else {
    ok 0;
    print "#!!Got:         [@out]\n",
          "#!! but wanted: [@should]\n",
          "#!! from \"$in\"\n#\n";
  }
}

print "#\n#\n# Bye-bye!\n";
ok 1;