xref: /freebsd/contrib/bmake/unit-tests/varmod-match.mk (revision a521f2116473fbd8c09db395518f060a27d02334)
1# $NetBSD: varmod-match.mk,v 1.5 2020/09/13 05:36:26 rillig Exp $
2#
3# Tests for the :M variable modifier, which filters words that match the
4# given pattern.
5#
6# See ApplyModifier_Match and ModifyWord_Match for the implementation.
7
8.MAKEFLAGS: -dc
9
10NUMBERS=	One Two Three Four five six seven
11
12# Only keep words that start with an uppercase letter.
13.if ${NUMBERS:M[A-Z]*} != "One Two Three Four"
14.  error
15.endif
16
17# Only keep words that start with a character other than an uppercase letter.
18.if ${NUMBERS:M[^A-Z]*} != "five six seven"
19.  error
20.endif
21
22# Only keep words that don't start with s and at the same time end with
23# either of [ex].
24#
25# This test case ensures that the negation from the first character class
26# does not propagate to the second character class.
27.if ${NUMBERS:M[^s]*[ex]} != "One Three five"
28.  error
29.endif
30
31# Before 2020-06-13, this expression took quite a long time in Str_Match,
32# calling itself 601080390 times for 16 asterisks.
33.if ${:U****************:M****************b}
34.endif
35
36# To match a dollar sign in a word, double it.
37#
38# This is different from the :S and :C variable modifiers, where a '$'
39# has to be escaped as '\$'.
40.if ${:Ua \$ sign:M*$$*} != "\$"
41.  error
42.endif
43
44# In the :M modifier, '\$' does not escape a dollar.  Instead it is
45# interpreted as a backslash followed by whatever expression the
46# '$' starts.
47#
48# This differs from the :S, :C and several other variable modifiers.
49${:U*}=		asterisk
50.if ${:Ua \$ sign any-asterisk:M*\$*} != "any-asterisk"
51.  error
52.endif
53
54all:
55	@:;
56