From 8ba93d8dc62f4ca04d570784dba9fc59114e6e98 Mon Sep 17 00:00:00 2001 From: Kevin Wittek Date: Tue, 16 Apr 2019 23:21:09 +0200 Subject: [PATCH] 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 --- .gitignore | 4 + core-groovy-2/README.md | 5 ++ core-groovy-2/pom.xml | 80 +++++++++++++++++++ .../strings/StringMatchingSpec.groovy | 44 ++++++++++ pom.xml | 1 + 5 files changed, 134 insertions(+) create mode 100644 core-groovy-2/README.md create mode 100644 core-groovy-2/pom.xml create mode 100644 core-groovy-2/src/test/groovy/com/baeldung/strings/StringMatchingSpec.groovy diff --git a/.gitignore b/.gitignore index 21586748b7..b981a473f6 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,7 @@ .idea/ *.iml *.iws +out/ # Mac .DS_Store @@ -27,6 +28,9 @@ log/ target/ +# Gradle +.gradle/ + spring-openid/src/main/resources/application.properties .recommenders/ /spring-hibernate4/nbproject/ diff --git a/core-groovy-2/README.md b/core-groovy-2/README.md new file mode 100644 index 0000000000..9701976142 --- /dev/null +++ b/core-groovy-2/README.md @@ -0,0 +1,5 @@ +# Groovy + +## Relevant articles: + +- [String Matching in Groovy](http://www.baeldung.com/) \ No newline at end of file diff --git a/core-groovy-2/pom.xml b/core-groovy-2/pom.xml new file mode 100644 index 0000000000..bbedbf2157 --- /dev/null +++ b/core-groovy-2/pom.xml @@ -0,0 +1,80 @@ + + + 4.0.0 + core-groovy + 1.0-SNAPSHOT + core-groovy-2 + jar + + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + + + + + org.codehaus.groovy + groovy-all + ${groovy-all.version} + pom + + + org.hsqldb + hsqldb + ${hsqldb.version} + test + + + org.spockframework + spock-core + ${spock-core.version} + test + + + + + + + org.codehaus.gmavenplus + gmavenplus-plugin + ${gmavenplus-plugin.version} + + + + compile + compileTests + + + + + + maven-surefire-plugin + 2.20.1 + + false + + **/*Test.java + **/*Spec.java + + + + + + + + + central + http://jcenter.bintray.com + + + + + 2.5.6 + 2.4.0 + 1.3-groovy-2.5 + 1.6.3 + + + diff --git a/core-groovy-2/src/test/groovy/com/baeldung/strings/StringMatchingSpec.groovy b/core-groovy-2/src/test/groovy/com/baeldung/strings/StringMatchingSpec.groovy new file mode 100644 index 0000000000..3865bc73fa --- /dev/null +++ b/core-groovy-2/src/test/groovy/com/baeldung/strings/StringMatchingSpec.groovy @@ -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/ + } + +} diff --git a/pom.xml b/pom.xml index 80187ffc6f..ff2fa55410 100644 --- a/pom.xml +++ b/pom.xml @@ -1039,6 +1039,7 @@ cdi checker-plugin core-groovy + core-groovy-2 core-java-8