xref: /freebsd/contrib/bmake/unit-tests/varmod-match.mk (revision e2eeea75eb8b6dd50c1298067a0655880d186734)
1*e2eeea75SSimon J. Gerraty# $NetBSD: varmod-match.mk,v 1.6 2020/11/15 18:33:41 rillig Exp $
22c3632d1SSimon J. Gerraty#
32c3632d1SSimon J. Gerraty# Tests for the :M variable modifier, which filters words that match the
42c3632d1SSimon J. Gerraty# given pattern.
5956e45f6SSimon J. Gerraty#
6956e45f6SSimon J. Gerraty# See ApplyModifier_Match and ModifyWord_Match for the implementation.
72c3632d1SSimon J. Gerraty
8956e45f6SSimon J. Gerraty.MAKEFLAGS: -dc
92c3632d1SSimon J. Gerraty
102c3632d1SSimon J. GerratyNUMBERS=	One Two Three Four five six seven
112c3632d1SSimon J. Gerraty
12956e45f6SSimon J. Gerraty# Only keep words that start with an uppercase letter.
13956e45f6SSimon J. Gerraty.if ${NUMBERS:M[A-Z]*} != "One Two Three Four"
14956e45f6SSimon J. Gerraty.  error
15956e45f6SSimon J. Gerraty.endif
162c3632d1SSimon J. Gerraty
17956e45f6SSimon J. Gerraty# Only keep words that start with a character other than an uppercase letter.
18956e45f6SSimon J. Gerraty.if ${NUMBERS:M[^A-Z]*} != "five six seven"
19956e45f6SSimon J. Gerraty.  error
20956e45f6SSimon J. Gerraty.endif
21956e45f6SSimon J. Gerraty
22956e45f6SSimon J. Gerraty# Only keep words that don't start with s and at the same time end with
23956e45f6SSimon J. Gerraty# either of [ex].
24956e45f6SSimon J. Gerraty#
25956e45f6SSimon J. Gerraty# This test case ensures that the negation from the first character class
26956e45f6SSimon J. Gerraty# does not propagate to the second character class.
27956e45f6SSimon J. Gerraty.if ${NUMBERS:M[^s]*[ex]} != "One Three five"
28956e45f6SSimon J. Gerraty.  error
29956e45f6SSimon J. Gerraty.endif
302c3632d1SSimon J. Gerraty
312c3632d1SSimon J. Gerraty# Before 2020-06-13, this expression took quite a long time in Str_Match,
322c3632d1SSimon J. Gerraty# calling itself 601080390 times for 16 asterisks.
33956e45f6SSimon J. Gerraty.if ${:U****************:M****************b}
34956e45f6SSimon J. Gerraty.endif
35956e45f6SSimon J. Gerraty
36956e45f6SSimon J. Gerraty# To match a dollar sign in a word, double it.
37956e45f6SSimon J. Gerraty#
38956e45f6SSimon J. Gerraty# This is different from the :S and :C variable modifiers, where a '$'
39956e45f6SSimon J. Gerraty# has to be escaped as '\$'.
40956e45f6SSimon J. Gerraty.if ${:Ua \$ sign:M*$$*} != "\$"
41956e45f6SSimon J. Gerraty.  error
42956e45f6SSimon J. Gerraty.endif
43956e45f6SSimon J. Gerraty
44956e45f6SSimon J. Gerraty# In the :M modifier, '\$' does not escape a dollar.  Instead it is
45956e45f6SSimon J. Gerraty# interpreted as a backslash followed by whatever expression the
46956e45f6SSimon J. Gerraty# '$' starts.
47956e45f6SSimon J. Gerraty#
48956e45f6SSimon J. Gerraty# This differs from the :S, :C and several other variable modifiers.
49956e45f6SSimon J. Gerraty${:U*}=		asterisk
50956e45f6SSimon J. Gerraty.if ${:Ua \$ sign any-asterisk:M*\$*} != "any-asterisk"
51956e45f6SSimon J. Gerraty.  error
52956e45f6SSimon J. Gerraty.endif
53956e45f6SSimon J. Gerraty
54*e2eeea75SSimon J. Gerraty# TODO: ${VAR:M(((}}}}
55*e2eeea75SSimon J. Gerraty# TODO: ${VAR:M{{{)))}
56*e2eeea75SSimon J. Gerraty# TODO: ${VAR:M${UNBALANCED}}
57*e2eeea75SSimon J. Gerraty# TODO: ${VAR:M${:U(((\}\}\}}}
58*e2eeea75SSimon J. Gerraty
59956e45f6SSimon J. Gerratyall:
60956e45f6SSimon J. Gerraty	@:;
61