-
Notifications
You must be signed in to change notification settings - Fork 241
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
5 changed files
with
83 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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\\.)?([^\\ ]*)$"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters