alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Ant example source code file (matches-test.xml)

This example Ant source code file (matches-test.xml) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Ant tags/keywords

ab, ab, abc, c, c, jdk14, jdk14, nb, nl, nl, unix_lines

The matches-test.xml source code

<project xmlns:au="antlib:org.apache.ant.antunit">
  <!-- NB: ant's interface to JDK14 regex enables UNIX_LINES -->
  <property name="NL" value="
"/>
  <regexp id="myid" pattern="^[a-z]{3,4}$"/>

  <target name="test-refid">
    <au:assertTrue>
      <matches string="abc">
        <regexp refid="myid"/>
      </matches>
    </au:assertTrue>
  </target>

  <target name="test-simple">
    <au:assertTrue>
      <matches string="abc" pattern="^[a-z]{3,4}$"/>
    </au:assertTrue>
  </target>

  <target name="test-nomatch">
    <au:assertFalse>
      <matches string="abc" pattern="^b.*" />
    </au:assertFalse>
  </target>

  <target name="test-date">
    <tstamp>
      <format property="today" pattern="dd-MM-yyyy" locale="en"/>
    </tstamp>
    <au:assertTrue>
      <matches string="${today}">
        <regexp pattern="^[0123]\d-[01]\d-[12]\d\d\d$" />
      </matches>
    </au:assertTrue>
  </target>

  <target name="test-abc">
    <au:assertTrue>
      <matches string="abc" pattern="ab?"/>
    </au:assertTrue>
    <au:assertTrue>
      <matches string="abc" pattern="ab."/>
    </au:assertTrue>
    <au:assertTrue>
      <matches string="ab" pattern="ab?"/>
    </au:assertTrue>
    <au:assertTrue>
      <matches string="ab" pattern="ab"/>
    </au:assertTrue>
    <au:assertTrue>
      <matches string="acb" pattern="ab?"/>
    </au:assertTrue>
    <au:assertFalse>
      <matches string="acb" pattern="ab."/>
    </au:assertFalse>
  </target>

  <target name="test-caseinsensitive">
    <au:assertTrue>
      <matches string="ABC" pattern="ab?" casesensitive="false"/>
    </au:assertTrue>
  </target>

  <target name="test-singleline">
    <au:assertTrue>
      <matches string="AB${line.separator}C" pattern="^ab.*C$"
               casesensitive="false"
               singleline="true"/>
    </au:assertTrue>
    <au:assertFalse>
      <matches string="AB${line.separator}C" pattern="^ab.*C$"
               casesensitive="false"
               singleline="false"/>
    </au:assertFalse>
  </target>

  <target name="test-multiline">
    <au:assertTrue>
      <matches string="AB${NL}C" pattern="^C$"
               multiline="true"/>
    </au:assertTrue>
    <au:assertTrue>
      <matches string="AB${NL}C" pattern="^AB$"
               multiline="true"/>
    </au:assertTrue>
  </target>

</project>

Other Ant examples (source code examples)

Here is a short list of links related to this Ant matches-test.xml source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.