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