Commit Graph
96 Commits
Author SHA1 Message Date
Miguel de Icaza c6ab899595 [System] Fix most warnings on the System test suite 2014-09-24 10:43:46 -04:00
Dave Dunkin cd364b4374 Add test for Regex RTL substring matching. 2014-08-05 08:51:38 -07:00
Dave Dunkin 509863e570 Add test for Regex.Match with anchors on a substring. 2014-08-04 14:42:34 -07:00
Marek Safar f0ad346fb6 Mobile tests update 2013-02-22 21:41:19 +01:00
Bojan Rajkovic 1bbb0f0880 Revert "Bug 2663: Regular Expression Bug Fixes"
This reverts commit dc6efdab29. This
patch completely regressed performance for regexes in the same class
as the regexes it fixed. Xamarin bug #6198 details the regressions,
and I've confirmed that reverting this commit fixes the 2 order of
magnitude performance drop (with the patch, the test takes almost 7
seconds, without it, it takes .07 seconds). The bug still needs to be
fixed, but this is not the right fix.
2012-10-17 12:35:57 -04:00
Rob Wilkens 60a463c6f3 Bug 2663: Regular Expression Bug Fixes
What this fixes:
IF you were checking a regex which contained something like "(A|AB)C" and then you
checked something like "ABC" against it, it would fail previously, because its
first trip thru the regex it would match "A" first and short circuit out of the
"or" (|)  then next try to match "C" but find "B" and fail.  In this case, it should
be obvious that it needs to, after it fails, go back and try "AB" rather than "A"
and that's where this patch comes in.

Brief summary of each change in order that "git diff --staged" is giving them to
me:

This first one summarizes the background of goal of project:
New Function: EmitJumpTest
For when we are evaluating Alternatives (or's) we now want to be able to go back
and try or paths we haven't already tried if and only if we fail.  This alternate to
EmitJump instead of jumping to target if we have a match immediately, will
on first attempt do the jump, but later if we have already tried this jump
combination, it will jump to ElseTarget, which is the equivalent of this test
failing on subsequent attempts with the same combination of 'or's passing.

RxCompiler:
EmitJumpTest isn't implemented for RxCompiler because i didn't have sample
code to test it on, so it falls back to a regular jump, nothing changes in
RxCompiler in other words other than having this required fucntion front.

arch.cs:
New OpCode added for JumpTest (see EmitJumpTest above)

compiler.cs:
EmitJumpTest added here for regular compiler, it now takes two arguments (two
items on stack) first was the standard where to jump to address, the second
argument is where to jump to in case where we have already tried this
combination)

interpreter.cs:

JumpTestEntry - What we keep track of to know if we've been here before, for
now i presumed just 'pc' (program counter') and 'ptr' (pointer - where we are)
were enough to tell us if we've been to this particular spot before.

Eval has been moved into Eval_Real

Eval if it gets called with parameters indicating we've already been here
(i.e we're being called recursively) just passes the call directly to eval_real
as-was.

Otherwise eval will loop on eval_real while we fail and haven't tried every
possible path through all the or's. (Note: The special case of where we're
running a 'test' (i.e. checking !(a|b|c) rather than just matching (a|b|c)),
and if we're running a test, we turn off JumpTestTracking while it's in its
recursive section.  The reason for this is because while we can rightly check
all the options of (a|ab|abc)  first for a then try again with ab then try again
with abc, we cannot do the same for a not (i.e. !(something or something else)
is really (not something AND not somtehing else), and it is not (not something
or not something else))

JumpTestList tracks our current run's JumpTest calls...
TriedCombo's tracks all the combos (all the JumpTestList results) that we've
already tried.

All calls to anything which calls Eval were modified to call eval passing
the optional new parameters that we now need, and remember if we call
eval with those parameters having a value, it will just forward the call
to Eval_Real.

This included modifying TryMatch because it calls Eval.

OpCode.JumpTest handler was added, what it does is first check if we need
to ByPass to jump to 'else' right away, which again happens when we're in
a test recursive call (Checking not, for example).
Next, it will create and populate a new JumpTestEntry with the current values.
It then calls CheckComboMatch() which sees if we match a combo already on file.
If we don't have a Match we jump to the first label (at pc+1) which is the
regular jump call.  If we have a match, though, it will jump to the else label
which is now at (pc+2).

CheckComboMatch had to be broken up into two functions because it was going
too deep in terms of nesting.  What it does by now should be somewhat understood
it will see if we have a match between our current run and previous runs, and
if we have a match, it returns true.  If we don't have a match, it returns
false.  I have some doubts about whether this function is 100% correct, there
may remain a bug or two, but it does pass all the "System" unit tests which
includes all the regular expression tests, plus it works for all the tests
in the bug report, so i have little reason to mess with it.

syntax.cs:
Here's where i modified so that when evaluating alternatives ("or"s or "|"s)
we instead call EmitJumpTest rather than just a regular EmitJump.

RegExBugs.cs:
This is the unit test (a bunch in one) which fails on mono without this patch
but succeeds with it
commit 48027ac2bdd9b60d18985ec2537eb188607f8164 1 parent 91c4180d55

This patch was originally submitted under another branch which had a bunch of
unrelated commits in it.  I'm hoping if i did this right, these changes stand
alone.
2012-06-18 07:38:57 -04:00
Miguel de Icaza 183e538e52 2010-07-20 Miguel de Icaza <[email protected]>
* parser.cs (ParseEscape): Now parses with some context, whether
	we are parsing inside a character range which can not contain
	back-references or when we are parsing on a string context which
	can contain back references.

	This fixes bug #577346 which exposed a bug parsing this:

	new Regex("[\\177-\\377]")



svn path=/trunk/mcs/; revision=160626
2010-07-20 17:31:31 +00:00
Raja R Harinath 1dc4bea327 Revert "processed with astyle" (SVN r159583)
svn path=/trunk/mcs/; revision=159587
2010-06-28 06:39:43 +00:00
C.J. Adams-Collier 56886b8c11 processed with astyle
svn path=/trunk/mcs/; revision=159583
2010-06-27 20:11:26 +00:00
Rodrigo Kumpera 8f2c8508de 2010-06-21 Rodrigo Kumpera <[email protected]>
* RegexBugs.cs: Regression test for #610587.

svn path=/trunk/mcs/; revision=159293
2010-06-21 20:36:17 +00:00
C.J. Adams-Collier 33142e1b47 first pass at adding RegexOption.Compiled to constructor in tests
svn path=/trunk/mcs/; revision=158888
2010-06-14 17:36:45 +00:00
Rodrigo Kumpera 3905873f3c 2010-02-03 Rodrigo Kumpera <[email protected]>
* SplitTests.cs: New tests for #566117.

svn path=/trunk/mcs/; revision=150787
2010-02-03 21:10:25 +00:00
Raja R Harinath ce41ff407f Check in up-to-date version of RegexTest.cs. Somehow the previous
checkin got an untested preliminary version

svn path=/trunk/mcs/; revision=141530
2009-09-08 15:12:38 +00:00
Jonathan Pobst cc73e26443 - Fix System tests build. (There were two tests named Split_InvalidCount.)
svn path=/trunk/mcs/; revision=141525
2009-09-08 14:26:08 +00:00
Raja R Harinath 2d8031df3c regex: A few more null and bounds checks
* Regex.cs (Escape, Unescape): Add null checks.
(validate_options): Add ECMAScript option checks.
(Replace, Split): Add a few bounds checks.

svn path=/trunk/mcs/; revision=141459
2009-09-07 17:14:37 +00:00
Raja R Harinath e8d4a97211 Add some null checks and bounds checks.
* Regex.cs (default_startat): New.  Replaces the fragment
'RightToLeft ?  input.Length : 0' with a null-safe variant.
(Replace) <string variant>: Add null checks for argument strings.
(Split): Likewise.
(.ctor): Likewise.  Validate regex options partially.
(Match): Add null check on string arguments, and bounds checks for
offset and length arguments.

svn path=/trunk/mcs/; revision=141457
2009-09-07 16:25:50 +00:00
Raja R Harinath 66fee73c0a Final piece of explicit numeric group support
* parser.cs (gap): New.
(GetMapping): Return it.
(ResolveReferences): Collect explicit numeric groups which may not
match their indices.
(HandleExplicitNumericGroups): New.  Process the above list to
assign appropriate indices, and compute the correct value of 'gap'.

svn path=/trunk/mcs/; revision=140290
2009-08-19 20:43:01 +00:00
Raja R Harinath 4735fd50bc * parser.cs (GetMapping): Extend duplicate check for numeric groups too.
svn path=/trunk/mcs/; revision=140097
2009-08-17 19:26:40 +00:00
Raja R Harinath 51c4ad074a * parser.cs (ResolveReferences): Handle some cases of explicitly-named numeric groups.
svn path=/trunk/mcs/; revision=140096
2009-08-17 19:26:18 +00:00
Raja R Harinath 58b4f2fb60 * RegexTrial.cs (Execute): Prepare to handle dis-contiguous group numbers.
svn path=/trunk/mcs/; revision=140052
2009-08-17 12:28:23 +00:00
Raja R Harinath 1163a482f7 regexp backreferences: Implement fallback to octal numbers, and ECMAScript semantics.
* syntax.cs (BackslashNumber.ResolveReference): Implement fallback
to octal numbers, and ECMAScript semantics.
* parser.cs (ResolveReferences): Use it.
* RegexMatchTests.cs (RegexTrial0054..60): New.

svn path=/trunk/mcs/; revision=139657
2009-08-10 16:25:10 +00:00
Raja R Harinath 88c39f81b9 Regex.IsMatch("abcab", @"(?<ab>ab)c\1")
* System.Text.RegularExpressions/parser.cs (ResolveReferences):
Allow named groups to be referred-to by their group numbers too.
* RegexMatchTests.cs (RegexTrial0053): New.

svn path=/trunk/mcs/; revision=139655
2009-08-10 16:24:21 +00:00
Jonathan Pryor 247cfd34f0 * System.Text.RegularExpressions/Regex.cs (Replace): Check that input &
evaluator are not null, as documented in MSDN (and the variance found 
	  while testing DbLinq).
	* Test/System.Text.RegularExpressions/RegexReplace.cs: Add null 
	  argument checks for Regex.Replace().

svn path=/trunk/mcs/; revision=128241
2009-02-27 21:40:17 +00:00
Zoltan Varga 38444bef3b 2009-01-14 Zoltan Varga <[email protected]>
* RegexTrial.cs: Run all tests with the CIL Compiler too.

svn path=/trunk/mcs/; revision=123419
2009-01-14 21:36:01 +00:00
Zoltan Varga ebd4ba561f 2009-01-14 Zoltan Varga <[email protected]>
* RegexBugs.cs: Add a test for #466151.

svn path=/trunk/mcs/; revision=123418
2009-01-14 21:34:46 +00:00
Gert Driesen 5bf5128a72 * RegexBugs.cs: added test for bug #443841.
svn path=/trunk/mcs/; revision=118761
2008-11-13 20:20:00 +00:00
Gonzalo Paniagua Javier a9497316ff 2008-11-11 Gonzalo Paniagua Javier <[email protected]>
* RegexBugs.cs: test from bug 432172.


svn path=/trunk/mcs/; revision=118512
2008-11-11 16:42:18 +00:00
Gonzalo Paniagua Javier ab2d87302f 2008-10-30 Gonzalo Paniagua Javier <[email protected]>
* RegexBugs.cs: added test from bug #439947.


svn path=/trunk/mcs/; revision=117488
2008-10-30 16:04:57 +00:00
Zoltan Varga a1531dd064 2008-10-09 Zoltan Varga <[email protected]>
* RegexBugs.cs: Add test for #432172.

svn path=/trunk/mcs/; revision=115312
2008-10-09 08:00:46 +00:00
Zoltan Varga 6dad6b5f3b 2008-09-14 Zoltan Varga <[email protected]>
* RegexBugs.cs: Add a test for #426142.

svn path=/trunk/mcs/; revision=112946
2008-09-14 00:07:44 +00:00
Roei Erez ccca1e1079 Fix a bug only in TARGET_JVM that happens when a match contains empty group at the end.
svn path=/trunk/mcs/; revision=104994
2008-06-05 12:06:06 +00:00
Arina Itkes 357ee9ae90 New test for groups with same name. Fix for JvmReMachine.
svn path=/trunk/mcs/; revision=91864
2007-12-24 15:40:41 +00:00
Arina Itkes 074e54f3f8 Max value of m for a construct {n,m} is 2147483647.
svn path=/trunk/mcs/; revision=90629
2007-12-04 10:35:14 +00:00
Raja R Harinath 01dbfb50d5 Fix 324390
In System/System.Text.RegularExpressions:
	* BaseMachine.cs (LTRReplace): Don't use non-advancement of 'ptr'
	to deduce absence of matches -- a match can have length 0.
	(RTLReplace): Likewise.

In System/Test/System.Text.RegularExpressions:
	* RegexReplace.cs (tests): New test from #324390.

svn path=/trunk/mcs/; revision=89176
2007-11-08 03:31:44 +00:00
Raja R Harinath b35097bc0b Support RegexOptions.RightToLeft in Replace().
In b/class/System/System.Text.RegularExpressions:
	* BaseMachine.cs (Replace): Use either LTRReplace or RTLReplace
	based on regex.
	(LTRReplace): Make internal and rename the MatchAppendEvaluator
	version of Replace to this.
	(RTLReplace): New.
	* Regex.cs (Replace): Use LTRReplace and RTLReplace from BaseMachine.
	* replace.cs (ReplacementEvaluator.Evaluate): Optimize simple case.
	Based on patch by Stephane Delcroix.

In b/class/System/Test/System.Text.RegularExpressions:
	* MatchTest.cs (Match_Backref): New.
	* RegexReplace.cs (direction, testcase.direction): New.
	(testcase..ctor): Allow specifying the direction of the replace.
	(ReplaceTests): Test replace in both directions.
	(EvaluatorTests): New test based on #321036.

svn path=/trunk/mcs/; revision=89034
2007-11-06 22:03:35 +00:00
Raja R Harinath baf4cdef81 In System.Text.RegularExpressions:
* replace.cs (Compile): Don't unescape string.

In Test/System.Text.RegularExpressions:
	* RegexReplace.cs (tests): New test from #317092.
	(ReplaceTests): Don't catch an AssertException.

svn path=/trunk/mcs/; revision=89021
2007-11-06 19:28:12 +00:00
Arina Itkes 24bdc004e1 Fix for expected result of 44 test
svn path=/trunk/mcs/; revision=88816
2007-11-04 11:22:13 +00:00
Gert Driesen 99c7c20a33 * RegexReplace.cs: Fixed line endings.
svn path=/trunk/mcs/; revision=88686
2007-11-01 21:19:14 +00:00
Gert Driesen 083af1ff31 * GroupTest.cs: Improved test for null argument check.
* MatchTest.cs: Improved tests for null argument checks. Added and
fixed replacement tests.
* RegexMatchTest.cs: Marked tests that do not pass on MS as NotDotNet.
Fixed expected result for trial 5.
* RegexResultTests.cs: Fixed Assert.
* Match.cs: Do not throw NotSupportedException on zero-length 
replacement argument.

svn path=/trunk/mcs/; revision=88685
2007-11-01 21:17:50 +00:00
Arina Itkes 963b4f5073 Updated changelog fog revision 88355
svn path=/trunk/mcs/; revision=88392
2007-10-29 16:12:39 +00:00
Arina Itkes 120ae48ce4 New tests for Regex:
- for Result method,
- for patterns with number of groups more than 10
- for patterns with ExpicitCapture options

svn path=/trunk/mcs/; revision=88355
2007-10-29 09:15:16 +00:00
Gert Driesen 159ff004eb * RegexBugs.cs: No longer derive from deprecated Assertion class.
Added test for bug #313642.
* MatchTest.cs: Code formatting.
* RegexTest.cs: Fixed compiler warnings. Code formatting. Spaces to
tabs.

svn path=/trunk/mcs/; revision=87864
2007-10-21 09:46:50 +00:00
Gert Driesen bea2c42267 * RegexReplace.cs: Fixed compiler warning.
svn path=/trunk/mcs/; revision=85913
2007-09-17 17:30:51 +00:00
Raja R Harinath 05c754d952 In System.Text.RegularExpressions:
Fix #80554
	* parser.cs (ResolveReferences): Don't throw an expression if a
	capture assertion reference cannot be resolved.
	(ParseGroupingConstruct): Provide fallback expression to a capture
	assertion.
	* syntax.cs (CaptureAssertion): If the bareword doesn't refer to
	the name of a capture group, fallback to treating it as a literal
	expression.

In Test/System.Text.RegularExpressions:
	* RegexBugs.cs (bug80554_trials): New tests based on #80554.

svn path=/trunk/mcs/; revision=75885
2007-04-18 14:52:01 +00:00
Raja R Harinath e1bb85b9d7 * RegexTest.cs (PrimeRegex): New backtracking torture test using
a regex that recognizes composite numbers represented in unary.

svn path=/trunk/mcs/; revision=75388
2007-04-04 14:33:46 +00:00
Raja R Harinath 24bba3fcc8 In System.Text.RegularExpressions:
Fix #79472
	* parser.cs (Parser.GetMapping): Use the actual group numbers to
	build the mapping.

In Test/System.Text.RegularExpressions:
	* RegexBugs.cs (GroupNumbers): New test based on #79472.

svn path=/trunk/mcs/; revision=70374
2007-01-02 17:52:33 +00:00
Raja R Harinath 083ccb79d8 In System.Text.RegularExpressions:
Fix #78278
	Remove 65535-limit on number of repetitions matched by a pattern.
	We still have a 65535 limit on the length of a pattern and the
	number of groups in a pattern.
	* compiler.cs (PatternCompiler.EmitCount): New.  Emits an int as
	two ushorts into the program stream.
	(EmitInfo, EmitRepeat, EmitFastRepeat): Use it to emit integers
	rather than shorts.
	* interpreter.cs (Intepreter.ReadProgramCount): Read an int
	emitted into the program stream.
	(Interpreter): Use it.  Update counts.
	(Interpreter.Eval) [OpCode.Repeat, OpCode.FastRepeat]: Likewise.
	* parser.cs (ParseGroup): Pass 0x7ffffff as the max value for '*'
	and '+' repetition patterns.
	* arch.cs (Info, Repeat, FastRepeat): Update description.

In Test/System.Text.RegularExpressions:
	* RegexBugs.cs (Kill65535_1, Kill65535_2, No65535Limit): New tests
	based on #78278.

svn path=/trunk/mcs/; revision=60401
2006-05-08 13:44:23 +00:00
Raja R Harinath a0072aeec0 In System.Text.RegularExpressions:
2006-04-17  Florian Gross  <[email protected]>
	    Raja R Harinath  <[email protected]>

	* syntax.cs (CharacterClass.Compile): Emit categories after the
	character intervals so that the evaluator can pick up the
	'IgnoreCase' flag.

In Test/System.Text.RegularExpressions:
2006-04-17  Florian Gross  <[email protected]>

	* RegexBugs.cs (CharClassWithIgnoreCase): Ensure that character
	classes don't interfere with RegexOptions.IgnoreCase.

Started looking at some of Florian's patches, which I realized now that
he hadn't applied.

svn path=/trunk/mcs/; revision=59538
2006-04-17 14:05:46 +00:00
Raja R Harinath d96a4c42b2 In System.Text.RegularExpressions:
Fix #78007
	* interpreter.cs (Interpreter.Eval) [Anchor, Position.StartOfString]:
	Don't reset 'ptr' to 0 during forward scan.

In Test/System.Text.RegularExpressions:
	* RegexBugs.cs (Bug78007): New test from #78007.

svn path=/trunk/mcs/; revision=59177
2006-04-07 13:44:55 +00:00
Raja R Harinath 4d94dda2bf In System.Text.RegularExpressions:
Fix #76345
	* interpreter.cs (Interpreter.FastEval) [FastRepeat]: If the first
	tail operation has a 'negate' flag, avoid the "match next char"
	optimization.

In Test/System.Text.RegularExpressions:
	* RegexBugs.cs (Bug76345): New test from #76345.

svn path=/trunk/mcs/; revision=59174
2006-04-07 12:01:44 +00:00