Skip to content

Commit

Permalink
Modify README and unit tests broken into Real world and basic func.
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
es committed Aug 15, 2013
1 parent 7412c71 commit de00a86
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 23 deletions.
48 changes: 48 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,52 @@
[![Build Status](https://travis-ci.org/VerbalExpressions/JavaVerbalExpressions.png)](https://travis-ci.org/VerbalExpressions/JavaVerbalExpressions)
JavaVerbalExpressions
=====================
VerbalExpressions is a Java library that helps to construct difficult regular expressions - ported from the wonderful [JSVerbalExpressions](https://github.com/VerbalExpressions/JSVerbalExpressions).

##Examples
```java

VerbalExpression testRegex = new VerbalExpression ()
.startOfLine()
.then("http")
.maybe("s")
.then("://")
.maybe("www.")
.anythingBut(" ")
.endOfLine();

// Create an example URL
String url = "https://www.google.com";

// Use VerbalExpression's testExact() method to test if the entire string matches
// the regex
testRegex.testExact(url); //True

testRegex.toString(); // Ouputs the regex used:
// ^(http)(s)?(\:\/\/)(www\.)?([^\ ]*)$

VerbalExpression testRegex = new VerbalExpression ()
.startOfLine()
.then("abc")
.or("def");

String testString = "defzzz";

//Use VerbalExpression's test() method to test if parts if the string match the regex
testRegex.test(testString); //true
testRegex.testExact(testString); //false


```

## Other implementations
You can view all implementations on [VerbalExpressions.github.io](http://VerbalExpressions.github.io)
- [Javascript](https://github.com/VerbalExpressions/JSVerbalExpressions)
- [PHP](https://github.com/VerbalExpressions/PHPVerbalExpressions)
- [Python](https://github.com/VerbalExpressions/PythonVerbalExpressions)
- [C#](https://github.com/VerbalExpressions/CSharpVerbalExpressions)
- [Objective-C](https://github.com/VerbalExpressions/ObjectiveCVerbalExpressions)
- [Ruby](https://github.com/ryan-endacott/verbal_expressions)
- [Groovy](https://github.com/VerbalExpressions/GroovyVerbalExpressions)
- [Haskell](https://github.com/VerbalExpressions/HaskellVerbalExpressions)
- [C++](https://github.com/VerbalExpressions/CppVerbalExpressions)
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import org.junit.Ignore;
import static org.junit.Assert.*;

public class VerbalExpressionUnitTests {
public class BasicFunctionalityUnitTests {

@Test
public void testSomething() {
Expand All @@ -24,7 +24,6 @@ public void testAnything() {
assertTrue(testRegex.test(testString));
}

@Ignore ("Test not ready yet")
@Test
public void testAnythingBut() {
VerbalExpression testRegex = new VerbalExpression ()
Expand Down Expand Up @@ -79,9 +78,11 @@ public void testMaybe () {
.startOfLine()
.then("a")
.maybe("b");

assertEquals("Regex isn't correct", testRegex.toString(), "^(a)(b)?");
String testString = "acb";
assertTrue("Maybe has a 'b' after an 'a'", testRegex.test(testString));

assertTrue("Maybe has a 'b' after an 'a'", testRegex.test(testString));
testString = "abc";
assertTrue("Maybe has a 'b' after an 'a'", testRegex.test(testString));
}
Expand Down Expand Up @@ -166,11 +167,10 @@ public void testWithAnyCase () {
.then("a");
String testString = "A";
assertFalse("not case insensitive", testRegex.test(testString));

testRegex = new VerbalExpression ()
.startOfLine()
.then("a")
.withAnyCase();
.startOfLine()
.then("a")
.withAnyCase();
testString = "A";
assertTrue("case insensitive", testRegex.test(testString));

Expand Down Expand Up @@ -199,18 +199,4 @@ public void testSearchOneLine () {
testString = "a\nb";
assertTrue("b is on the second line but we are only searching the first", testRegex.test(testString));
}

/*@Before
public void setUp(){
value1=3;
value2=3;
}
// test method to add two values
@Ignore ("Test not ready yet")
@Test
public void testAdd(){
double result= value1 + value2;
assertTrue(result == 6);
}*/
}
25 changes: 25 additions & 0 deletions src/test/java/RealWorldUnitTests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import org.junit.Test;
import org.junit.Before;
import org.junit.Ignore;
import static org.junit.Assert.*;

public class RealWorldUnitTests {

@Test
public void testUrl() {
VerbalExpression testRegex = new VerbalExpression ()
.startOfLine()
.then("http")
.maybe("s")
.then("://")
.maybe("www.")
.anythingBut(" ")
.endOfLine();

// Create an example URL
String testUrl = "https://www.google.com";
assertTrue("Matches Google's url",testRegex.test(testUrl)); //True

assertEquals("Regex doesn't match same regex as in example", testRegex.toString(), "^(http)(s)?(\\:\\/\\/)(www\\.)?([^\\ ]*)$");
}
}
2 changes: 1 addition & 1 deletion src/test/java/TestRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

public class TestRunner {
public static void main(String[] args) {
Result result = JUnitCore.runClasses(VerbalExpressionUnitTests.class);
Result result = JUnitCore.runClasses(TestSuite.class);
for (Failure failure : result.getFailures()) {
System.out.println(failure.toString());
}
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/TestSuite.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
//JUnit Suite Test
@RunWith(Suite.class)
@Suite.SuiteClasses({
VerbalExpressionUnitTests.class
BasicFunctionalityUnitTests.class,
RealWorldUnitTests.class
})
public class TestSuite {

Expand Down

0 comments on commit de00a86

Please sign in to comment.