BAEL-2771 string matching - Move to new module (#6744)

* BAEL-2771 Add String matching example to core-groovy

* Move test to new core-groovy-2 module
This commit is contained in:
Kevin Wittek 2019-04-16 23:21:09 +02:00 committed by maibin
parent 8eb613bc86
commit 8ba93d8dc6
5 changed files with 134 additions and 0 deletions

4
.gitignore vendored
View File

@ -19,6 +19,7 @@
.idea/ .idea/
*.iml *.iml
*.iws *.iws
out/
# Mac # Mac
.DS_Store .DS_Store
@ -27,6 +28,9 @@
log/ log/
target/ target/
# Gradle
.gradle/
spring-openid/src/main/resources/application.properties spring-openid/src/main/resources/application.properties
.recommenders/ .recommenders/
/spring-hibernate4/nbproject/ /spring-hibernate4/nbproject/

5
core-groovy-2/README.md Normal file
View File

@ -0,0 +1,5 @@
# Groovy
## Relevant articles:
- [String Matching in Groovy](http://www.baeldung.com/)

80
core-groovy-2/pom.xml Normal file
View File

@ -0,0 +1,80 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>core-groovy</artifactId>
<version>1.0-SNAPSHOT</version>
<name>core-groovy-2</name>
<packaging>jar</packaging>
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>${groovy-all.version}</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>${hsqldb.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.spockframework</groupId>
<artifactId>spock-core</artifactId>
<version>${spock-core.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>${gmavenplus-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>compileTests</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version>
<configuration>
<useFile>false</useFile>
<includes>
<include>**/*Test.java</include>
<include>**/*Spec.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>central</id>
<url>http://jcenter.bintray.com</url>
</repository>
</repositories>
<properties>
<groovy-all.version>2.5.6</groovy-all.version>
<hsqldb.version>2.4.0</hsqldb.version>
<spock-core.version>1.3-groovy-2.5</spock-core.version>
<gmavenplus-plugin.version>1.6.3</gmavenplus-plugin.version>
</properties>
</project>

View File

@ -0,0 +1,44 @@
package com.baeldung.strings
import spock.lang.Specification
import java.util.regex.Pattern
class StringMatchingSpec extends Specification {
def "pattern operator example"() {
given: "a pattern"
def p = ~'foo'
expect:
p instanceof Pattern
and: "you can use slash strings to avoid escaping of blackslash"
def digitPattern = ~/\d*/
digitPattern.matcher('4711').matches()
}
def "match operator example"() {
expect:
'foobar' ==~ /.*oba.*/
and: "matching is strict"
!('foobar' ==~ /foo/)
}
def "find operator example"() {
when: "using the find operator"
def matcher = 'foo and bar, baz and buz' =~ /(\w+) and (\w+)/
then: "will find groups"
matcher.size() == 2
and: "can access groups using array"
matcher[0][0] == 'foo and bar'
matcher[1][2] == 'buz'
and: "you can use it as a predicate"
'foobarbaz' =~ /bar/
}
}

View File

@ -1039,6 +1039,7 @@
<module>cdi</module> <module>cdi</module>
<module>checker-plugin</module> <module>checker-plugin</module>
<module>core-groovy</module> <module>core-groovy</module>
<module>core-groovy-2</module>
<!-- <module>core-java-10</module> --> <!-- We haven't upgraded to java 10. Fixing in BAEL-10841 --> <!-- <module>core-java-10</module> --> <!-- We haven't upgraded to java 10. Fixing in BAEL-10841 -->
<!-- <module>core-java-11</module> --> <!-- We haven't upgraded to java 11. Fixing in BAEL-10841 --> <!-- <module>core-java-11</module> --> <!-- We haven't upgraded to java 11. Fixing in BAEL-10841 -->
<module>core-java-8</module> <module>core-java-8</module>