Commits

shl...@6a489e09-e8c2-0310-a3fb-a128a961c0b2  committed b6456ca

Fixed and completing the set-lang test.

  • Participants
  • Parent commits b7f55e8

Comments (0)

Files changed (2)

File installer/tests/set-lang-settings.pl

+#!/usr/bin/perl -w
+
+use strict;
+
+my ($dir, $global_lang, $global_charset, $local_lang, $local_charset) = @ARGV;
+
+sub add_header
+{
+    my $filename = shift;
+    my $header = shift;
+
+    open I, "<$filename";
+    my $text = join("",<I>);
+    close(I);
+
+    open O, ">$filename";
+    print O "$header\n$text";
+    close(O);
+}
+
+my $total_lang = "en-US";
+my $total_charset = "iso-8859-1";
+
+sub get_header
+{
+    my $lang = shift;
+    my $charset = shift;
+
+    if ($lang)
+    {
+        $total_lang = $lang;
+    }
+    if ($charset)
+    {
+        $total_charset = $charset;
+    }
+
+    return "#include \"wml_helpers.wml\"\n" . 
+            ($lang ? 
+                "<default-var \"lang\" \"$lang\" />\n" : 
+                ""
+            ) .
+            ($charset ? 
+                "<default-var \"charset\" \"$charset\" />\n" : 
+                ""
+            );
+}
+
+if ($global_lang || $global_charset)
+{
+    add_header(
+        "$dir/template.wml", 
+        get_header($global_lang, $global_charset),
+        );
+}
+
+if ($local_lang || $local_charset)
+{
+    add_header(
+        "$dir/src/index.html.wml", 
+        get_header($local_lang, $local_charset),
+        );    
+}
+
+print "$total_charset $total_lang\n";
+

File installer/tests/test-lang-settings.bash

 fi
 cd "in-out"
 
-# Check that the default 
-t=1
-test_dir=testlang$t 
+# Check that the default charset and lang are OK.
+t=0
+
+perform_test()
+{
+let t++
+echo "Test No. $t"
+global_to_set_lang="$1"
+shift
+global_to_set_charset="$1"
+shift
+local_to_set_lang="$1"
+shift
+local_to_set_charset="$1"
+shift
+echo "Args: \"$global_to_set_lang\" \"$global_to_set_charset\" \"$local_to_set_lang\" \"$local_to_set_charset\""
+    
+test_dir=testlang$t
 quadp setup $test_dir --dest-dir=`pwd`/${test_dir}-output
 cat > $test_dir/src/index.html.wml <<EOF
 #include 'template.wml'
 </p>
 
 EOF
+
+wanted="$(perl ../set-lang-settings.pl "$test_dir" "$global_to_set_lang" "$global_to_set_charset" "$local_to_set_lang" "$local_to_set_charset")"
+
+echo "Got \"$wanted\" as a result"
+
 (cd $test_dir && quadp render -a)
 output_file=$test_dir-output/index.html
 if ! tidy -errors $output_file ; then
-    echo "File does not validate!" 1>2 ; 
+    echo "File does not validate!" 1>&2 
     exit 
 fi
-if ! perl ../verify-lang-settings.pl iso-8859-1 en-US < $output_file ; then
-    echo "File has improper language encodings" 1>2 
+if ! perl ../verify-lang-settings.pl $wanted < $output_file ; then
+    echo "File has improper language encodings" 1>&2 
     exit
 fi
+}
 
-# TODO:
-# Write a test setting the encoding and/or language to something else
+for lang1 in "" "he-IL" ; do
+    for char1 in "" "utf-8" ; do
+        for lang2 in "" "en-GB" ; do
+            for char2 in "" "iso-8859-8" ; do
+                perform_test "$lang1" "$char1" "$lang2" "$char2"
+            done
+        done
+    done
+done
 
-exit 1
-