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