Skip to content

Commit 8ba93d8

Browse files
kiviewmaibin
authored andcommitted
BAEL-2771 string matching - Move to new module (eugenp#6744)
* BAEL-2771 Add String matching example to core-groovy * Move test to new core-groovy-2 module
1 parent 8eb613b commit 8ba93d8

File tree

5 files changed

+134
-0
lines changed

5 files changed

+134
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
.idea/
2020
*.iml
2121
*.iws
22+
out/
2223

2324
# Mac
2425
.DS_Store
@@ -27,6 +28,9 @@
2728
log/
2829
target/
2930

31+
# Gradle
32+
.gradle/
33+
3034
spring-openid/src/main/resources/application.properties
3135
.recommenders/
3236
/spring-hibernate4/nbproject/

core-groovy-2/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Groovy
2+
3+
## Relevant articles:
4+
5+
- [String Matching in Groovy](http://www.baeldung.com/)

core-groovy-2/pom.xml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<artifactId>core-groovy</artifactId>
6+
<version>1.0-SNAPSHOT</version>
7+
<name>core-groovy-2</name>
8+
<packaging>jar</packaging>
9+
10+
<parent>
11+
<groupId>com.baeldung</groupId>
12+
<artifactId>parent-modules</artifactId>
13+
<version>1.0.0-SNAPSHOT</version>
14+
</parent>
15+
16+
<dependencies>
17+
<dependency>
18+
<groupId>org.codehaus.groovy</groupId>
19+
<artifactId>groovy-all</artifactId>
20+
<version>${groovy-all.version}</version>
21+
<type>pom</type>
22+
</dependency>
23+
<dependency>
24+
<groupId>org.hsqldb</groupId>
25+
<artifactId>hsqldb</artifactId>
26+
<version>${hsqldb.version}</version>
27+
<scope>test</scope>
28+
</dependency>
29+
<dependency>
30+
<groupId>org.spockframework</groupId>
31+
<artifactId>spock-core</artifactId>
32+
<version>${spock-core.version}</version>
33+
<scope>test</scope>
34+
</dependency>
35+
</dependencies>
36+
37+
<build>
38+
<plugins>
39+
<plugin>
40+
<groupId>org.codehaus.gmavenplus</groupId>
41+
<artifactId>gmavenplus-plugin</artifactId>
42+
<version>${gmavenplus-plugin.version}</version>
43+
<executions>
44+
<execution>
45+
<goals>
46+
<goal>compile</goal>
47+
<goal>compileTests</goal>
48+
</goals>
49+
</execution>
50+
</executions>
51+
</plugin>
52+
<plugin>
53+
<artifactId>maven-surefire-plugin</artifactId>
54+
<version>2.20.1</version>
55+
<configuration>
56+
<useFile>false</useFile>
57+
<includes>
58+
<include>**/*Test.java</include>
59+
<include>**/*Spec.java</include>
60+
</includes>
61+
</configuration>
62+
</plugin>
63+
</plugins>
64+
</build>
65+
66+
<repositories>
67+
<repository>
68+
<id>central</id>
69+
<url>http://jcenter.bintray.com</url>
70+
</repository>
71+
</repositories>
72+
73+
<properties>
74+
<groovy-all.version>2.5.6</groovy-all.version>
75+
<hsqldb.version>2.4.0</hsqldb.version>
76+
<spock-core.version>1.3-groovy-2.5</spock-core.version>
77+
<gmavenplus-plugin.version>1.6.3</gmavenplus-plugin.version>
78+
</properties>
79+
</project>
80+
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.baeldung.strings
2+
3+
import spock.lang.Specification
4+
5+
import java.util.regex.Pattern
6+
7+
class StringMatchingSpec extends Specification {
8+
9+
def "pattern operator example"() {
10+
given: "a pattern"
11+
def p = ~'foo'
12+
13+
expect:
14+
p instanceof Pattern
15+
16+
and: "you can use slash strings to avoid escaping of blackslash"
17+
def digitPattern = ~/\d*/
18+
digitPattern.matcher('4711').matches()
19+
}
20+
21+
def "match operator example"() {
22+
expect:
23+
'foobar' ==~ /.*oba.*/
24+
25+
and: "matching is strict"
26+
!('foobar' ==~ /foo/)
27+
}
28+
29+
def "find operator example"() {
30+
when: "using the find operator"
31+
def matcher = 'foo and bar, baz and buz' =~ /(\w+) and (\w+)/
32+
33+
then: "will find groups"
34+
matcher.size() == 2
35+
36+
and: "can access groups using array"
37+
matcher[0][0] == 'foo and bar'
38+
matcher[1][2] == 'buz'
39+
40+
and: "you can use it as a predicate"
41+
'foobarbaz' =~ /bar/
42+
}
43+
44+
}

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,6 +1039,7 @@
10391039
<module>cdi</module>
10401040
<module>checker-plugin</module>
10411041
<module>core-groovy</module>
1042+
<module>core-groovy-2</module>
10421043
<!-- <module>core-java-10</module> --> <!-- We haven't upgraded to java 10. Fixing in BAEL-10841 -->
10431044
<!-- <module>core-java-11</module> --> <!-- We haven't upgraded to java 11. Fixing in BAEL-10841 -->
10441045
<module>core-java-8</module>

0 commit comments

Comments
 (0)