Author: sebb Date: Tue Nov 18 14:32:33 2008 New Revision: 718745 URL: http://svn.apache.org/viewvc?rev=718745&view=rev Log: Fix regex function - was failing to process $m$mid$n$ correctly
Modified: jakarta/jmeter/trunk/src/functions/org/apache/jmeter/functions/RegexFunction.java jakarta/jmeter/trunk/test/src/org/apache/jmeter/functions/TestRegexFunction.java jakarta/jmeter/trunk/xdocs/changes.xml Modified: jakarta/jmeter/trunk/src/functions/org/apache/jmeter/functions/RegexFunction.java URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/functions/org/apache/jmeter/functions/RegexFunction.java?rev=718745&r1=718744&r2=718745&view=diff ============================================================================== --- jakarta/jmeter/trunk/src/functions/org/apache/jmeter/functions/RegexFunction.java (original) +++ jakarta/jmeter/trunk/src/functions/org/apache/jmeter/functions/RegexFunction.java Tue Nov 18 14:32:33 2008 @@ -60,7 +60,9 @@ private static final List desc = new LinkedList(); - private Pattern templatePattern;// initialised to the regex \$(\d+)\$ + private static final String TEMPLATE_PATTERN = "\\$(\\d+)\\$"; //$NON-NLS-1$ + /** initialised to the regex \$(\d+)\$ */ + private final Pattern templatePattern; // Number of parameters expected - used to reject invalid calls private static final int MIN_PARAMETER_COUNT = 2; @@ -77,11 +79,7 @@ } public RegexFunction() { - initPattern(); - } - - private void initPattern() { - templatePattern = JMeterUtils.getPatternCache().getPattern("\\$(\\d+)\\$", //$NON-NLS-1$ + templatePattern = JMeterUtils.getPatternCache().getPattern(TEMPLATE_PATTERN, Perl5Compiler.READ_ONLY_MASK); } @@ -242,8 +240,11 @@ PatternMatcher matcher = JMeterUtils.getMatcher(); Util.split(pieces, matcher, templatePattern, rawTemplate); PatternMatcherInput input = new PatternMatcherInput(rawTemplate); - Iterator iter = pieces.iterator(); boolean startsWith = isFirstElementGroup(rawTemplate); + if (startsWith) { + pieces.remove(0);// Remove initial empty entry + } + Iterator iter = pieces.iterator(); while (iter.hasNext()) { boolean matchExists = matcher.contains(input, templatePattern); if (startsWith) { Modified: jakarta/jmeter/trunk/test/src/org/apache/jmeter/functions/TestRegexFunction.java URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/test/src/org/apache/jmeter/functions/TestRegexFunction.java?rev=718745&r1=718744&r2=718745&view=diff ============================================================================== --- jakarta/jmeter/trunk/test/src/org/apache/jmeter/functions/TestRegexFunction.java (original) +++ jakarta/jmeter/trunk/test/src/org/apache/jmeter/functions/TestRegexFunction.java Tue Nov 18 14:32:33 2008 @@ -127,6 +127,158 @@ assertEquals("times", vars.getObject("OUTVAR_g2")); } + public void testVariableExtractionFromVariable2() throws Exception { + params = new LinkedList(); + params.add(new CompoundVariable("(\\d+)\\s+(\\w+)")); + params.add(new CompoundVariable("$1$$2$")); // template + params.add(new CompoundVariable("1")); // match number + params.add(new CompoundVariable("-")); // ALL separator + params.add(new CompoundVariable("default")); + params.add(new CompoundVariable("OUTVAR")); + params.add(new CompoundVariable(INPUT_VARIABLE_NAME)); + variable.setParameters(params); + String match = variable.execute(result, null); + assertEquals("1", vars.getObject("OUTVAR_matchNr")); + assertEquals("123times", match); + assertEquals("123times", vars.getObject("OUTVAR")); + assertEquals("123 times", vars.getObject("OUTVAR_g0")); + assertEquals("123", vars.getObject("OUTVAR_g1")); + assertEquals("times", vars.getObject("OUTVAR_g2")); + } + + public void testVariableExtractionFromVariable3() throws Exception { + params = new LinkedList(); + params.add(new CompoundVariable("(\\d+)\\s+(\\w+)")); + params.add(new CompoundVariable("pre$2$post")); // template + params.add(new CompoundVariable("1")); // match number + params.add(new CompoundVariable("-")); // ALL separator + params.add(new CompoundVariable("default")); + params.add(new CompoundVariable("OUTVAR")); + params.add(new CompoundVariable(INPUT_VARIABLE_NAME)); + variable.setParameters(params); + String match = variable.execute(result, null); + assertEquals("1", vars.getObject("OUTVAR_matchNr")); + assertEquals("pretimespost", match); + assertEquals("pretimespost", vars.getObject("OUTVAR")); + assertEquals("123 times", vars.getObject("OUTVAR_g0")); + assertEquals("123", vars.getObject("OUTVAR_g1")); + assertEquals("times", vars.getObject("OUTVAR_g2")); + } + + public void testVariableExtractionFromVariable4() throws Exception { + params = new LinkedList(); + params.add(new CompoundVariable("(\\d+)\\s+(\\w+)")); + params.add(new CompoundVariable("pre$2$")); // template + params.add(new CompoundVariable("1")); // match number + params.add(new CompoundVariable("-")); // ALL separator + params.add(new CompoundVariable("default")); + params.add(new CompoundVariable("OUTVAR")); + params.add(new CompoundVariable(INPUT_VARIABLE_NAME)); + variable.setParameters(params); + String match = variable.execute(result, null); + assertEquals("1", vars.getObject("OUTVAR_matchNr")); + assertEquals("pretimes", match); + assertEquals("pretimes", vars.getObject("OUTVAR")); + assertEquals("123 times", vars.getObject("OUTVAR_g0")); + assertEquals("123", vars.getObject("OUTVAR_g1")); + assertEquals("times", vars.getObject("OUTVAR_g2")); + } + + public void testVariableExtractionFromVariable5() throws Exception { + params = new LinkedList(); + params.add(new CompoundVariable("(\\d+)\\s+(\\w+)")); + params.add(new CompoundVariable("$2$post")); // template + params.add(new CompoundVariable("1")); // match number + params.add(new CompoundVariable("-")); // ALL separator + params.add(new CompoundVariable("default")); + params.add(new CompoundVariable("OUTVAR")); + params.add(new CompoundVariable(INPUT_VARIABLE_NAME)); + variable.setParameters(params); + String match = variable.execute(result, null); + assertEquals("1", vars.getObject("OUTVAR_matchNr")); + assertEquals("timespost", match); + assertEquals("timespost", vars.getObject("OUTVAR")); + assertEquals("123 times", vars.getObject("OUTVAR_g0")); + assertEquals("123", vars.getObject("OUTVAR_g1")); + assertEquals("times", vars.getObject("OUTVAR_g2")); + } + + public void testVariableExtractionFromVariable6() throws Exception { + params = new LinkedList(); + params.add(new CompoundVariable("(\\d+)\\s+(\\w+)")); + params.add(new CompoundVariable("$2$$2$")); // template + params.add(new CompoundVariable("1")); // match number + params.add(new CompoundVariable("-")); // ALL separator + params.add(new CompoundVariable("default")); + params.add(new CompoundVariable("OUTVAR")); + params.add(new CompoundVariable(INPUT_VARIABLE_NAME)); + variable.setParameters(params); + String match = variable.execute(result, null); + assertEquals("1", vars.getObject("OUTVAR_matchNr")); + assertEquals("timestimes", match); + assertEquals("timestimes", vars.getObject("OUTVAR")); + assertEquals("123 times", vars.getObject("OUTVAR_g0")); + assertEquals("123", vars.getObject("OUTVAR_g1")); + assertEquals("times", vars.getObject("OUTVAR_g2")); + } + + public void testVariableExtractionFromVariable7() throws Exception { + params = new LinkedList(); + params.add(new CompoundVariable("(\\d+)\\s+(\\w+)")); + params.add(new CompoundVariable("pre$1$mid$2$post")); // template + params.add(new CompoundVariable("1")); // match number + params.add(new CompoundVariable("-")); // ALL separator + params.add(new CompoundVariable("default")); + params.add(new CompoundVariable("OUTVAR")); + params.add(new CompoundVariable(INPUT_VARIABLE_NAME)); + variable.setParameters(params); + String match = variable.execute(result, null); + assertEquals("1", vars.getObject("OUTVAR_matchNr")); + assertEquals("pre123midtimespost", match); + assertEquals("pre123midtimespost", vars.getObject("OUTVAR")); + assertEquals("123 times", vars.getObject("OUTVAR_g0")); + assertEquals("123", vars.getObject("OUTVAR_g1")); + assertEquals("times", vars.getObject("OUTVAR_g2")); + } + + public void testVariableExtractionFromVariable8() throws Exception { + params = new LinkedList(); + params.add(new CompoundVariable("(\\d+)\\s+(\\w+)")); + params.add(new CompoundVariable("pre$1$mid$2$")); // template + params.add(new CompoundVariable("1")); // match number + params.add(new CompoundVariable("-")); // ALL separator + params.add(new CompoundVariable("default")); + params.add(new CompoundVariable("OUTVAR")); + params.add(new CompoundVariable(INPUT_VARIABLE_NAME)); + variable.setParameters(params); + String match = variable.execute(result, null); + assertEquals("1", vars.getObject("OUTVAR_matchNr")); + assertEquals("pre123midtimes", match); + assertEquals("pre123midtimes", vars.getObject("OUTVAR")); + assertEquals("123 times", vars.getObject("OUTVAR_g0")); + assertEquals("123", vars.getObject("OUTVAR_g1")); + assertEquals("times", vars.getObject("OUTVAR_g2")); + } + + public void testVariableExtractionFromVariable9() throws Exception { + params = new LinkedList(); + params.add(new CompoundVariable("(\\d+)\\s+(\\w+)")); + params.add(new CompoundVariable("$1$mid$2$post")); // template + params.add(new CompoundVariable("1")); // match number + params.add(new CompoundVariable("-")); // ALL separator + params.add(new CompoundVariable("default")); + params.add(new CompoundVariable("OUTVAR")); + params.add(new CompoundVariable(INPUT_VARIABLE_NAME)); + variable.setParameters(params); + String match = variable.execute(result, null); + assertEquals("1", vars.getObject("OUTVAR_matchNr")); + assertEquals("123midtimespost", match); + assertEquals("123midtimespost", vars.getObject("OUTVAR")); + assertEquals("123 times", vars.getObject("OUTVAR_g0")); + assertEquals("123", vars.getObject("OUTVAR_g1")); + assertEquals("times", vars.getObject("OUTVAR_g2")); + } + public void testVariableExtraction2() throws Exception { params = new LinkedList(); params.add(new CompoundVariable("<value field=\"(pinposition\\d+)\">(\\d+)</value>")); Modified: jakarta/jmeter/trunk/xdocs/changes.xml URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/xdocs/changes.xml?rev=718745&r1=718744&r2=718745&view=diff ============================================================================== --- jakarta/jmeter/trunk/xdocs/changes.xml (original) +++ jakarta/jmeter/trunk/xdocs/changes.xml Tue Nov 18 14:32:33 2008 @@ -166,6 +166,7 @@ <li>JMSPublisher and Subscriber fixes: thread-safety, support dynamic locale changes, locale independence for JMX attribute values</li> <li>Add HeaderAsPropertyRenderer to support header resource names; use this to fix locale changes in various GUI elements</li> <li>Fixed language change handling for menus (does not yet work for TestBeans)</li> +<li>Fix regex function - was failing to process $m$mid$n$ correctly</li> </ul> <h3>Improvements</h3> --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]