Skip to content

Commit de00a86

Browse files
committed
Modify README and unit tests broken into Real world and basic func.
- Modify README.md to link to other implementations, show a basic working example, and contain a build status image - Break Unit tests into two files, one testing basic functionality and the other testing real world use cases.
1 parent 7412c71 commit de00a86

File tree

5 files changed

+83
-23
lines changed

5 files changed

+83
-23
lines changed

README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,52 @@
1+
[![Build Status](https://travis-ci.org/VerbalExpressions/JavaVerbalExpressions.png)](https://travis-ci.org/VerbalExpressions/JavaVerbalExpressions)
12
JavaVerbalExpressions
23
=====================
4+
VerbalExpressions is a Java library that helps to construct difficult regular expressions - ported from the wonderful [JSVerbalExpressions](https://github.com/VerbalExpressions/JSVerbalExpressions).
5+
6+
##Examples
7+
```java
8+
9+
VerbalExpression testRegex = new VerbalExpression ()
10+
.startOfLine()
11+
.then("http")
12+
.maybe("s")
13+
.then("://")
14+
.maybe("www.")
15+
.anythingBut(" ")
16+
.endOfLine();
17+
18+
// Create an example URL
19+
String url = "https://www.google.com";
20+
21+
// Use VerbalExpression's testExact() method to test if the entire string matches
22+
// the regex
23+
testRegex.testExact(url); //True
24+
25+
testRegex.toString(); // Ouputs the regex used:
26+
// ^(http)(s)?(\:\/\/)(www\.)?([^\ ]*)$
27+
28+
VerbalExpression testRegex = new VerbalExpression ()
29+
.startOfLine()
30+
.then("abc")
31+
.or("def");
32+
33+
String testString = "defzzz";
34+
35+
//Use VerbalExpression's test() method to test if parts if the string match the regex
36+
testRegex.test(testString); //true
37+
testRegex.testExact(testString); //false
38+
39+
40+
```
41+
342
## Other implementations
443
You can view all implementations on [VerbalExpressions.github.io](http://VerbalExpressions.github.io)
44+
- [Javascript](https://github.com/VerbalExpressions/JSVerbalExpressions)
45+
- [PHP](https://github.com/VerbalExpressions/PHPVerbalExpressions)
46+
- [Python](https://github.com/VerbalExpressions/PythonVerbalExpressions)
47+
- [C#](https://github.com/VerbalExpressions/CSharpVerbalExpressions)
48+
- [Objective-C](https://github.com/VerbalExpressions/ObjectiveCVerbalExpressions)
49+
- [Ruby](https://github.com/ryan-endacott/verbal_expressions)
50+
- [Groovy](https://github.com/VerbalExpressions/GroovyVerbalExpressions)
51+
- [Haskell](https://github.com/VerbalExpressions/HaskellVerbalExpressions)
52+
- [C++](https://github.com/VerbalExpressions/CppVerbalExpressions)

src/test/java/VerbalExpressionUnitTests.java renamed to src/test/java/BasicFunctionalityUnitTests.java

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import org.junit.Ignore;
44
import static org.junit.Assert.*;
55

6-
public class VerbalExpressionUnitTests {
6+
public class BasicFunctionalityUnitTests {
77

88
@Test
99
public void testSomething() {
@@ -24,7 +24,6 @@ public void testAnything() {
2424
assertTrue(testRegex.test(testString));
2525
}
2626

27-
@Ignore ("Test not ready yet")
2827
@Test
2928
public void testAnythingBut() {
3029
VerbalExpression testRegex = new VerbalExpression ()
@@ -79,9 +78,11 @@ public void testMaybe () {
7978
.startOfLine()
8079
.then("a")
8180
.maybe("b");
81+
82+
assertEquals("Regex isn't correct", testRegex.toString(), "^(a)(b)?");
8283
String testString = "acb";
83-
assertTrue("Maybe has a 'b' after an 'a'", testRegex.test(testString));
8484

85+
assertTrue("Maybe has a 'b' after an 'a'", testRegex.test(testString));
8586
testString = "abc";
8687
assertTrue("Maybe has a 'b' after an 'a'", testRegex.test(testString));
8788
}
@@ -166,11 +167,10 @@ public void testWithAnyCase () {
166167
.then("a");
167168
String testString = "A";
168169
assertFalse("not case insensitive", testRegex.test(testString));
169-
170170
testRegex = new VerbalExpression ()
171-
.startOfLine()
172-
.then("a")
173-
.withAnyCase();
171+
.startOfLine()
172+
.then("a")
173+
.withAnyCase();
174174
testString = "A";
175175
assertTrue("case insensitive", testRegex.test(testString));
176176

@@ -199,18 +199,4 @@ public void testSearchOneLine () {
199199
testString = "a\nb";
200200
assertTrue("b is on the second line but we are only searching the first", testRegex.test(testString));
201201
}
202-
203-
/*@Before
204-
public void setUp(){
205-
value1=3;
206-
value2=3;
207-
}
208-
209-
// test method to add two values
210-
@Ignore ("Test not ready yet")
211-
@Test
212-
public void testAdd(){
213-
double result= value1 + value2;
214-
assertTrue(result == 6);
215-
}*/
216202
}

src/test/java/RealWorldUnitTests.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import org.junit.Test;
2+
import org.junit.Before;
3+
import org.junit.Ignore;
4+
import static org.junit.Assert.*;
5+
6+
public class RealWorldUnitTests {
7+
8+
@Test
9+
public void testUrl() {
10+
VerbalExpression testRegex = new VerbalExpression ()
11+
.startOfLine()
12+
.then("http")
13+
.maybe("s")
14+
.then("://")
15+
.maybe("www.")
16+
.anythingBut(" ")
17+
.endOfLine();
18+
19+
// Create an example URL
20+
String testUrl = "https://www.google.com";
21+
assertTrue("Matches Google's url",testRegex.test(testUrl)); //True
22+
23+
assertEquals("Regex doesn't match same regex as in example", testRegex.toString(), "^(http)(s)?(\\:\\/\\/)(www\\.)?([^\\ ]*)$");
24+
}
25+
}

src/test/java/TestRunner.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
public class TestRunner {
66
public static void main(String[] args) {
7-
Result result = JUnitCore.runClasses(VerbalExpressionUnitTests.class);
7+
Result result = JUnitCore.runClasses(TestSuite.class);
88
for (Failure failure : result.getFailures()) {
99
System.out.println(failure.toString());
1010
}

src/test/java/TestSuite.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
//JUnit Suite Test
55
@RunWith(Suite.class)
66
@Suite.SuiteClasses({
7-
VerbalExpressionUnitTests.class
7+
BasicFunctionalityUnitTests.class,
8+
RealWorldUnitTests.class
89
})
910
public class TestSuite {
1011

0 commit comments

Comments
 (0)