Home | History | Annotate | Line # | Download | only in unit-tests
varmod-match.mk revision 1.4
      1  1.4  rillig # $NetBSD: varmod-match.mk,v 1.4 2020/09/12 22:35:43 rillig Exp $
      2  1.1  rillig #
      3  1.2  rillig # Tests for the :M variable modifier, which filters words that match the
      4  1.2  rillig # given pattern.
      5  1.4  rillig #
      6  1.4  rillig # See ApplyModifier_Match and ModifyWord_Match for the implementation.
      7  1.1  rillig 
      8  1.4  rillig .MAKEFLAGS: -dc
      9  1.3  rillig 
     10  1.3  rillig NUMBERS=	One Two Three Four five six seven
     11  1.3  rillig 
     12  1.4  rillig # Only keep numbers that start with an uppercase letter.
     13  1.4  rillig .if ${NUMBERS:M[A-Z]*} != "One Two Three Four"
     14  1.4  rillig .  error
     15  1.4  rillig .endif
     16  1.4  rillig 
     17  1.4  rillig # Only keep numbers that don't start with an uppercase letter.
     18  1.4  rillig .if ${NUMBERS:M[^A-Z]*} != "five six seven"
     19  1.4  rillig .  error
     20  1.4  rillig .endif
     21  1.4  rillig 
     22  1.4  rillig # Only keep numbers that don't start with s and at the same time
     23  1.4  rillig # ends with either of [ex].
     24  1.4  rillig .if ${NUMBERS:M[^s]*[ex]} != "One Three five"
     25  1.4  rillig .  error
     26  1.4  rillig .endif
     27  1.3  rillig 
     28  1.3  rillig # Before 2020-06-13, this expression took quite a long time in Str_Match,
     29  1.3  rillig # calling itself 601080390 times for 16 asterisks.
     30  1.4  rillig .if ${:U****************:M****************b}
     31  1.4  rillig .endif
     32  1.4  rillig 
     33  1.4  rillig # To match a dollar sign in a word, double it.
     34  1.4  rillig # This is different from the :S and :C variable modifiers, where a '$'
     35  1.4  rillig # has to be escaped as '$$'.
     36  1.4  rillig .if ${:Ua \$ sign:M*$$*} != "\$"
     37  1.4  rillig .  error
     38  1.4  rillig .endif
     39  1.4  rillig 
     40  1.4  rillig # In the :M modifier, it does not work to escape a dollar using a backslash.
     41  1.4  rillig # This is different from the :S, :C and a few other variable modifiers.
     42  1.4  rillig ${:U*}=		asterisk
     43  1.4  rillig .if ${:Ua \$ sign any-asterisk:M*\$*} != "any-asterisk"
     44  1.4  rillig .  error
     45  1.4  rillig .endif
     46  1.4  rillig 
     47  1.4  rillig all:
     48  1.4  rillig 	@:;
     49