Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regex with a dollar sign and a cap sign seems to be buggy during stub generation. (This ticket contains tests.) #899

Closed
mikhail-putilov opened this issue Feb 28, 2019 · 3 comments

Comments

@mikhail-putilov
Copy link
Contributor

mikhail-putilov commented Feb 28, 2019

Bug report

Spring cloud version: 2.1.0.RELEASE. I added new methods to XegerTest which reproduce minimal failing test cases:

package repackaged.nl.flotsam.xeger;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertFalse;

public class XegerTest {

	/**
	 * Add general expectations for developers with different knowledge background about regex 
	 */
	@Test
	public void generalExpectationsAboutPipeAndCompiledFlag() {
		String regexAbc = "|abc";
		assertTrue("".matches(regexAbc));
		assertTrue("abc".matches(regexAbc));

		// note that regex is compiled with a flag of zero. Which means that this is false:
		assertFalse("aabc".matches(regexAbc));
	}

	@Test
	public void shouldGenerateTextCorrectlyWithDollarSignInTheEnd() {
		String regex = ".*$";
		// baseline assumption:
		assertTrue("".matches(regex));
		assertTrue("a".matches(regex));

		Xeger generator = new Xeger(regex);
		for (int i = 0; i < 100; i++) {
			String text = generator.generate();
			assertTrue(text.matches(regex));
		}
	}

	@Test
	public void shouldGenerateTextCorrectlyWithCapSignInTheBegging() {
		String regex = "^b*";
		// baseline assumption:
		assertTrue("".matches(regex));
		assertTrue("b".matches(regex));

		Xeger generator = new Xeger(regex);
		for (int i = 0; i < 100; i++) {
			String text = generator.generate();
			assertTrue(text.matches(regex));
		}
	}

	@Test
	public void shouldGenerateTextCorrectlyWithPipeAndDollarSign() {
		String regex = ".$|bca";
		// baseline assumption:
		assertTrue("b".matches(regex));
		assertTrue("bca".matches(regex));
		assertFalse("".matches(regex));
		assertFalse("bc".matches(regex));

		Xeger generator = new Xeger(regex);
		for (int i = 0; i < 100; i++) {
			String text = generator.generate();
			assertTrue(text.matches(regex));
		}
	}

	@Test
	public void shouldGenerateTextCorrectlyWithPipeAndEmptyExpression() {
		String regex = "|bca";
		// baseline assumption:
		assertTrue("".matches(regex));
		assertTrue("bca".matches(regex));
		assertFalse(" ".matches(regex));

		Xeger generator = new Xeger(regex);
		for (int i = 0; i < 100; i++) {
			String text = generator.generate();
			assertTrue(text.matches(regex));
		}
	}
}

For me, it looks like if a developer doesn't know those details about a regex engine beihind, he or she is doomed to spend a lot of time debugging things. Please, take a closer look at Xeger.

@OlgaMaciaszek
Copy link
Collaborator

@mikhail-putilov Thanks for reporting this. We have looked at various regex engines and have not found anything better. However, I guess we should add this info to the documentation. Would you be interested in contributing a short paragraph about the possible expected vs. actual behaviours of the engine to our docs as PR?

@mikhail-putilov
Copy link
Contributor Author

mikhail-putilov commented Mar 5, 2019

Sure, will do on an upcoming weekend

@mikhail-putilov
Copy link
Contributor Author

@OlgaMaciaszek done
I'm open to change if something is wrong from my side :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants