Home | History | Annotate | Line # | Download | only in unit-tests
varmod-order-numeric.mk revision 1.2
      1 # $NetBSD: varmod-order-numeric.mk,v 1.2 2021/07/30 22:16:09 rillig Exp $
      2 #
      3 # Tests for the :On variable modifier, which returns the words, sorted in
      4 # ascending numeric order.
      5 
      6 # This list contains only 32-bit numbers since the make code needs to conform
      7 # to C90, which does not provide integer types larger than 32 bit.  It uses
      8 # 'long long' by default, but that type is overridable if necessary.
      9 # To get 53-bit integers even in C90, it would be possible to switch to
     10 # 'double' instead, but that would allow floating-point numbers as well, which
     11 # is out of scope for this variable modifier.
     12 NUMBERS=	3 5 7 1 42 -42 5K -3m 1M 1k -2G
     13 
     14 .if ${NUMBERS:On} != "-2G -3m -42 1 3 5 7 42 1k 5K 1M"
     15 .  error ${NUMBERS:On}
     16 .endif
     17 
     18 .if ${NUMBERS:Orn} != "1M 5K 1k 42 7 5 3 1 -42 -3m -2G"
     19 .  error ${NUMBERS:Orn}
     20 .endif
     21 
     22 # Both ':Onr' and ':Orn' have the same effect.
     23 .if ${NUMBERS:Onr} != "1M 5K 1k 42 7 5 3 1 -42 -3m -2G"
     24 .  error ${NUMBERS:Onr}
     25 .endif
     26 
     27 # Shuffling numerically doesn't make sense, so don't allow 'x' and 'n' to be
     28 # combined.
     29 #
     30 # expect-text: Bad modifier ":Oxn" for variable "NUMBERS"
     31 # expect+1: Malformed conditional (${NUMBERS:Oxn})
     32 .if ${NUMBERS:Oxn}
     33 .  error
     34 .else
     35 .  error
     36 .endif
     37 
     38 # Extra characters after ':On' are detected and diagnosed.
     39 # TODO: Add line number information to the "Bad modifier" diagnostic.
     40 # TODO: Use uniform diagnostics for ':On' and ':Onr'.
     41 # TODO: Fix the misleading ':typo' in the diagnostic.
     42 # TODO: The '_' is already wrong but does not occur in the diagnostic.
     43 #
     44 # expect-text: Bad modifier ":typo" for variable "NUMBERS"
     45 .if ${NUMBERS:On_typo}
     46 .  error
     47 .else
     48 .  error
     49 .endif
     50 
     51 # Extra characters after ':Onr' are detected and diagnosed.
     52 #
     53 # expect+1: Unknown modifier "_typo"
     54 .if ${NUMBERS:Onr_typo}
     55 .  error
     56 .else
     57 .  error
     58 .endif
     59 
     60 # Extra characters after ':Orn' are detected and diagnosed.
     61 #
     62 # expect+1: Unknown modifier "_typo"
     63 .if ${NUMBERS:Orn_typo}
     64 .  error
     65 .else
     66 .  error
     67 .endif
     68 
     69 # Repeating the 'n' is not supported.  In the typical use cases, the sorting
     70 # criteria are fixed, not computed, therefore allowing this redundancy does
     71 # not make sense.
     72 #
     73 # TODO: This repetition is not diagnosed.
     74 .if ${NUMBERS:Onn}
     75 .  error
     76 .else
     77 .  error
     78 .endif
     79 
     80 # Repeating the 'r' is not supported as well, for the same reasons as above.
     81 #
     82 # expect+1: Unknown modifier "r"
     83 .if ${NUMBERS:Onrr}
     84 .  error
     85 .else
     86 .  error
     87 .endif
     88 
     89 # Repeating the 'r' is not supported as well, for the same reasons as above.
     90 #
     91 # TODO: Use uniform diagnostics for ':Onrr' and ':Orrn'.
     92 #
     93 # expect-text: Bad modifier ":Orrn" for variable "NUMBERS"
     94 .if ${NUMBERS:Orrn}
     95 .  error
     96 .else
     97 .  error
     98 .endif
     99 
    100 all:
    101