Skip to content

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

@mikhail-putilov

Description

@mikhail-putilov

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions