Home | History | Annotate | Line # | Download | only in unit-tests
varmod-sysv.mk revision 1.3
      1  1.3  rillig # $NetBSD: varmod-sysv.mk,v 1.3 2020/08/23 14:52:06 rillig Exp $
      2  1.1  rillig #
      3  1.2  rillig # Tests for the ${VAR:from=to} variable modifier, which replaces the suffix
      4  1.2  rillig # "from" with "to".  It can also use '%' as a wildcard.
      5  1.2  rillig #
      6  1.2  rillig # This modifier is applied when the other modifiers don't match exactly.
      7  1.1  rillig 
      8  1.3  rillig all: words ampersand anchor-dollar mismatch
      9  1.1  rillig 
     10  1.3  rillig # The :Q looks like a modifier but isn't.
     11  1.3  rillig # It is part of the replacement string.
     12  1.3  rillig words:
     13  1.3  rillig 	@echo a${a b c d e:L:%a=x:Q}b
     14  1.3  rillig 
     15  1.3  rillig # Before 2020-07-19, an ampersand could be used in the replacement part
     16  1.3  rillig # of a SysV substitution modifier.  This was probably a copy-and-paste
     17  1.3  rillig # mistake since the SysV modifier code looked a lot like the code for the
     18  1.3  rillig # :S and :C modifiers.  The ampersand is not mentioned in the manual page.
     19  1.3  rillig ampersand:
     20  1.3  rillig 	@echo ${:U${a.bcd.e:L:a.%=%}:Q}
     21  1.3  rillig 	@echo ${:U${a.bcd.e:L:a.%=&}:Q}
     22  1.3  rillig 
     23  1.3  rillig # Before 2020-07-20, when a SysV modifier was parsed, a single dollar
     24  1.3  rillig # before the '=' was interpreted as an anchor, which doesn't make sense
     25  1.3  rillig # since the anchor was discarded immediately.
     26  1.3  rillig anchor-dollar:
     27  1.3  rillig 	@echo $@: ${:U${value:L:e$=x}:Q}
     28  1.3  rillig 	@echo $@: ${:U${value:L:e=x}:Q}
     29  1.3  rillig 
     30  1.3  rillig # Words that don't match are copied unmodified.
     31  1.3  rillig # The % placeholder can be anywhere in the string.
     32  1.3  rillig mismatch:
     33  1.3  rillig 	@echo $@: ${:Ufile.c file.h:%.c=%.cpp}
     34  1.3  rillig 	@echo $@: ${:Ufile.c other.c:file.%=renamed.%}
     35  1.3  rillig 
     36  1.3  rillig # Trying to cover all possible variants of the SysV modifier.
     37  1.3  rillig LIST=	one two
     38  1.3  rillig EXPR.1=	${LIST:o=X}
     39  1.3  rillig EXP.1=	one twX
     40  1.3  rillig EXPR.2=	${LIST:o=}
     41  1.3  rillig EXP.2=	one tw
     42  1.3  rillig EXPR.3=	${LIST:o=%}
     43  1.3  rillig EXP.3=	one tw%
     44  1.3  rillig EXPR.4=	${LIST:%o=X}
     45  1.3  rillig EXP.4=	one X
     46  1.3  rillig EXPR.5=	${LIST:o%=X}
     47  1.3  rillig EXP.5=	X two
     48  1.3  rillig EXPR.6=	${LIST:o%e=X}
     49  1.3  rillig EXP.6=	X two
     50  1.3  rillig EXPR.7=	${LIST:o%%e=X}		# Only the first '%' is the wildcard.
     51  1.3  rillig EXP.7=	one two			# None of the words contains a literal '%'.
     52  1.3  rillig EXPR.8=	${LIST:%=%%}
     53  1.3  rillig EXP.8=	one% two%
     54  1.3  rillig EXPR.9=	${LIST:%nes=%xxx}	# lhs is longer than the word "one"
     55  1.3  rillig EXP.9=	one two
     56  1.3  rillig 
     57  1.3  rillig .for i in ${:U:range=9}
     58  1.3  rillig .if ${EXPR.$i} != ${EXP.$i}
     59  1.3  rillig .warning test case $i expected "${EXP.$i}", got "${EXPR.$i}
     60  1.3  rillig .endif
     61  1.3  rillig .endfor
     62