-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change regexp generation library to RgxGen
- Loading branch information
1 parent
f615f30
commit 4d02923
Showing
5 changed files
with
124 additions
and
61 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
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
57 changes: 57 additions & 0 deletions
57
...e-monkey-api/src/test/java/com/navercorp/fixturemonkey/api/random/RegexGeneratorTest.java
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,57 @@ | ||
package com.navercorp.fixturemonkey.api.random; | ||
|
||
import static org.assertj.core.api.BDDAssertions.then; | ||
import static org.assertj.core.api.BDDAssertions.thenThrownBy; | ||
|
||
import java.util.List; | ||
import java.util.regex.Pattern; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
public class RegexGeneratorTest { | ||
private static final RegexGenerator SUT = new RegexGenerator(); | ||
private static final int FLAG_CASE_INSENSITIVE = 2; | ||
|
||
@Test | ||
void regExpGenerationSuccess() { | ||
String emailRegex = "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$"; | ||
List<String> strings = SUT.generateAll(emailRegex, new int[] {}, null, null); | ||
|
||
Pattern pattern = Pattern.compile(emailRegex); | ||
then(strings).allMatch(it -> pattern.matcher(it).matches()); | ||
} | ||
|
||
@Test | ||
void generateRegExpWithCaseInsensitiveFlag() { | ||
List<String> strings = SUT.generateAll("a", new int[] {FLAG_CASE_INSENSITIVE}, null, null); | ||
|
||
then("a").isIn(strings); | ||
then("A").isIn(strings); | ||
} | ||
|
||
@Test | ||
void generateRegExpWithMinMaxLength() { | ||
List<String> strings = SUT.generateAll("^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$", new int[] {}, 3, 7); | ||
|
||
then(strings).allMatch(it -> it.length() >= 3 && it.length() <= 7); | ||
} | ||
|
||
@Test | ||
void generateInvalidRegExpThrows() { | ||
thenThrownBy( | ||
() -> SUT.generateAll("^^a", new int[] {}, null, null) | ||
).isExactlyInstanceOf(IllegalArgumentException.class); | ||
} | ||
|
||
@Test | ||
void generateIncalculableRegExpThrows() { | ||
thenThrownBy( | ||
() -> SUT.generateAll( | ||
"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$", | ||
new int[] {}, | ||
20, | ||
null | ||
) | ||
).isExactlyInstanceOf(IllegalArgumentException.class); | ||
} | ||
} |
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