Home | History | Annotate | Line # | Download | only in tests
format-lisp-2 revision 1.1
      1  1.1  christos #! /bin/sh
      2  1.1  christos 
      3  1.1  christos # Test checking of Lisp format strings.
      4  1.1  christos 
      5  1.1  christos tmpfiles=""
      6  1.1  christos trap 'rm -fr $tmpfiles' 1 2 3 15
      7  1.1  christos 
      8  1.1  christos tmpfiles="$tmpfiles f-l-2.data"
      9  1.1  christos cat <<\EOF > f-l-2.data
     10  1.1  christos # Valid: ~~ doesn't count
     11  1.1  christos msgid  "abc~~def"
     12  1.1  christos msgstr "xyz"
     13  1.1  christos # Invalid: invalid msgstr
     14  1.1  christos msgid  "abc~~def"
     15  1.1  christos msgstr "xyz~"
     16  1.1  christos # Valid: same argument
     17  1.1  christos msgid  "abc~Ddef"
     18  1.1  christos msgstr "xyz~D"
     19  1.1  christos # Valid: same arguments
     20  1.1  christos msgid  "abc~1000000@*~Ddef"
     21  1.1  christos msgstr "~1000000@*xyz~D"
     22  1.1  christos # Valid: permutation
     23  1.1  christos msgid  "abc~D~C~Fdef"
     24  1.1  christos msgstr "xyz~2@*~F~2:*~C~2:*~D"
     25  1.1  christos # Invalid: too few arguments
     26  1.1  christos msgid  "abc~1@*~Sdef~0@*~S"
     27  1.1  christos msgstr "xyz~S"
     28  1.1  christos # Invalid: too many arguments
     29  1.1  christos msgid  "abc~Ddef"
     30  1.1  christos msgstr "xyz~Duvw~C"
     31  1.1  christos # Invalid: missing non-final argument
     32  1.1  christos msgid  "abc~1@*~Sdef~0@*~F"
     33  1.1  christos msgstr "xyz~1@*~S"
     34  1.1  christos # Invalid: added non-final argument
     35  1.1  christos msgid  "abc~1@*~Ddef"
     36  1.1  christos msgstr "xyz~F~D"
     37  1.1  christos # Valid: formatting variations
     38  1.1  christos msgid  "abc~Sdef"
     39  1.1  christos msgstr "xyz~:S"
     40  1.1  christos # Valid: formatting variations
     41  1.1  christos msgid  "abc~4Sdef"
     42  1.1  christos msgstr "xyz~7S"
     43  1.1  christos # Valid: type compatibility
     44  1.1  christos msgid  "abc~Sdef"
     45  1.1  christos msgstr "xyz~W"
     46  1.1  christos # Valid: type compatibility
     47  1.1  christos msgid  "abc~Ddef"
     48  1.1  christos msgstr "xyz~B"
     49  1.1  christos # Valid: type compatibility
     50  1.1  christos msgid  "abc~Ddef"
     51  1.1  christos msgstr "xyz~O"
     52  1.1  christos # Valid: type compatibility
     53  1.1  christos msgid  "abc~Ddef"
     54  1.1  christos msgstr "xyz~X"
     55  1.1  christos # Valid: type compatibility
     56  1.1  christos msgid  "abc~Ddef"
     57  1.1  christos msgstr "xyz~R"
     58  1.1  christos # Valid: optional plural
     59  1.1  christos msgid  "~D egg~:P"
     60  1.1  christos msgstr "~D Eier"
     61  1.1  christos # Valid: type compatibility
     62  1.1  christos msgid  "abc~Fdef"
     63  1.1  christos msgstr "xyz~E"
     64  1.1  christos # Valid: type compatibility
     65  1.1  christos msgid  "abc~Fdef"
     66  1.1  christos msgstr "xyz~G"
     67  1.1  christos # Valid: type compatibility
     68  1.1  christos msgid  "abc~Fdef"
     69  1.1  christos msgstr "xyz~$"
     70  1.1  christos # Invalid: type incompatibility
     71  1.1  christos msgid  "abc~Fdef"
     72  1.1  christos msgstr "xyz~D"
     73  1.1  christos # Invalid: type incompatibility
     74  1.1  christos msgid  "abc~Ddef"
     75  1.1  christos msgstr "xyz~C"
     76  1.1  christos # Invalid: type incompatibility
     77  1.1  christos msgid  "abc~Fdef"
     78  1.1  christos msgstr "xyz~C"
     79  1.1  christos # Invalid: type incompatibility
     80  1.1  christos msgid  "abc~Sdef"
     81  1.1  christos msgstr "xyz~D"
     82  1.1  christos # Invalid: type incompatibility
     83  1.1  christos msgid  "abc~Sdef"
     84  1.1  christos msgstr "xyz~F"
     85  1.1  christos # Invalid: type incompatibility
     86  1.1  christos msgid  "abc~Sdef"
     87  1.1  christos msgstr "xyz~C"
     88  1.1  christos # Valid: extra formatting
     89  1.1  christos msgid  "abc~Ddef~S"
     90  1.1  christos msgstr "xyz~D~_def~%~S"
     91  1.1  christos # Valid: FORMAT-GOTO doesn't consume an argument by itself
     92  1.1  christos msgid  "abc~5@*~Ddef~C"
     93  1.1  christos msgstr "xyz~6@*~C~2@*uvw~5@*~R"
     94  1.1  christos # Invalid: @ matters
     95  1.1  christos msgid  "abc~?"
     96  1.1  christos msgstr "xyz~@?"
     97  1.1  christos # Valid: case conversion is optional
     98  1.1  christos msgid  "abc~(~S~)"
     99  1.1  christos msgstr "xyz~S"
    100  1.1  christos # Valid: case conversion is optional
    101  1.1  christos msgid  "abc~(~D~^ ~D~)"
    102  1.1  christos msgstr "xyz~D~^ ~D"
    103  1.1  christos # Invalid: ~^ matters
    104  1.1  christos msgid  "abc~(~D~^ ~D~)"
    105  1.1  christos msgstr "xyz~(~D ~D~)"
    106  1.1  christos # Valid: case conversion is optional, and it doesn't catch ~^
    107  1.1  christos msgid  "abc~(~D~^ ~D~)def~C"
    108  1.1  christos msgstr "xyz~D~^ ~Duvw~C"
    109  1.1  christos # Valid: synonymous conditionals
    110  1.1  christos msgid  "abc~@[~D~]def~C"
    111  1.1  christos msgstr "xyz~:[~;~:*~D~]~C"
    112  1.1  christos # Valid: synonymous conditionals
    113  1.1  christos msgid  "abc~Ddef"
    114  1.1  christos msgstr "abc~[null~;eins~:;~:*~D~]def"
    115  1.1  christos # Valid: conditionals are optional and don't catch ~^
    116  1.1  christos msgid  "abc~:[~;~]~^~D~C"
    117  1.1  christos msgstr "xyz~:[uvw~^~R~;~:*~S~^~D~]~C"
    118  1.1  christos # Invalid: ~:[ requires an argument, ~1@* doesn't
    119  1.1  christos msgid  "abc~1@*~^~D~C"
    120  1.1  christos msgstr "xyz~:[uvw~^~R~;~:*~S~^~D~]~C"
    121  1.1  christos # Invalid: ~{~} is special
    122  1.1  christos msgid  "abc~{ ~}"
    123  1.1  christos msgstr "xyz~{~}"
    124  1.1  christos # Invalid: @ matters
    125  1.1  christos msgid  "abc~{~S~}"
    126  1.1  christos msgstr "xyz~@{~S~}"
    127  1.1  christos # Invalid: @ matters
    128  1.1  christos msgid  "abc~:{~S~}"
    129  1.1  christos msgstr "xyz~@:{~S~}"
    130  1.1  christos # Invalid: : matters
    131  1.1  christos msgid  "abc~{~S~}"
    132  1.1  christos msgstr "xyz~:{~S~}"
    133  1.1  christos # Invalid: : matters
    134  1.1  christos msgid  "abc~@{~S~}"
    135  1.1  christos msgstr "xyz~@:{~S~}"
    136  1.1  christos # Invalid: @: matters
    137  1.1  christos msgid  "abc~{~S~}"
    138  1.1  christos msgstr "xyz~@:{~S~}"
    139  1.1  christos # Valid: permutation inside iteration
    140  1.1  christos msgid  "abc~{~D ~C~}"
    141  1.1  christos msgstr "xyz~{~1@*~C~2:*~D~1*~}"
    142  1.1  christos # Invalid: permutation inside iteration, but wrong position at iteration end
    143  1.1  christos msgid  "abc~{~D ~C~}"
    144  1.1  christos msgstr "xyz~{~1@*~C~2:*~D~}"
    145  1.1  christos # Invalid: ~^ inside iteration matters
    146  1.1  christos msgid  "abc~{~D ~^~C~}"
    147  1.1  christos msgstr "xyz~{~D ~C~}"
    148  1.1  christos # Invalid: ~^ inside iteration depends on position
    149  1.1  christos msgid  "abc~{~D ~^~C~}"
    150  1.1  christos msgstr "xyz~{~1@*~C~^~2:*~D~1*~}"
    151  1.1  christos # Invalid: ~^ inside iteration depends on position
    152  1.1  christos msgid  "abc~{~D ~^~C~}"
    153  1.1  christos msgstr "xyz~{~1@*~C~2:*~^~D~1*~}"
    154  1.1  christos # Invalid: ~^ inside iteration depends on position
    155  1.1  christos msgid  "abc~{~D ~^~C~}"
    156  1.1  christos msgstr "xyz~{~1@*~C~2:*~D~^~1*~}"
    157  1.1  christos # Invalid: ~^ inside iteration depends on position
    158  1.1  christos msgid  "abc~{~D ~^~C~}"
    159  1.1  christos msgstr "xyz~{~1@*~C~2:*~D~1*~^~}"
    160  1.1  christos # Valid: justification is optional
    161  1.1  christos msgid  "abc~<~D~;~C~>"
    162  1.1  christos msgstr "xyz~D~C"
    163  1.1  christos # Valid: justification with different segmentation
    164  1.1  christos msgid  "abc~<~D ~D~;~C~;~S~S~>"
    165  1.1  christos msgstr "xyz~<~D~;~D~C~S~;~S~>"
    166  1.1  christos # Invalid: justification catches ~^
    167  1.1  christos msgid  "abc~<~D~;~^~D~>~C"
    168  1.1  christos msgstr "abc~D~^~D~C"
    169  1.1  christos EOF
    170  1.1  christos 
    171  1.1  christos : ${MSGFMT=msgfmt}
    172  1.1  christos n=0
    173  1.1  christos while read comment; do
    174  1.1  christos   read msgid_line
    175  1.1  christos   read msgstr_line
    176  1.1  christos   n=`expr $n + 1`
    177  1.1  christos   tmpfiles="$tmpfiles f-l-2-$n.po f-l-2-$n.mo"
    178  1.1  christos   cat <<EOF > f-l-2-$n.po
    179  1.1  christos #, lisp-format
    180  1.1  christos ${msgid_line}
    181  1.1  christos ${msgstr_line}
    182  1.1  christos EOF
    183  1.1  christos   fail=
    184  1.1  christos   if echo "$comment" | grep 'Valid:' > /dev/null; then
    185  1.1  christos     if ${MSGFMT} --check-format -o f-l-2-$n.mo f-l-2-$n.po; then
    186  1.1  christos       :
    187  1.1  christos     else
    188  1.1  christos       fail=yes
    189  1.1  christos     fi
    190  1.1  christos   else
    191  1.1  christos     ${MSGFMT} --check-format -o f-l-2-$n.mo f-l-2-$n.po 2> /dev/null
    192  1.1  christos     if test $? = 1; then
    193  1.1  christos       :
    194  1.1  christos     else
    195  1.1  christos       fail=yes
    196  1.1  christos     fi
    197  1.1  christos   fi
    198  1.1  christos   if test -n "$fail"; then
    199  1.1  christos     echo "Format string checking error:" 1>&2
    200  1.1  christos     cat f-l-2-$n.po 1>&2
    201  1.1  christos     exit 1
    202  1.1  christos   fi
    203  1.1  christos   rm -f f-l-2-$n.po f-l-2-$n.mo
    204  1.1  christos done < f-l-2.data
    205  1.1  christos 
    206  1.1  christos rm -fr $tmpfiles
    207  1.1  christos 
    208  1.1  christos exit 0
    209