Home | History | Annotate | Line # | Download | only in tests
      1  1.1  christos #! /bin/sh
      2  1.1  christos 
      3  1.1  christos # Test recognition 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-1.data"
      9  1.1  christos cat <<\EOF > f-l-1.data
     10  1.1  christos # Valid: no argument, ( | . *)
     11  1.1  christos "abc~~def"
     12  1.1  christos # Valid: one argument, (* | . *)
     13  1.1  christos "abc~Sdef"
     14  1.1  christos # Valid: 11 arguments, (* * * * * * * * * * * | . *)
     15  1.1  christos "abc~10@*~Sdef"
     16  1.1  christos # Invalid: unterminated
     17  1.1  christos "abc~~def~"
     18  1.1  christos # Invalid: unterminated
     19  1.1  christos "abc~~def~1"
     20  1.1  christos # Invalid: unterminated
     21  1.1  christos "abc~~def~:"
     22  1.1  christos # Invalid: unterminated
     23  1.1  christos "abc~~def~@"
     24  1.1  christos # Valid: colon
     25  1.1  christos "abc~:Sdef"
     26  1.1  christos # Valid: atsign
     27  1.1  christos "abc~@Sdef"
     28  1.1  christos # Valid: colon and atsign
     29  1.1  christos "abc~:@Sdef"
     30  1.1  christos # Valid: atsign and colon
     31  1.1  christos "abc~@:Sdef"
     32  1.1  christos # Valid: params before atsign and colon
     33  1.1  christos "abc~3,-4,,'*@:Sdef"
     34  1.1  christos # Invalid: params after atsign and colon
     35  1.1  christos "abc~@:3,-4Sdef"
     36  1.1  christos # Invalid: params after atsign and colon
     37  1.1  christos "abc~@:-4Sdef"
     38  1.1  christos # Invalid: params after atsign and colon
     39  1.1  christos "abc~@:,-4Sdef"
     40  1.1  christos # Valid: V and # params, (i() * | . *)
     41  1.1  christos "abc~#,vSdef"
     42  1.1  christos # Invalid: wrong type params
     43  1.1  christos "abc~,'*Sdef"
     44  1.1  christos # Valid: FORMAT-ASCII, (i() i() i() c() * | . *)
     45  1.1  christos "abc~v,v,v,vA"
     46  1.1  christos # Invalid: too many params
     47  1.1  christos "abc~v,v,v,v,5A"
     48  1.1  christos # Valid: FORMAT-S-EXPRESSION, (i() i() i() c() * | . *)
     49  1.1  christos "abc~v,v,v,vS"
     50  1.1  christos # Invalid: too many params
     51  1.1  christos "abc~v,v,v,v,5S"
     52  1.1  christos # Valid: FORMAT-WRITE, (* | . *)
     53  1.1  christos "abc~W"
     54  1.1  christos # Invalid: too many params
     55  1.1  christos "abc~3W"
     56  1.1  christos # Valid: FORMAT-DECIMAL, (i() c() c() i() i | . *)
     57  1.1  christos "abc~v,v,v,vD"
     58  1.1  christos # Invalid: too many params
     59  1.1  christos "abc~v,v,v,v,5D"
     60  1.1  christos # Valid: FORMAT-BINARY, (i() c() c() i() i | . *)
     61  1.1  christos "abc~v,v,v,vB"
     62  1.1  christos # Invalid: too many params
     63  1.1  christos "abc~v,v,v,v,5B"
     64  1.1  christos # Valid: FORMAT-OCTAL, (i() c() c() i() i | . *)
     65  1.1  christos "abc~v,v,v,vO"
     66  1.1  christos # Invalid: too many params
     67  1.1  christos "abc~v,v,v,v,5O"
     68  1.1  christos # Valid: FORMAT-HEXADECIMAL, (i() c() c() i() i | . *)
     69  1.1  christos "abc~v,v,v,vX"
     70  1.1  christos # Invalid: too many params
     71  1.1  christos "abc~v,v,v,v,5X"
     72  1.1  christos # Valid: FORMAT-RADIX, (i() i() c() c() i() i | . *)
     73  1.1  christos "abc~v,v,v,v,vR"
     74  1.1  christos # Invalid: too many params
     75  1.1  christos "abc~v,v,v,v,v,5R"
     76  1.1  christos # Valid: FORMAT-PLURAL, (* | . *)
     77  1.1  christos "abc~P"
     78  1.1  christos # Valid: FORMAT-PLURAL, (i | . *)
     79  1.1  christos "abc~R egg~:P"
     80  1.1  christos # Invalid: too many params
     81  1.1  christos "abc~2P"
     82  1.1  christos # Valid: FORMAT-CHARACTER, (c | . *)
     83  1.1  christos "abc~C"
     84  1.1  christos # Invalid: too many params
     85  1.1  christos "abc~4C"
     86  1.1  christos # Valid: FORMAT-FIXED-FLOAT, (i() i() i() c() c() r | . *)
     87  1.1  christos "abc~v,v,v,v,vF"
     88  1.1  christos # Invalid: too many params
     89  1.1  christos "abc~v,v,v,v,v,5F"
     90  1.1  christos # Valid: FORMAT-EXPONENTIAL-FLOAT, (i() i() i() i() c() c() c() r | . *)
     91  1.1  christos "abc~v,v,v,v,v,v,vE"
     92  1.1  christos # Invalid: too many params
     93  1.1  christos "abc~v,v,v,v,v,v,v,5E"
     94  1.1  christos # Valid: FORMAT-GENERAL-FLOAT, (i() i() i() i() c() c() c() r | . *)
     95  1.1  christos "abc~v,v,v,v,v,v,vG"
     96  1.1  christos # Invalid: too many params
     97  1.1  christos "abc~v,v,v,v,v,v,v,5G"
     98  1.1  christos # Valid: FORMAT-DOLLARS-FLOAT, (i() i() i() c() r | . *)
     99  1.1  christos "abc~v,v,v,v$"
    100  1.1  christos # Invalid: too many params
    101  1.1  christos "abc~v,v,v,v,5$"
    102  1.1  christos # Valid: FORMAT-TERPRI, (i() | . *)
    103  1.1  christos "abc~v%"
    104  1.1  christos # Invalid: too many params
    105  1.1  christos "abc~v,5%"
    106  1.1  christos # Valid: FORMAT-FRESH-LINE, (i() | . *)
    107  1.1  christos "abc~v&"
    108  1.1  christos # Invalid: too many params
    109  1.1  christos "abc~v,5&"
    110  1.1  christos # Valid: FORMAT-PAGE, (i() | . *)
    111  1.1  christos "abc~v|"
    112  1.1  christos # Invalid: too many params
    113  1.1  christos "abc~v,5|"
    114  1.1  christos # Valid: FORMAT-TILDE, (i() | . *)
    115  1.1  christos "abc~v~"
    116  1.1  christos # Invalid: too many params
    117  1.1  christos "abc~v,5~"
    118  1.1  christos # Valid: underscore, ( | . *)
    119  1.1  christos "abc~_"
    120  1.1  christos # Invalid: too many params
    121  1.1  christos "abc~5_"
    122  1.1  christos # Valid: FORMAT-TABULATE, (i() i() | . *)
    123  1.1  christos "abc~v,vT"
    124  1.1  christos # Invalid: too many params
    125  1.1  christos "abc~v,v,5T"
    126  1.1  christos # Valid: FORMAT-GOTO absolute, (* r c | . *)
    127  1.1  christos "abc~S~F~S~2@*~C"
    128  1.1  christos # Invalid: type incompatibility
    129  1.1  christos "abc~S~F~S~1@*~C"
    130  1.1  christos # Valid: FORMAT-GOTO backward, (* c r | . *)
    131  1.1  christos "abc~S~S~F~2:*~C"
    132  1.1  christos # Invalid: type incompatibility
    133  1.1  christos "abc~S~S~F~1:*~C"
    134  1.1  christos # Invalid: too many params
    135  1.1  christos "abc~v,4*"
    136  1.1  christos # Valid: FORMAT-GOTO with large number
    137  1.1  christos "abc~S~F~S~1000000@*~C"
    138  1.1  christos # Valid: FORMAT-INDIRECTION, (~ ( | . *) | . *)
    139  1.1  christos "abc~?"
    140  1.1  christos # Valid: FORMAT-INDIRECTION, (~ | . *)
    141  1.1  christos "abc~@?"
    142  1.1  christos # Invalid: too many params
    143  1.1  christos "abc~4?"
    144  1.1  christos # Valid: FORMAT-CALL-USER-FUNCTION, (* | . *)
    145  1.1  christos "abc~/FOOBAR/"
    146  1.1  christos # Invalid: too many params
    147  1.1  christos "abc~4/FOOBAR/"
    148  1.1  christos # Invalid: unterminated
    149  1.1  christos "abc~/FOOB"
    150  1.1  christos # Invalid: nesting mismatch
    151  1.1  christos "abc~(~/FOOB~)/"
    152  1.1  christos # Valid: FORMAT-CASE-CONVERSION, (* | . *)
    153  1.1  christos "abc~(~S~)"
    154  1.1  christos # Invalid: too many params
    155  1.1  christos "abc~4(~S~)"
    156  1.1  christos # Invalid: too many params
    157  1.1  christos "abc~(~S~4)"
    158  1.1  christos # Invalid: unterminated
    159  1.1  christos "abc~(~S"
    160  1.1  christos # Invalid: separator
    161  1.1  christos "abc~(~S~;~S~)"
    162  1.1  christos # Valid: FORMAT-CONDITIONAL, (i() c | . *)
    163  1.1  christos "abc~@[~D~]~C"
    164  1.1  christos # Valid: FORMAT-CONDITIONAL, (i() | . *)
    165  1.1  christos "abc~@[~D~D~]~C"
    166  1.1  christos # Invalid: separator
    167  1.1  christos "abc~@[~D~;~D~]~C"
    168  1.1  christos # Valid: FORMAT-CONDITIONAL, (* i c | . *)
    169  1.1  christos "abc~:[~X~;~D~]~C"
    170  1.1  christos # Invalid: missing separator
    171  1.1  christos "abc~:[~D~]~C"
    172  1.1  christos # Invalid: too many separators
    173  1.1  christos "abc~:[~X~;~D~;~E~]~C"
    174  1.1  christos # Valid: FORMAT-CONDITIONAL, (* | . *)
    175  1.1  christos "abc~[~D~;~X~]~C"
    176  1.1  christos # Valid: FORMAT-CONDITIONAL, (* i c | . *)
    177  1.1  christos "abc~[~D~;~X~:;~R~]~C"
    178  1.1  christos # Invalid: default clause not last
    179  1.1  christos "abc~[~D~;~X~:;~R~;~R~]~C"
    180  1.1  christos # Invalid: too many params
    181  1.1  christos "abc~4@[~D~]"
    182  1.1  christos # Invalid: too many params
    183  1.1  christos "abc~@[~D~4]"
    184  1.1  christos # Invalid: too many params
    185  1.1  christos "abc~4:[~D~;~X~]"
    186  1.1  christos # Invalid: too many params
    187  1.1  christos "abc~:[~D~4;~X~]"
    188  1.1  christos # Invalid: too many params
    189  1.1  christos "abc~:[~D~;~X~4]"
    190  1.1  christos # Valid: FORMAT-CONDITIONAL, one param, without colon or atsign
    191  1.1  christos "abc~4[~D~;~X~]"
    192  1.1  christos # Invalid: too many params
    193  1.1  christos "abc~4,4[~D~;~X~]"
    194  1.1  christos # Invalid: too many params
    195  1.1  christos "abc~[~D~4;~X~]"
    196  1.1  christos # Invalid: too many params
    197  1.1  christos "abc~[~D~;~X~4]"
    198  1.1  christos # Valid: FORMAT-ITERATION, (( | . *) | . *)
    199  1.1  christos "abc~{~~~}"
    200  1.1  christos # Valid: FORMAT-ITERATION, (( | . ( | . *)) | . *)
    201  1.1  christos "abc~:{~~~}"
    202  1.1  christos # Valid: FORMAT-ITERATION, ( | . *)
    203  1.1  christos "abc~@{~~~}"
    204  1.1  christos # Valid: FORMAT-ITERATION, ( | . ( | . *))
    205  1.1  christos "abc~:@{~~~}"
    206  1.1  christos # Valid: FORMAT-ITERATION with indirection, (~ ( | . *) | . *)
    207  1.1  christos "abc~{~}"
    208  1.1  christos # Valid: FORMAT-ITERATION with indirection, (~ ( | . ( | . *)) | . *)
    209  1.1  christos "abc~:{~}"
    210  1.1  christos # Valid: FORMAT-ITERATION with indirection, (~ | . *)
    211  1.1  christos "abc~@{~}"
    212  1.1  christos # Valid: FORMAT-ITERATION with indirection, (~ | . ( | . *))
    213  1.1  christos "abc~:@{~}"
    214  1.1  christos # Valid: FORMAT-ITERATION with loop, (( | . i c) | . *)
    215  1.1  christos "abc~{~D ~C~}"
    216  1.1  christos # Valid: FORMAT-ITERATION with loop, (( | . (i c | . *)) | . *)
    217  1.1  christos "abc~:{~D ~C~}"
    218  1.1  christos # Valid: FORMAT-ITERATION with loop, ( | . i c)
    219  1.1  christos "abc~@{~D ~C~}"
    220  1.1  christos # Valid: FORMAT-ITERATION with loop, ( | . (i c | . *))
    221  1.1  christos "abc~:@{~D ~C~}"
    222  1.1  christos # Valid: FORMAT-ITERATION with variable-advance loop, (( | . *) | . *)
    223  1.1  christos "abc~{~[~D~]~}"
    224  1.1  christos # Valid: FORMAT-ITERATION with variable-advance loop, (( | . (* | . *)) | . *)
    225  1.1  christos "abc~:{~[~D~]~}"
    226  1.1  christos # Valid: FORMAT-ITERATION with variable-advance loop, ( | . *)
    227  1.1  christos "abc~@{~[~D~]~}"
    228  1.1  christos # Valid: FORMAT-ITERATION with variable-advance loop, ( | . (* | . *))
    229  1.1  christos "abc~:@{~[~D~]~}"
    230  1.1  christos # Invalid: separator
    231  1.1  christos "abc~{~D~;~C~}"
    232  1.1  christos # Valid: FORMAT-JUSTIFICATION, (i() i() i() c() i | . *)
    233  1.1  christos "abc~v,v,v,v<~D~>"
    234  1.1  christos # Invalid: too many params
    235  1.1  christos "abc~v,v,v,v,4<~D~>"
    236  1.1  christos # Valid: separators
    237  1.1  christos "abc~<~D~;~X~;def~>"
    238  1.1  christos # Invalid: wrongly nested
    239  1.1  christos "abc~<~(~>~)"
    240  1.1  christos # Invalid: wrongly nested
    241  1.1  christos "abc~{~(~}~)"
    242  1.1  christos # Invalid: wrongly nested
    243  1.1  christos "abc~{~<~}~>"
    244  1.1  christos # Valid: FORMAT-CALL, (f * | . *)
    245  1.1  christos "abc~!"
    246  1.1  christos # Valid: any number of arguments
    247  1.1  christos "abc~v,v,v,v,v!"
    248  1.1  christos # Invalid: type incompatibility between integer and list
    249  1.1  christos "abc~D~:*~{~D~}"
    250  1.1  christos # Invalid: type incompatibility between real and list
    251  1.1  christos "abc~{~S~}~:*~F"
    252  1.1  christos # Valid: list must be empty
    253  1.1  christos "abc~{~C~}~:*~{~D~}"
    254  1.1  christos EOF
    255  1.1  christos 
    256  1.1  christos : ${XGETTEXT=xgettext}
    257  1.1  christos n=0
    258  1.1  christos while read comment; do
    259  1.1  christos   read string
    260  1.1  christos   n=`expr $n + 1`
    261  1.1  christos   tmpfiles="$tmpfiles f-l-1-$n.in f-l-1-$n.po"
    262  1.1  christos   cat <<EOF > f-l-1-$n.in
    263  1.1  christos (gettext ${string})
    264  1.1  christos EOF
    265  1.1  christos   ${XGETTEXT} -L Lisp -o f-l-1-$n.po f-l-1-$n.in || exit 1
    266  1.1  christos   test -f f-l-1-$n.po || exit 1
    267  1.1  christos   fail=
    268  1.1  christos   if echo "$comment" | grep 'Valid:' > /dev/null; then
    269  1.1  christos     if grep lisp-format f-l-1-$n.po > /dev/null; then
    270  1.1  christos       :
    271  1.1  christos     else
    272  1.1  christos       fail=yes
    273  1.1  christos     fi
    274  1.1  christos   else
    275  1.1  christos     if grep lisp-format f-l-1-$n.po > /dev/null; then
    276  1.1  christos       fail=yes
    277  1.1  christos     else
    278  1.1  christos       :
    279  1.1  christos     fi
    280  1.1  christos   fi
    281  1.1  christos   if test -n "$fail"; then
    282  1.1  christos     echo "Format string recognition error:" 1>&2
    283  1.1  christos     cat f-l-1-$n.in 1>&2
    284  1.1  christos     echo "Got:" 1>&2
    285  1.1  christos     cat f-l-1-$n.po 1>&2
    286  1.1  christos     exit 1
    287  1.1  christos   fi
    288  1.1  christos   rm -f f-l-1-$n.in f-l-1-$n.po
    289  1.1  christos done < f-l-1.data
    290  1.1  christos 
    291  1.1  christos rm -fr $tmpfiles
    292  1.1  christos 
    293  1.1  christos exit 0
    294