aboutsummaryrefslogtreecommitdiff
path: root/unit-tests/modmisc.mk
diff options
context:
space:
mode:
Diffstat (limited to 'unit-tests/modmisc.mk')
-rw-r--r--unit-tests/modmisc.mk113
1 files changed, 39 insertions, 74 deletions
diff --git a/unit-tests/modmisc.mk b/unit-tests/modmisc.mk
index d0c334342934..f2977da8a0ba 100644
--- a/unit-tests/modmisc.mk
+++ b/unit-tests/modmisc.mk
@@ -1,4 +1,4 @@
-# $Id: modmisc.mk,v 1.1.1.3 2020/07/09 22:35:19 sjg Exp $
+# $Id: modmisc.mk,v 1.1.1.15 2020/08/23 15:52:08 sjg Exp $
#
# miscellaneous modifier tests
@@ -15,13 +15,15 @@ MOD_HOMES=S,/home/,/homes/,
MOD_OPT=@d@$${exists($$d):?$$d:$${d:S,/usr,/opt,}}@
MOD_SEP=S,:, ,g
-all: modvar modvarloop modsysv mod-HTE emptyvar undefvar
-all: mod-S mod-C mod-at-varname mod-at-resolve
-all: mod-subst-dollar mod-loop-dollar
+all: modvar modvarloop modsysv emptyvar undefvar
+all: mod-quote
+all: mod-break-many-words
+# See also sysv.mk.
modsysv:
@echo "The answer is ${libfoo.a:L:libfoo.a=42}"
+# Demonstrates modifiers that are given indirectly from a variable.
modvar:
@echo "path='${path}'"
@echo "path='${path:${MOD_NODOT}}'"
@@ -39,13 +41,6 @@ modvarloop:
@echo "paths=${paths}"
@echo "PATHS=${paths:tu}"
-PATHNAMES= a/b/c def a.b.c a.b/c a a.a .gitignore a a.a
-mod-HTE:
- @echo "dirname of '"${PATHNAMES:Q}"' is '"${PATHNAMES:H:Q}"'"
- @echo "basename of '"${PATHNAMES:Q}"' is '"${PATHNAMES:T:Q}"'"
- @echo "suffix of '"${PATHNAMES:Q}"' is '"${PATHNAMES:E:Q}"'"
- @echo "root of '"${PATHNAMES:Q}"' is '"${PATHNAMES:R:Q}"'"
-
# When a modifier is applied to the "" variable, the result is discarded.
emptyvar:
@echo S:${:S,^$,empty,}
@@ -61,67 +56,37 @@ undefvar:
@echo C:${:U:C,^$,empty,}
@echo @:${:U:@var@empty@}
-mod-S:
- @echo :${:Ua b b c:S,a b,,:Q}:
- @echo :${:Ua b b c:S,a b,,1:Q}:
- @echo :${:Ua b b c:S,a b,,W:Q}:
- @echo :${:Ua b b c:S,b,,g:Q}:
- @echo :${:U1 2 3 1 2 3:S,1 2,___,Wg:S,_,x,:Q}:
-
-mod-C:
- @echo :${:Ua b b c:C,a b,,:Q}:
- @echo :${:Ua b b c:C,a b,,1:Q}:
- @echo :${:Ua b b c:C,a b,,W:Q}:
- @echo :${:Uword1 word2:C,****,____,g:C,word,____,:Q}:
- @echo :${:Ua b b c:C,b,,g:Q}:
- @echo :${:U1 2 3 1 2 3:C,1 2,___,Wg:C,_,x,:Q}:
-
-# In the :@ modifier, the name of the loop variable can even be generated
-# dynamically. There's no practical use-case for this, and hopefully nobody
-# will ever depend on this, but technically it's possible.
-mod-at-varname:
- @echo :${:Uone two three:@${:Ubar:S,b,v,}@+${var}+@:Q}:
-
-# The :@ modifier resolves the variables a little more often than expected.
-# In particular, it resolves _all_ variables from the context, and not only
-# the loop variable (in this case v).
-#
-# The d means direct reference, the i means indirect reference.
-RESOLVE= ${RES1} $${RES1}
-RES1= 1d${RES2} 1i$${RES2}
-RES2= 2d${RES3} 2i$${RES3}
-RES3= 3
-
-mod-at-resolve:
- @echo $@:${RESOLVE:@v@w${v}w@:Q}:
-
-# No matter how many dollar characters there are, they all get merged
-# into a single dollar by the :S modifier.
-mod-subst-dollar:
- @echo $@:${:U1:S,^,$,:Q}:
- @echo $@:${:U2:S,^,$$,:Q}:
- @echo $@:${:U3:S,^,$$$,:Q}:
- @echo $@:${:U4:S,^,$$$$,:Q}:
- @echo $@:${:U5:S,^,$$$$$,:Q}:
- @echo $@:${:U6:S,^,$$$$$$,:Q}:
- @echo $@:${:U7:S,^,$$$$$$$,:Q}:
- @echo $@:${:U8:S,^,$$$$$$$$,:Q}:
-# This generates no dollar at all:
- @echo $@:${:UU8:S,^,${:U$$$$$$$$},:Q}:
-# Here is an alternative way to generate dollar characters.
-# It's unexpectedly complicated though.
- @echo $@:${:U:range=5:ts\x24:C,[0-9],,g:Q}:
-
-# Demonstrate that it is possible to generate dollar characters using the
-# :@ modifier.
+
+mod-quote:
+ @echo $@: new${.newline:Q}${.newline:Q}line
+
+# Cover the bmake_realloc in brk_string.
+mod-break-many-words:
+ @echo $@: ${UNDEF:U:range=500:[#]}
+
+# To apply a modifier indirectly via another variable, the whole
+# modifier must be put into a single variable.
+.if ${value:L:${:US}${:U,value,replacement,}} != "S,value,replacement,}"
+.warning unexpected
+.endif
+
+# Adding another level of indirection (the 2 nested :U expressions) helps.
+.if ${value:L:${:U${:US}${:U,value,replacement,}}} != "replacement"
+.warning unexpected
+.endif
+
+# Multiple indirect modifiers can be applied one after another as long as
+# they are separated with colons.
+.if ${value:L:${:US,a,A,}:${:US,e,E,}} != "vAluE"
+.warning unexpected
+.endif
+
+# An indirect variable that evaluates to the empty string is allowed though.
+# This makes it possible to define conditional modifiers, like this:
#
-# These are edge cases that could have resulted in a parse error as well
-# since the $@ at the end could have been interpreted as a variable, which
-# would mean a missing closing @ delimiter.
-mod-loop-dollar:
- @echo $@:${:U1:@word@${word}$@:Q}:
- @echo $@:${:U2:@word@$${word}$$@:Q}:
- @echo $@:${:U3:@word@$$${word}$$$@:Q}:
- @echo $@:${:U4:@word@$$$${word}$$$$@:Q}:
- @echo $@:${:U5:@word@$$$$${word}$$$$$@:Q}:
- @echo $@:${:U6:@word@$$$$$${word}$$$$$$@:Q}:
+# M.little-endian= S,1234,4321,
+# M.big-endian= # none
+.if ${value:L:${:Dempty}S,a,A,} != "vAlue"
+.warning unexpected
+.endif
+