Home | History | Annotate | Line # | Download | only in unit-tests
varmod-order-numeric.mk revision 1.8
      1 # $NetBSD: varmod-order-numeric.mk,v 1.8 2022/09/27 19:18:45 rillig Exp $
      2 #
      3 # Tests for the variable modifiers ':On', which returns the words, sorted in
      4 # ascending numeric order, and for ':Orn' and ':Onr', which additionally
      5 # reverse the order.
      6 #
      7 # The variable modifiers ':On', ':Onr' and ':Orn' were added in var.c 1.939
      8 # from 2021-07-30.
      9 
     10 # This list contains only 32-bit numbers since the make code needs to conform
     11 # to C90, which does not necessarily provide integer types larger than 32 bit.
     12 # Make uses 'long long' for C99 or later, and 'long' for older C versions.
     13 #
     14 # To get 53-bit integers even in C90, it would be possible to switch to
     15 # 'double' instead, but that would allow floating-point numbers as well, which
     16 # is out of scope for this variable modifier.
     17 NUMBERS=	3 5 7 1 42 -42 5K -3m 1M 1k -2G
     18 
     19 .if ${NUMBERS:On} != "-2G -3m -42 1 3 5 7 42 1k 5K 1M"
     20 .  error ${NUMBERS:On}
     21 .endif
     22 
     23 .if ${NUMBERS:Orn} != "1M 5K 1k 42 7 5 3 1 -42 -3m -2G"
     24 .  error ${NUMBERS:Orn}
     25 .endif
     26 
     27 # Both ':Onr' and ':Orn' have the same effect.
     28 .if ${NUMBERS:Onr} != "1M 5K 1k 42 7 5 3 1 -42 -3m -2G"
     29 .  error ${NUMBERS:Onr}
     30 .endif
     31 
     32 # Duplicate numbers are preserved in the output.  In this case the
     33 # equal-valued numbers are spelled the same, so they are indistinguishable in
     34 # the output.
     35 DUPLICATES=	3 1 2 2 1 1	# subsequence of https://oeis.org/A034002
     36 .if ${DUPLICATES:On} != "1 1 1 2 2 3"
     37 .  error ${DUPLICATES:On}
     38 .endif
     39 
     40 # If there are several numbers that have the same integer value, they are
     41 # returned in unspecified order.
     42 SAME_VALUE:=	${:U 79 80 0x0050 81 :On}
     43 .if ${SAME_VALUE} != "79 80 0x0050 81" && ${SAME_VALUE} != "79 0x0050 80 81"
     44 .  error ${SAME_VALUE}
     45 .endif
     46 
     47 # Hexadecimal and octal numbers can be sorted as well.
     48 MIXED_BASE=	0 010 0x7 9
     49 .if ${MIXED_BASE:On} != "0 0x7 010 9"
     50 .  error ${MIXED_BASE:On}
     51 .endif
     52 
     53 # The measurement units for suffixes are k, M, G, but not T.
     54 # The string '3T' evaluates to 3, the string 'x' evaluates as '0'.
     55 .if ${4 3T 2M x:L:On} != "x 3T 4 2M"
     56 .  error
     57 .endif
     58 
     59 all:
     60