Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@@ -0,0 +1,77 @@
//
// CaptureCas.cs - CAS unit tests for System.Text.RegularExpressions.Capture
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using System;
using System.Reflection;
using System.Security;
using System.Security.Permissions;
using System.Text.RegularExpressions;
namespace MonoCasTests.System.Text.RegularExpressions {
[TestFixture]
[Category ("CAS")]
public class CaptureCas {
private Capture capture;
[TestFixtureSetUp]
public void FixtureSetUp ()
{
capture = (Capture) Match.Empty.Groups [0];
}
[SetUp]
public void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void Deny_Unrestricted ()
{
Assert.AreEqual (0, capture.Index, "Index");
Assert.AreEqual (0, capture.Length, "Length");
Assert.AreEqual (String.Empty, capture.Value, "Value");
Assert.AreEqual (String.Empty, capture.ToString (), "ToString");
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void LinkDemand_Deny_Unrestricted ()
{
MethodInfo mi = typeof (Group).GetProperty ("Index").GetGetMethod ();
Assert.IsNotNull (mi, "Index");
Assert.AreEqual (0, (int)mi.Invoke (capture, null), "invoke");
}
}
}

View File

@@ -0,0 +1,90 @@
//
// CaptureCollectionCas.cs
// - CAS unit tests for System.Text.RegularExpressions.CaptureCollection
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using System;
using System.Reflection;
using System.Security;
using System.Security.Permissions;
using System.Text.RegularExpressions;
namespace MonoCasTests.System.Text.RegularExpressions {
[TestFixture]
[Category ("CAS")]
public class CaptureCollectionCas {
private CaptureCollection coll;
[TestFixtureSetUp]
public void FixtureSetUp ()
{
coll = Match.Empty.Captures;
}
[SetUp]
public void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void Deny_Unrestricted ()
{
Assert.AreEqual (0, coll.Count, "Count");
Assert.IsTrue (coll.IsReadOnly, "IsReadOnly");
Assert.IsFalse (coll.IsSynchronized, "IsSynchronized");
Assert.IsNotNull (coll.SyncRoot, "SyncRoot");
Assert.IsNotNull (coll.GetEnumerator (), "GetEnumerator");
Capture[] captures = new Capture[0];
coll.CopyTo (captures, 0);
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
[ExpectedException (typeof (ArgumentOutOfRangeException))]
public void Items_Deny_Unrestricted ()
{
Assert.IsNotNull (coll[0], "this[int]");
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void LinkDemand_Deny_Unrestricted ()
{
MethodInfo mi = typeof (CaptureCollection).GetProperty ("Count").GetGetMethod ();
Assert.IsNotNull (mi, "Count");
Assert.AreEqual (0, (int)mi.Invoke (coll, null), "invoke");
}
}
}

View File

@@ -0,0 +1,299 @@
2010-06-21 Rodrigo Kumpera <rkumpera@novell.com>
* RegexBugs.cs: Regression test for #610587.
2010-02-03 Rodrigo Kumpera <rkumpera@novell.com>
* SplitTests.cs: New tests for #566117.
2009-08-20 Raja R Harinath <harinath@hurrynot.org>
* RegexMatchTests.cs: Add some explicit numeric group tests.
2009-08-17 Raja R Harinath <harinath@hurrynot.org>
* RegexMatchTests.cs (RegexTrial0061): New.
2009-08-17 Raja R Harinath <harinath@hurrynot.org>
* RegexTrial.cs (Execute): Prepare to handle dis-contiguous group numbers.
2009-08-10 Raja R Harinath <harinath@hurrynot.org>
* RegexMatchTests.cs (RegexTrial0054..60): New.
2009-08-10 Raja R Harinath <harinath@hurrynot.org>
* RegexMatchTests.cs (RegexTrial0053): New.
2009-02-27 Jonathan Pryor <jpryor@novell.com>
* RegexReplace.cs: Add null argument checks for Regex.Replace().
2009-01-14 Zoltan Varga <vargaz@gmail.com>
* RegexTrial.cs: Run all tests with the CIL Compiler too.
* RegexBugs.cs: Add a test for #466151.
2008-11-13 Gert Driesen <drieseng@users.sourceforge.net>
* RegexBugs.cs: added test for bug #443841.
2008-11-11 Gonzalo Paniagua Javier <gonzalo@novell.com>
* RegexBugs.cs: test from bug 432172.
2008-10-30 Gonzalo Paniagua Javier <gonzalo@novell.com>
* RegexBugs.cs: added test from bug #439947.
2008-10-09 Zoltan Varga <vargaz@gmail.com>
* RegexBugs.cs: Add test for #432172.
2008-09-14 Zoltan Varga <vargaz@gmail.com>
* RegexBugs.cs: Add a test for #426142.
2008-06-05 Roei Erez <roeie@mainsoft.com>
* RegexTest.cs: Add test case where a match that contains
empty group at the end.
2007-11-08 Raja R Harinath <harinath@gmail.com>
* RegexReplace.cs (tests): New test from #324390.
2007-11-07 Raja R Harinath <harinath@gmail.com>
* 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.
* RegexReplace.cs (tests): New test from #317092.
(ReplaceTests): Don't catch an AssertException.
2007-11-01 Gert Driesen <drieseng@users.sourceforge.net>
* 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.
* RegexReplace.cs: Fixed line endings.
2007-10-29 Arina Itkes <arinai@mainsoft.com>
* RegexReplace.cs RegxMatchTests.cs RegexResultTests.cs
New tests for Regex:
- for Result method,
- for patterns with number of groups more than 10
- for patterns with ExpicitCapture options
2007-10-21 Gert Driesen <drieseng@users.sourceforge.net>
* 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.
2007-09-17 Gert Driesen <drieseng@users.sourceforge.net>
* RegexReplace.cs: Fixed compiler warning.
2007-04-18 Raja R Harinath <rharinath@novell.com>
* RegexBugs.cs (bug80554_trials): New tests based on #80554.
2007-04-04 Raja R Harinath <rharinath@novell.com>
* RegexTest.cs (PrimeRegex): New backtracking torture test using
a regex that recognizes composite numbers represented in unary.
2007-01-02 Raja R Harinath <rharinath@novell.com>
* RegexBugs.cs (GroupNumbers): New test based on #79472.
2006-05-08 Raja R Harinath <rharinath@novell.com>
* RegexBugs.cs (Kill65535_1, Kill65535_2, No65535Limit): New tests
based on #78278.
2006-04-17 Florian Gross <flgr@ccan.de>
* RegexBugs.cs (CharClassWithIgnoreCase): Ensure that character
classes don't interfere with RegexOptions.IgnoreCase.
2006-04-07 Raja R Harinath <rharinath@novell.com>
* RegexBugs.cs (Bug78007): New test from #78007.
* RegexBugs.cs (Bug76345): New test from #76345.
* RegexBugs.cs (Bug69269): New test from #69269.
2006-04-06 Raja R Harinath <rharinath@novell.com>
* RegexBugs.cs (Bug77487): New test based on #77487.
* RegexTrial.cs (Execute): Run NUnit assertion here.
* PerlTests.cs: Simplify.
2006-03-30 Raja R Harinath <harinath@gmail.com>
* RegexBugs.cs (HangingHyphens): New tests from #77626, and
related bugs found by inspection.
(HangingHyphens1): New testcase for exceptions in character ranges.
2005-11-21 Sebastien Pouliot <sebastien@ximian.com>
* CaptureCas.cs: New. CAS tests.
* CaptureCollectionCas.cs: New. CAS tests.
* GroupCas.cs: New. CAS tests.
* GroupCollectionCas.cs: New. CAS tests.
* GroupTest.cs: New. Unit tests.
* MatchCas.cs: New. CAS tests.
* MatchCollectionCas.cs: New. CAS tests.
* MatchTest.cs: New. Unit tests.
* RegexCas.cs: New. CAS tests.
* RegexCompilationInfoCas.cs: New. CAS tests.
* RegexCompilationInfoTest.cs: New. Unit tests.
* RegexRunnerCas.cs: New. CAS tests.
* RegexRunnerFactoryCas.cs: New. CAS tests.
* RegexTest.cs: Added test cases for new (2.0) CacheSize property.
2005-07-08 Raja R Harinath <rharinath@novell.com>
* RegexTest.cs (Matches1, Matches2, ..., Matches10): Combine into ...
(Matches): ... this. Convert to use a data-driven approach. Use ...
(trials): ... this. New variable that lists the regexp, input
text and expected results.
(runTrial): New. Run a suite of MatchCollection tests on each trial.
Tests both incremental and non-incremental modes.
2005-06-14 Raja R Harinath <harinath@gmail.com>
* RegexBugs.cs (NameLookupInEmptyMatch): New test from #74753.
2005-05-25 Raja R Harinath <rharinath@novell.com>
* RegexReplace.cs: Add a couple more testcases.
2005-05-24 Raja R Harinath <rharinath@novell.com>
* RegexReplace.cs: Add testcase for $+.
2005-05-20 Raja R Harinath <rharinath@novell.com>
* RegexReplace.cs: New file. Most of the tests were inspired by
#74735.
2005-04-20 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* PerlTest.cs: split.
2005-02-27 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* RegexBugs.cs: tests for bug #69193.
2005-01-10 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* RegexBugs.cs: tests for bug #69065.
2005-01-08 Miguel de Icaza <miguel@ximian.com>
* RegexBugs.cs: Add new test.
2005-01-08 Nick Drochak <ndrochak@ieee.org>
* RegexTest.cs: Make pass on MS.NET
2004-11-29 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* System.Text.RegularExpressions/RegexBugs.cs: test case for bug #57274.
2004-10-18 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* System.Text.RegularExpressions/RegexBugs.cs: added test for bug
#68398.
2004-07-05 Jackson Harper <jackson@ximian.com>
* RegexTest.cs: Add some simple tests for debugging/zen building.
2004-06-06 Jambunathan K <kjambunathan@novell.com>
* RegexTest.cs:
* RegexBugs.cs: Added test case for exercising Regex.Unescape()
Added test cases for exercising \b as a word boundary operator
and as a character class in a regex. Refer bug #58256 for more
information.
2004-06-01 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* RegexBugs.cs: added CategoryAndNegated test.
2004-05-27 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* RegexBugs.cs: added tests from bug #59150.
2004-04-19 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* Test/System.Text.RegularExpressions/PerlTrials.cs:
Patch by Eric Durand Tremblay with tests.
1) Capture inner group when named.
2) Resolved parse error caused by not capturing inner group
3) Resolved incorrect capture group
4) Now, not capturing anything when unnamed ( correct behavior)
2004-04-19 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* PerlTrials.cs: unix line endings.
2004-03-30 Lluis Sanchez Gual <lluis@ximian.com>
* RegexBugs.cs: Added test for bug #52890.
2004-03-24 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* RegexBugs.cs: added new test with a regex used when discovering the
wsdl document for a asmx page.
2004-03-22 Jackson Harper <jackson@ximian.com>
* RegexBugs.cs: Add test case for multiple matches.
2004-03-17 Francois Beauchemin <beauche@softhome.net>
* PerlTrials.cs : Added many test for RightToLeft
* PerlTest.cs, RegexTrial : Modified version of regextrial to
be run all the test and to report exception.
2004-03-16 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* RegexBugs.cs: added test case for bug 54797.
2004-02-02 Nick Drochak <ndrochak@ieee.org>
* RegexBugs.cs (RangeIgnoreCase): made the last assert pass on .NET.
2004-01-16 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* RegexBugs.cs: added test from bug #52924.
2004-01-07 Lluis Sanchez Gual <lluis@ximian.com>
* RegexBugs.cs: Improved test. In Split(), if the last match is at the
end of the string, an empty string must be added to the array of
results.
2003-11-27 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* RegexBugs.cs: added tests from bug #42529.

View File

@@ -0,0 +1,76 @@
//
// GroupCas.cs - CAS unit tests for System.Text.RegularExpressions.Group
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using System;
using System.Reflection;
using System.Security;
using System.Security.Permissions;
using System.Text.RegularExpressions;
namespace MonoCasTests.System.Text.RegularExpressions {
[TestFixture]
[Category ("CAS")]
public class GroupCas {
private Group group;
[TestFixtureSetUp]
public void FixtureSetUp ()
{
group = Match.Empty.Groups [0];
}
[SetUp]
public void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void Deny_Unrestricted ()
{
Group sg = Group.Synchronized (group);
Assert.IsNotNull (sg.Captures, "Captures");
Assert.IsFalse (sg.Success, "Success");
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void LinkDemand_Deny_Unrestricted ()
{
MethodInfo mi = typeof (Group).GetProperty ("Success").GetGetMethod ();
Assert.IsNotNull (mi, "Success");
Assert.IsFalse ((bool) mi.Invoke (group, null), "invoke");
}
}
}

View File

@@ -0,0 +1,83 @@
//
// GroupCollectionCas.cs
// - CAS unit tests for System.Text.RegularExpressions.GroupCollection
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using System;
using System.Reflection;
using System.Security;
using System.Security.Permissions;
using System.Text.RegularExpressions;
namespace MonoCasTests.System.Text.RegularExpressions {
[TestFixture]
[Category ("CAS")]
public class GroupCollectionCas {
private GroupCollection coll;
[TestFixtureSetUp]
public void FixtureSetUp ()
{
coll = Match.Empty.Groups;
}
[SetUp]
public void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void Deny_Unrestricted ()
{
Assert.AreEqual (1, coll.Count, "Count");
Assert.IsTrue (coll.IsReadOnly, "IsReadOnly");
Assert.IsFalse (coll.IsSynchronized, "IsSynchronized");
Assert.IsNotNull (coll.SyncRoot, "SyncRoot");
Assert.IsNotNull (coll[0], "this[int]");
Assert.IsNotNull (coll.GetEnumerator (), "GetEnumerator");
Group[] groups = new Group[1];
coll.CopyTo (groups, 0);
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void LinkDemand_Deny_Unrestricted ()
{
MethodInfo mi = typeof (GroupCollection).GetProperty ("Count").GetGetMethod ();
Assert.IsNotNull (mi, "Count");
Assert.AreEqual (1, (int)mi.Invoke (coll, null), "invoke");
}
}
}

View File

@@ -0,0 +1,62 @@
//
// GroupTest.cs - Unit tests for System.Text.RegularExpressions.Group
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using System;
using System.Text.RegularExpressions;
namespace MonoTests.System.Text.RegularExpressions
{
[TestFixture]
public class GroupTest
{
[Test]
public void Synchronized_Inner_Null ()
{
try {
Group.Synchronized (null);
Assert.Fail ("#1");
} catch (ArgumentNullException ex) {
Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
Assert.IsNull (ex.InnerException, "#3");
Assert.IsNotNull (ex.Message, "#4");
Assert.IsNotNull (ex.ParamName, "#5");
Assert.AreEqual ("inner", ex.ParamName, "#6");
}
}
[Test]
public void Synchronized_Empty ()
{
Group eg = Match.Empty.Groups[0];
Group sg = Match.Synchronized (eg);
Assert.AreSame (eg, sg, "Synchronized");
}
}
}

View File

@@ -0,0 +1,80 @@
//
// MatchCas.cs - CAS unit tests for System.Text.RegularExpressions.Match
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using System;
using System.Reflection;
using System.Security;
using System.Security.Permissions;
using System.Text.RegularExpressions;
namespace MonoCasTests.System.Text.RegularExpressions {
[TestFixture]
[Category ("CAS")]
public class MatchCas {
[SetUp]
public void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void Deny_Unrestricted ()
{
Match m = Match.Empty;
Assert.IsNotNull (m, "Empty");
Assert.IsNotNull (m.Groups, "Groups");
Assert.AreSame (m, m.NextMatch (), "NextMatch");
Match sm = Match.Synchronized (m);
Assert.IsNotNull (sm, "Synchronized");
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
[ExpectedException (typeof (NotSupportedException))]
public void Result_Deny_Unrestricted ()
{
Match.Empty.Result (String.Empty);
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void LinkDemand_Deny_Unrestricted ()
{
MethodInfo mi = typeof (Match).GetProperty ("Empty").GetGetMethod ();
Assert.IsNotNull (mi, "Empty");
Assert.IsNotNull (mi.Invoke (null, null), "invoke");
}
}
}

View File

@@ -0,0 +1,73 @@
//
// MatchCollectionCas.cs
// - CAS unit tests for System.Text.RegularExpressions.MatchCollection
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using System;
using System.Reflection;
using System.Security;
using System.Security.Permissions;
using System.Text.RegularExpressions;
namespace MonoCasTests.System.Text.RegularExpressions {
[TestFixture]
[Category ("CAS")]
public class MatchCollectionCas {
private MatchCollection coll;
[TestFixtureSetUp]
public void FixtureSetUp ()
{
}
[SetUp]
public void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void Deny_Unrestricted ()
{
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void LinkDemand_Deny_Unrestricted ()
{
MethodInfo mi = typeof (Match).GetProperty ("Empty").GetGetMethod ();
Assert.IsNotNull (mi, "Empty");
Assert.IsNotNull (mi.Invoke (null, null), "invoke");
}
}
}

View File

@@ -0,0 +1,108 @@
//
// MatchTest.cs - Unit tests for System.Text.RegularExpressions.Match
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using System;
using System.Text.RegularExpressions;
namespace MonoTests.System.Text.RegularExpressions
{
[TestFixture]
public class MatchTest
{
[Test]
public void Synchronized_Inner_Null ()
{
try {
Match.Synchronized (null);
Assert.Fail ("#1");
} catch (ArgumentNullException ex) {
Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
Assert.IsNull (ex.InnerException, "#3");
Assert.IsNotNull (ex.Message, "#4");
Assert.IsNotNull (ex.ParamName, "#5");
Assert.AreEqual ("inner", ex.ParamName, "#6");
}
}
[Test]
public void Synchronized_Empty ()
{
Match em = Match.Empty;
Match sm = Match.Synchronized (em);
Assert.AreSame (em, sm, "Synchronized");
}
[Test]
public void Result_Replacement_Null ()
{
try {
Match.Empty.Result (null);
Assert.Fail ("#1");
} catch (ArgumentNullException ex) {
Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
Assert.IsNull (ex.InnerException, "#3");
Assert.IsNotNull (ex.Message, "#4");
Assert.IsNotNull (ex.ParamName, "#5");
Assert.AreEqual ("replacement", ex.ParamName, "#6");
}
}
[Test]
public void Result_Replacement_Empty ()
{
Regex email = new Regex ("(?<user>[^@]+)@(?<domain>.+)");
Match m = email.Match ("mono@go-mono.com");
string exp = m.Result (string.Empty);
Assert.AreEqual (string.Empty, exp);
}
[Test]
public void Result_Match_Empty ()
{
try {
Match.Empty.Result ("whatever");
Assert.Fail ("#1");
} catch (NotSupportedException ex) {
// Result cannot be called on failed Match
Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
Assert.IsNull (ex.InnerException, "#3");
Assert.IsNotNull (ex.Message, "#4");
}
}
[Test]
public void Match_Backref ()
{
Assert.IsTrue (Regex.IsMatch ("F2345678910LL1", @"(F)(2)(3)(4)(5)(6)(7)(8)(9)(10)(L)\11"), "ltr");
// FIXME
//Assert.IsTrue (Regex.IsMatch ("F2345678910LL1", @"(F)(2)(3)(4)(5)(6)(7)(8)(9)(10)(L)\11", RegexOptions.RightToLeft), "rtl");
}
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,243 @@
//
// RegexCas.cs - CAS unit tests for System.Text.RegularExpressions.Regex
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if !MOBILE
using NUnit.Framework;
using System;
using System.IO;
using System.Reflection;
using System.Runtime.Serialization.Formatters.Binary;
using System.Security;
using System.Security.Permissions;
using System.Text.RegularExpressions;
namespace MonoCasTests.System.Text.RegularExpressions {
class TestRegex: Regex {
public TestRegex ()
{
// note: test protected default ctor
}
public void TestProtectedStuff ()
{
pattern = String.Empty;
roptions = RegexOptions.None;
try {
InitializeReferences ();
}
catch (NotImplementedException) {
// mono
}
Assert.IsFalse (UseOptionC (), "UseOptionC");
Assert.IsFalse (UseOptionR (), "UseOptionR");
Assert.IsNull (capnames, "capnames");
Assert.IsNull (caps, "caps");
Assert.AreEqual (0, capsize, "capsize");
Assert.IsNull (capslist, "capslist");
Assert.IsNull (factory, "factory");
}
}
[TestFixture]
[Category ("CAS")]
public class RegexCas {
private AssemblyName aname;
[TestFixtureSetUp]
public void FixtureSetUp ()
{
aname = new AssemblyName ();
aname.Name = "Cas.Test.RegularExpressions";
}
[SetUp]
public void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
}
private string Evaluator (Match match)
{
return String.Empty;
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void Static_Deny_Unrestricted ()
{
Assert.AreEqual (String.Empty, Regex.Escape (String.Empty), "Escape");
Assert.AreEqual (String.Empty, Regex.Unescape (String.Empty), "Unescape");
Assert.IsTrue (Regex.IsMatch (String.Empty, String.Empty), "IsMatch");
Assert.IsTrue (Regex.IsMatch (String.Empty, String.Empty, RegexOptions.Singleline), "IsMatch2");
Assert.IsNotNull (Regex.Match (String.Empty, String.Empty), "Match");
Assert.IsNotNull (Regex.Match (String.Empty, String.Empty, RegexOptions.Singleline), "Match2");
Assert.AreEqual (1, Regex.Matches (String.Empty, String.Empty).Count, "Matches");
Assert.AreEqual (1, Regex.Matches (String.Empty, String.Empty, RegexOptions.Singleline).Count, "Matches2");
Assert.AreEqual (String.Empty, Regex.Replace (String.Empty, String.Empty, new MatchEvaluator (Evaluator)), "Replace");
Assert.AreEqual (String.Empty, Regex.Replace (String.Empty, String.Empty, new MatchEvaluator (Evaluator), RegexOptions.Singleline), "Replace2");
Assert.AreEqual (String.Empty, Regex.Replace (String.Empty, String.Empty, String.Empty), "Replace3");
Assert.AreEqual (String.Empty, Regex.Replace (String.Empty, String.Empty, String.Empty, RegexOptions.Singleline), "Replace4");
Assert.AreEqual (2, Regex.Split (String.Empty, String.Empty).Length, "Split");
Assert.AreEqual (2, Regex.Split (String.Empty, String.Empty, RegexOptions.Singleline).Length, "Split2");
#if NET_2_0
Assert.AreEqual (15, Regex.CacheSize, "CacheSize");
Regex.CacheSize = 1;
#endif
}
[Test]
[SecurityPermission (SecurityAction.Deny, ControlEvidence = true)]
[ExpectedException (typeof (SecurityException))]
[Category ("NotWorking")]
public void CompileToAssembly_Deny_ControlEvidence ()
{
RegexCompilationInfo info = new RegexCompilationInfo (String.Empty, RegexOptions.None, "name", String.Empty, false);
Regex.CompileToAssembly (new RegexCompilationInfo[1] { info }, aname, null, null);
}
[Test]
[FileIOPermission (SecurityAction.Deny, Unrestricted = true)]
[ExpectedException (typeof (SecurityException))]
[Category ("NotWorking")]
public void CompileToAssembly_Deny_FileIOPermission ()
{
RegexCompilationInfo info = new RegexCompilationInfo (String.Empty, RegexOptions.None, "name", String.Empty, false);
Regex.CompileToAssembly (new RegexCompilationInfo[1] { info }, aname, null, null);
}
[Test]
[SecurityPermission (SecurityAction.PermitOnly, ControlEvidence = true)]
[FileIOPermission (SecurityAction.PermitOnly, Unrestricted = true)]
[Category ("NotWorking")]
public void CompileToAssembly_PermitOnly_ControlEvidence ()
{
RegexCompilationInfo info = new RegexCompilationInfo (String.Empty, RegexOptions.None, "name", String.Empty, false);
Regex.CompileToAssembly (new RegexCompilationInfo[1] { info }, aname, null, null);
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void Instance_Deny_Unrestricted ()
{
Regex r = new Regex (String.Empty);
Assert.AreEqual (RegexOptions.None, r.Options, "Options");
Assert.IsFalse (r.RightToLeft, "RightToLeft");
Assert.AreEqual (1, r.GetGroupNames ().Length, "GetGroupNames");
Assert.AreEqual (1, r.GetGroupNumbers ().Length, "GetGroupNumbers");
Assert.AreEqual ("0", r.GroupNameFromNumber (0), "GroupNameFromNumber");
Assert.AreEqual (0, r.GroupNumberFromName ("0"), "GroupNumberFromName");
Assert.IsTrue (r.IsMatch (String.Empty), "IsMatch");
Assert.IsTrue (r.IsMatch (String.Empty, 0), "IsMatch2");
Assert.IsNotNull (r.Match (String.Empty), "Match");
Assert.IsNotNull (r.Match (String.Empty, 0), "Match2");
Assert.IsNotNull (r.Match (String.Empty, 0, 0), "Match3");
Assert.AreEqual (1, r.Matches (String.Empty).Count, "Matches");
Assert.AreEqual (1, r.Matches (String.Empty, 0).Count, "Matches2");
Assert.AreEqual (String.Empty, r.Replace (String.Empty, new MatchEvaluator (Evaluator)), "Replace");
Assert.AreEqual (String.Empty, r.Replace (String.Empty, new MatchEvaluator (Evaluator), 0), "Replace2");
Assert.AreEqual (String.Empty, r.Replace (String.Empty, new MatchEvaluator (Evaluator), 0, 0), "Replace3");
Assert.AreEqual (String.Empty, r.Replace (String.Empty, String.Empty), "Replace4");
Assert.AreEqual (String.Empty, r.Replace (String.Empty, String.Empty, 0), "Replace5");
Assert.AreEqual (String.Empty, r.Replace (String.Empty, String.Empty, 0, 0), "Replace6");
Assert.AreEqual (2, r.Split (String.Empty).Length, "Split");
Assert.AreEqual (2, r.Split (String.Empty, 0).Length, "Split2");
Assert.AreEqual (2, r.Split (String.Empty, 0, 0).Length, "Split3");
Assert.AreEqual (String.Empty, r.ToString (), "ToString");
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void Protected_Deny_Unrestricted ()
{
TestRegex r = new TestRegex ();
r.TestProtectedStuff ();
}
[Test]
[SecurityPermission (SecurityAction.Deny, SerializationFormatter = true)]
[ExpectedException (typeof (SecurityException))]
public void Serialization_Deny_SerializationFormatter ()
{
BinaryFormatter bf = new BinaryFormatter ();
MemoryStream ms = new MemoryStream ();
Regex r1 = new Regex (String.Empty, RegexOptions.Singleline);
bf.Serialize (ms, r1);
}
[Test]
[SecurityPermission (SecurityAction.PermitOnly, SerializationFormatter = true)]
public void Serialization_PermitOnly_SerializationFormatter ()
{
BinaryFormatter bf = new BinaryFormatter ();
MemoryStream ms = new MemoryStream ();
Regex r1 = new Regex (String.Empty, RegexOptions.Singleline);
bf.Serialize (ms, r1);
ms.Position = 0;
Regex r2 = (Regex) bf.Deserialize (ms);
Assert.AreEqual (r1.Options, r2.Options, "Options");
Assert.AreEqual (r1.ToString (), r2.ToString (), "ToString");
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void LinkDemand_Deny_Unrestricted ()
{
Type[] types = new Type[1] { typeof (string) };
ConstructorInfo ci = typeof (Regex).GetConstructor (types);
Assert.IsNotNull (ci, ".ctor (string)");
Assert.IsNotNull (ci.Invoke (new object[1] { String.Empty }), "invoke");
}
}
}
#endif

View File

@@ -0,0 +1,76 @@
//
// RegexCompilationInfoCas.cs - CAS unit tests for
// System.Text.RegularExpressions.RegexCompilationInfo
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using System;
using System.Reflection;
using System.Security;
using System.Security.Permissions;
using System.Text.RegularExpressions;
using MonoTests.System.Text.RegularExpressions;
namespace MonoCasTests.System.Text.RegularExpressions {
[TestFixture]
[Category ("CAS")]
public class RegexCompilationInfoCas {
[SetUp]
public void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void ReuseUnitTest_Deny_Unrestricted ()
{
RegexCompilationInfoTest unit = new RegexCompilationInfoTest ();
unit.Constructor ();
unit.Constructor_InvalidRegexOptions ();
unit.Options_Invalid ();
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void LinkDemand_Deny_Unrestricted ()
{
Type[] types = new Type[5] { typeof (string), typeof (RegexOptions),
typeof (string), typeof (string), typeof (bool) };
ConstructorInfo ci = typeof (RegexCompilationInfo).GetConstructor (types);
Assert.IsNotNull (ci, ".ctor");
object[] parameters = new object[5] { String.Empty, RegexOptions.None,
"name", String.Empty, false };
Assert.IsNotNull (ci.Invoke (parameters), "invoke");
}
}
}

View File

@@ -0,0 +1,134 @@
//
// RegexCompilationInfoTest.cs
// - Unit tests for System.Text.RegularExpressions.RegexCompilationInfo
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using System;
using System.Text.RegularExpressions;
namespace MonoTests.System.Text.RegularExpressions {
[TestFixture]
public class RegexCompilationInfoTest {
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void Constructor_NullPattern ()
{
new RegexCompilationInfo (null, RegexOptions.None, "name", "fullnamespace", false);
}
[Test]
public void Constructor_InvalidRegexOptions ()
{
RegexOptions options = (RegexOptions) Int32.MinValue;
RegexCompilationInfo info = new RegexCompilationInfo ("pattern", options, "name", "fullnamespace", true);
Assert.AreEqual ("pattern", info.Pattern, "Pattern");
Assert.AreEqual (options, info.Options, "Options");
Assert.AreEqual ("name", info.Name, "Name");
Assert.AreEqual ("fullnamespace", info.Namespace, "Namespace");
Assert.IsTrue (info.IsPublic, "IsPublic");
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void Constructor_NullName ()
{
new RegexCompilationInfo ("pattern", RegexOptions.None, null, "fullnamespace", false);
}
[Test]
#if NET_2_0
[ExpectedException (typeof (ArgumentException))]
#endif
public void Constructor_EmptyName ()
{
new RegexCompilationInfo ("pattern", RegexOptions.None, String.Empty, "fullnamespace", false);
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void Constructor_NullNamespace ()
{
new RegexCompilationInfo ("pattern", RegexOptions.None, "name", null, false);
}
[Test]
public void Constructor ()
{
RegexCompilationInfo info = new RegexCompilationInfo (String.Empty, RegexOptions.None, "name", String.Empty, false);
Assert.AreEqual (String.Empty, info.Pattern, "Pattern");
Assert.AreEqual (RegexOptions.None, info.Options, "Options");
Assert.AreEqual ("name", info.Name, "Name");
Assert.AreEqual (String.Empty, info.Namespace, "Namespace");
Assert.IsFalse (info.IsPublic, "IsPublic");
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void Pattern_Null ()
{
RegexCompilationInfo info = new RegexCompilationInfo ("pattern", RegexOptions.None, "name", "fullnamespace", true);
info.Pattern = null;
}
[Test]
public void Options_Invalid ()
{
RegexCompilationInfo info = new RegexCompilationInfo ("pattern", RegexOptions.None, "name", "fullnamespace", true);
info.Options = (RegexOptions) Int32.MinValue;
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void Name_Null ()
{
RegexCompilationInfo info = new RegexCompilationInfo ("pattern", RegexOptions.None, "name", "fullnamespace", true);
info.Name = null;
}
[Test]
#if NET_2_0
[ExpectedException (typeof (ArgumentException))]
#endif
public void Name_Empty ()
{
RegexCompilationInfo info = new RegexCompilationInfo ("pattern", RegexOptions.None, "name", "fullnamespace", true);
info.Name = String.Empty;
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void Namespace_Null ()
{
RegexCompilationInfo info = new RegexCompilationInfo ("pattern", RegexOptions.None, "name", "fullnamespace", true);
info.Namespace = null;
}
}
}

View File

@@ -0,0 +1,360 @@
using System;
using System.Text;
using System.Text.RegularExpressions;
using NUnit.Framework;
namespace MonoTests.System.Text.RegularExpressions
{
[TestFixture]
public class RegexMatchTests
{
static RegexTrial [] trials = new RegexTrial [] {
new RegexTrial (@"(a)(b)(c)", RegexOptions.ExplicitCapture, "abc", "Pass. Group[0]=(0,3)"),//0
new RegexTrial (@"(a)(?<1>b)(c)", RegexOptions.ExplicitCapture, "abc", "Pass. Group[0]=(0,3) Group[1]=(1,1)"),//1
new RegexTrial (@"(a)(?<2>b)(c)", RegexOptions.None, "abc", "Pass. Group[0]=(0,3) Group[1]=(0,1) Group[1]=(1,1)(2,1)"),//2
new RegexTrial (@"(a)(?<foo>b)(c)", RegexOptions.ExplicitCapture, "abc", "Pass. Group[0]=(0,3) Group[1]=(1,1)"),//3
new RegexTrial (@"(F)(2)(3)(4)(5)(6)(7)(8)(9)(10)(L)\11", RegexOptions.None, "F2345678910LL", "Pass. Group[0]=(0,13)"//4
+ " Group[1]=(0,1)"
+ " Group[2]=(1,1)"
+ " Group[3]=(2,1)"
+ " Group[4]=(3,1)"
+ " Group[5]=(4,1)"
+ " Group[6]=(5,1)"
+ " Group[7]=(6,1)"
+ " Group[8]=(7,1)"
+ " Group[9]=(8,1)"
+ " Group[10]=(9,2)"
+ " Group[11]=(11,1)"
),
new RegexTrial (@"(F)(2)(3)(4)(5)(6)(7)(8)(9)(10)(L)\11", RegexOptions.ExplicitCapture, "F2345678910LL", "Fail."),//5
new RegexTrial (@"(F)(2)(3)(4)(5)(6)(?<S>7)(8)(9)(10)(L)\1", RegexOptions.None, "F2345678910L71", "Fail."),//6
new RegexTrial (@"(F)(2)(3)(4)(5)(6)(7)(8)(9)(10)(L)\11", RegexOptions.None, "F2345678910LF1", "Fail."),//7
new RegexTrial (@"(F)(2)(3)(4)(5)(6)(?<S>7)(8)(9)(10)(L)\11", RegexOptions.None, "F2345678910L71", "Pass."//8
+ " Group[0]=(0,13)"
+ " Group[1]=(0,1)"
+ " Group[2]=(1,1)"
+ " Group[3]=(2,1)"
+ " Group[4]=(3,1)"
+ " Group[5]=(4,1)"
+ " Group[6]=(5,1)"
+ " Group[7]=(7,1)"
+ " Group[8]=(8,1)"
+ " Group[9]=(9,2)"
+ " Group[10]=(11,1)"
+ " Group[11]=(6,1)"
),
new RegexTrial (@"(F)(2)(3)(?<S>4)(5)(6)(?'S'7)(8)(9)(10)(L)\10", RegexOptions.None, "F2345678910L71", "Pass."//9
+ " Group[0]=(0,13)"
+ " Group[1]=(0,1)"
+ " Group[2]=(1,1)"
+ " Group[3]=(2,1)"
+ " Group[4]=(4,1)"
+ " Group[5]=(5,1)"
+ " Group[6]=(7,1)"
+ " Group[7]=(8,1)"
+ " Group[8]=(9,2)"
+ " Group[9]=(11,1)"
+ " Group[10]=(3,1)(6,1)"
),
new RegexTrial (@"(F)(2)(3)(?<S>4)(5)(6)(?'S'7)(8)(9)(10)(L)\10", RegexOptions.ExplicitCapture, "F2345678910L70", "Fail."),//10
new RegexTrial (@"(F)(2)(3)(?<S>4)(5)(6)(?'S'7)(8)(9)(10)(L)\1", RegexOptions.ExplicitCapture, "F2345678910L70", "Pass. Group[0]=(0,13) Group[1]=(3,1)(6,1)"),//11
new RegexTrial (@"(?n:(F)(2)(3)(?<S>4)(5)(6)(?'S'7)(8)(9)(10)(L)\1)", RegexOptions.None, "F2345678910L70", "Pass. Group[0]=(0,13) Group[1]=(3,1)(6,1)"),//12
new RegexTrial (@"(F)(2)(3)(?<S>4)(5)(6)(?'S'7)(8)(9)(10)(L)(?(10)\10)", RegexOptions.None, "F2345678910L70","Pass."//13
+ " Group[0]=(0,13)"
+ " Group[1]=(0,1)"
+ " Group[2]=(1,1)"
+ " Group[3]=(2,1)"
+ " Group[4]=(4,1)"
+ " Group[5]=(5,1)"
+ " Group[6]=(7,1)"
+ " Group[7]=(8,1)"
+ " Group[8]=(9,2)"
+ " Group[9]=(11,1)"
+ " Group[10]=(3,1)(6,1)"
),
new RegexTrial (@"(F)(2)(3)(?<S>4)(5)(6)(?'S'7)(8)(9)(10)(L)(?(S)|\10)", RegexOptions.None, "F2345678910L70","Pass."//14
+ " Group[0]=(0,12)"
+ " Group[1]=(0,1)"
+ " Group[2]=(1,1)"
+ " Group[3]=(2,1)"
+ " Group[4]=(4,1)"
+ " Group[5]=(5,1)"
+ " Group[6]=(7,1)"
+ " Group[7]=(8,1)"
+ " Group[8]=(9,2)"
+ " Group[9]=(11,1)"
+ " Group[10]=(3,1)(6,1)"
),
new RegexTrial (@"(F)(2)(3)(?<S>4)(5)(6)(?'S'7)(8)(9)(10)(L)(?(7)|\10)", RegexOptions.None, "F2345678910L70","Pass."//15
+ " Group[0]=(0,12)"
+ " Group[1]=(0,1)"
+ " Group[2]=(1,1)"
+ " Group[3]=(2,1)"
+ " Group[4]=(4,1)"
+ " Group[5]=(5,1)"
+ " Group[6]=(7,1)"
+ " Group[7]=(8,1)"
+ " Group[8]=(9,2)"
+ " Group[9]=(11,1)"
+ " Group[10]=(3,1)(6,1)"
),
new RegexTrial (@"(F)(2)(3)(?<S>4)(5)(6)(?'S'7)(8)(9)(10)(L)(?(K)|\10)", RegexOptions.None, "F2345678910L70","Pass."//16
+ " Group[0]=(0,13)"
+ " Group[1]=(0,1)"
+ " Group[2]=(1,1)"
+ " Group[3]=(2,1)"
+ " Group[4]=(4,1)"
+ " Group[5]=(5,1)"
+ " Group[6]=(7,1)"
+ " Group[7]=(8,1)"
+ " Group[8]=(9,2)"
+ " Group[9]=(11,1)"
+ " Group[10]=(3,1)(6,1)"
),
new RegexTrial (@"\P{IsHebrew}", RegexOptions.None, "F<>", "Pass. Group[0]=(0,1)"),//17
new RegexTrial (@"\p{IsHebrew}", RegexOptions.None, "F<>", "Pass. Group[0]=(1,1)"),//18
new RegexTrial (@"(?<=a+)(?:a)*bc", RegexOptions.None, "aabc", "Pass. Group[0]=(1,3)"),//19
new RegexTrial (@"(?<=a*)(?:a)*bc", RegexOptions.None, "aabc", "Pass. Group[0]=(0,4)"),//20
new RegexTrial (@"(?<=a{1,5})(?:a)*bc", RegexOptions.None, "aabc", "Pass. Group[0]=(1,3)"),//21
new RegexTrial (@"(?<=a{1})(?:a)*bc", RegexOptions.None, "aabc", "Pass. Group[0]=(1,3)"),//22
new RegexTrial (@"(?<=a{1,})(?:a)*bc", RegexOptions.None, "aabc", "Pass. Group[0]=(1,3)"),//23
new RegexTrial (@"(?<=a+?)(?:a)*bc", RegexOptions.None, "aabc", "Pass. Group[0]=(1,3)"),//24
new RegexTrial (@"(?<=a*?)(?:a)*bc", RegexOptions.None, "aabc", "Pass. Group[0]=(0,4)"),//25
new RegexTrial (@"(?<=a{1,5}?)(?:a)*bc", RegexOptions.None, "aabc", "Pass. Group[0]=(1,3)"),//26
new RegexTrial (@"(?<=a{1}?)(?:a)*bc", RegexOptions.None, "aabc", "Pass. Group[0]=(1,3)"),//27
new RegexTrial (@"(?<=a{1}?)(?:a)*bc", RegexOptions.None, "aabc", "Pass. Group[0]=(1,3)"),//28
new RegexTrial (@"(?<!a+)(?:a)*bc", RegexOptions.None, "aabc", "Pass. Group[0]=(0,4)"),//29
new RegexTrial (@"(?<!a*)(?:a)*bc", RegexOptions.None, "aabc", "Fail."),//30
new RegexTrial (@"abc*(?=c*)", RegexOptions.None, "abcc", "Pass. Group[0]=(0,4)"),//31
new RegexTrial (@"abc*(?=c+)", RegexOptions.None, "abcc", "Pass. Group[0]=(0,3)"),//32
new RegexTrial (@"abc*(?=c{1})", RegexOptions.None, "abcc", "Pass. Group[0]=(0,3)"),//33
new RegexTrial (@"abc*(?=c{1,5})", RegexOptions.None, "abcc", "Pass. Group[0]=(0,3)"),//34
new RegexTrial (@"abc*(?=c{1,})", RegexOptions.None, "abcc", "Pass. Group[0]=(0,3)"),//35
new RegexTrial (@"abc*(?=c*?)", RegexOptions.None, "abcc", "Pass. Group[0]=(0,4)"),//36
new RegexTrial (@"abc*(?=c+?)", RegexOptions.None, "abcc", "Pass. Group[0]=(0,3)"),//37
new RegexTrial (@"abc*(?=c{1}?)", RegexOptions.None, "abcc", "Pass. Group[0]=(0,3)"),//38
new RegexTrial (@"abc*(?=c{1,5}?)", RegexOptions.None, "abcc", "Pass. Group[0]=(0,3)"),//39
new RegexTrial (@"abc*(?=c{1,}?)", RegexOptions.None, "abcc", "Pass. Group[0]=(0,3)"),//40
new RegexTrial (@"abc*?(?=c*)", RegexOptions.None, "abcc", "Pass. Group[0]=(0,2)"),//41
new RegexTrial (@"abc*?(?=c+)", RegexOptions.None, "abcc", "Pass. Group[0]=(0,2)"),//42
new RegexTrial (@"abc*?(?=c{1})", RegexOptions.None, "abcc", "Pass. Group[0]=(0,2)"),//43
new RegexTrial (@"abc*?(?=c{1,5})", RegexOptions.None, "abcc", "Pass. Group[0]=(0,2)"),//44
new RegexTrial (@"abc*?(?=c{1,})", RegexOptions.None, "abcc", "Pass. Group[0]=(0,2)"),//45
new RegexTrial (@"abc*(?!c*)", RegexOptions.None, "abcc", "Fail."),//46
new RegexTrial (@"abc*(?!c+)", RegexOptions.None, "abcc", "Pass. Group[0]=(0,4)"),//47
new RegexTrial (@"abc*(?!c{1})", RegexOptions.None, "abcc", "Pass. Group[0]=(0,4)"),//48
new RegexTrial (@"abc*(?!c{1,5})", RegexOptions.None, "abcc", "Pass. Group[0]=(0,4)"),//49
new RegexTrial (@"abc*(?!c{1,})", RegexOptions.None, "abcc", "Pass. Group[0]=(0,4)"),//50
new RegexTrial (@"(a)(?<1>b)(?'1'c)", RegexOptions.ExplicitCapture, "abc", "Pass. Group[0]=(0,3) Group[1]=(1,1)(2,1)"),//51
new RegexTrial (@"(?>a*).", RegexOptions.ExplicitCapture, "aaaa", "Fail."),//52
new RegexTrial (@"(?<ab>ab)c\1", RegexOptions.None, "abcabc", "Pass. Group[0]=(0,5) Group[1]=(0,2)"),//53
new RegexTrial (@"\1", RegexOptions.ECMAScript, "-", "Fail."),//54
new RegexTrial (@"\2", RegexOptions.ECMAScript, "-", "Fail."),//55
new RegexTrial (@"(a)|\2", RegexOptions.ECMAScript, "-", "Fail."),//56
new RegexTrial (@"\4400", RegexOptions.None, "asdf 012", "Pass. Group[0]=(4,2)"),//57
new RegexTrial (@"\4400", RegexOptions.ECMAScript, "asdf 012", "Fail."),//58
new RegexTrial (@"\4400", RegexOptions.None, "asdf$0012", "Fail."),//59
new RegexTrial (@"\4400", RegexOptions.ECMAScript, "asdf$0012", "Pass. Group[0]=(4,3)"),//60
new RegexTrial (@"(?<2>ab)(?<c>c)(?<d>d)", RegexOptions.None, "abcd", "Pass. Group[0]=(0,4) Group[1]=(2,1) Group[2]=(0,2) Group[3]=(3,1)"),// 61
new RegexTrial (@"(?<1>ab)(c)", RegexOptions.None, "abc", "Pass. Group[0]=(0,3) Group[1]=(0,2)(2,1)"),//62
new RegexTrial (@"(?<44>a)", RegexOptions.None, "a", "Pass. Group[0]=(0,1) Group[44]=(0,1)"),//63
new RegexTrial (@"(?<44>a)(?<8>b)", RegexOptions.None, "ab", "Pass. Group[0]=(0,2) Group[8]=(1,1) Group[44]=(0,1)"),//64
new RegexTrial (@"(?<44>a)(?<8>b)(?<1>c)(d)", RegexOptions.None, "abcd", "Pass. Group[0]=(0,4) Group[1]=(2,1)(3,1) Group[8]=(1,1) Group[44]=(0,1)"),//65
new RegexTrial (@"(?<44>a)(?<44>b)", RegexOptions.None, "ab", "Pass. Group[0]=(0,2) Group[44]=(0,1)(1,1)"),//66
new RegexTrial (@"(?<44>a)\440", RegexOptions.None, "a ", "Pass. Group[0]=(0,2) Group[44]=(0,1)"),//67
new RegexTrial (@"(?<44>a)\440", RegexOptions.ECMAScript, "a ", "Fail."),//68
new RegexTrial (@"(?<44>a)\440", RegexOptions.None, "aa0", "Fail."),//69
new RegexTrial (@"(?<44>a)\440", RegexOptions.ECMAScript, "aa0", "Pass. Group[0]=(0,3) Group[44]=(0,1)"),//70
};
[Test]
public void RegexJvmTrial0000 ()
{
trials [0].Execute ();
}
[Test]
public void RegexJvmTrial0001 ()
{
trials [1].Execute ();
}
[Test]
[Category ("NotDotNet")]
[Category ("NotWorking")]
public void RegexJvmTrial0002 ()
{
trials [2].Execute ();
}
[Test]
public void RegexJvmTrial0003 ()
{
trials [3].Execute ();
}
[Test]
public void RegexJvmTrial0004 ()
{
trials [4].Execute ();
}
[Test]
[Category ("NotWorking")]
public void RegexJvmTrial0005 ()
{
trials [5].Execute ();
}
[Test]
public void RegexJvmTrial0006 ()
{
trials [6].Execute ();
}
[Test]
public void RegexJvmTrial0007 ()
{
trials [7].Execute ();
}
[Test]
[Category ("NotWorking")]
[Category ("NotDotNet")]
public void RegexJvmTrial0008 ()
{
trials [8].Execute ();
}
[Test]
[Category ("NotWorking")]
[Category ("NotDotNet")]
public void RegexJvmTrial0009 ()
{
trials [9].Execute ();
}
[Test]
[Category ("NotWorking")]
public void RegexJvmTrial0010 ()
{
trials [10].Execute ();
}
[Test]
[Category ("NotWorking")]
public void RegexJvmTrial0011 ()
{
trials [11].Execute ();
}
[Test]
[Category ("NotWorking")]
public void RegexJvmTrial0012 ()
{
trials [12].Execute ();
}
[Test]
[Category ("NotWorking")]
[Category ("NotDotNet")]
public void RegexJvmTrial0013 ()
{
trials [13].Execute ();
}
[Test]
[Category ("NotWorking")]
[Category ("NotDotNet")]
public void RegexJvmTrial0014 ()
{
trials [14].Execute ();
}
[Test]
[Category ("NotWorking")]
[Category ("NotDotNet")]
public void RegexJvmTrial0015 ()
{
trials [15].Execute ();
}
[Test]
[Category ("NotWorking")]
[Category ("NotDotNet")]
public void RegexJvmTrial0016 ()
{
trials [16].Execute ();
}
[Test]
public void RegexJvmTrial0017 ()
{
trials [17].Execute ();
}
[Test]
[Category ("NotWorking")]
[Category ("NotDotNet")]
public void RegexJvmTrial0018 ()
{
trials [18].Execute ();
}
[Test] public void RegexJvmTrial0019 () { trials [19].Execute (); }
[Test] public void RegexJvmTrial0020 () { trials [20].Execute (); }
[Test] public void RegexJvmTrial0021 () { trials [21].Execute (); }
[Test] public void RegexJvmTrial0022 () { trials [22].Execute (); }
[Test] public void RegexJvmTrial0023 () { trials [23].Execute (); }
[Test] public void RegexJvmTrial0024 () { trials [24].Execute (); }
[Test] public void RegexJvmTrial0025 () { trials [25].Execute (); }
[Test] public void RegexJvmTrial0026 () { trials [26].Execute (); }
[Test] public void RegexJvmTrial0027 () { trials [27].Execute (); }
[Test] public void RegexJvmTrial0028 () { trials [28].Execute (); }
[Test] public void RegexJvmTrial0029 () { trials [29].Execute (); }
[Test] public void RegexJvmTrial0030 () { trials [30].Execute (); }
[Test] public void RegexJvmTrial0031 () { trials [31].Execute (); }
[Test] public void RegexJvmTrial0032 () { trials [32].Execute (); }
[Test] public void RegexJvmTrial0033 () { trials [33].Execute (); }
[Test] public void RegexJvmTrial0034 () { trials [34].Execute (); }
[Test] public void RegexJvmTrial0035 () { trials [35].Execute (); }
[Test] public void RegexJvmTrial0036 () { trials [36].Execute (); }
[Test] public void RegexJvmTrial0037 () { trials [37].Execute (); }
[Test] public void RegexJvmTrial0038 () { trials [38].Execute (); }
[Test] public void RegexJvmTrial0039 () { trials [39].Execute (); }
[Test] public void RegexJvmTrial0040 () { trials [40].Execute (); }
[Test] public void RegexJvmTrial0041 () { trials [41].Execute (); }
[Test] public void RegexJvmTrial0042 () { trials [42].Execute (); }
[Test] public void RegexJvmTrial0043 () { trials [43].Execute (); }
[Test] public void RegexJvmTrial0044 () { trials [44].Execute (); }
[Test] public void RegexJvmTrial0045 () { trials [45].Execute (); }
[Test] public void RegexJvmTrial0046 () { trials [46].Execute (); }
[Test] public void RegexJvmTrial0047 () { trials [47].Execute (); }
[Test] public void RegexJvmTrial0048 () { trials [48].Execute (); }
[Test] public void RegexJvmTrial0049 () { trials [49].Execute (); }
[Test] public void RegexJvmTrial0050 () { trials [50].Execute (); }
[Test] public void RegexJvmTrial0051 () { trials [51].Execute (); }
[Test] public void RegexJvmTrial0052 () { trials [52].Execute (); }
[Test] public void RegexTrial0053 () { trials [53].Execute (); }
[Test] public void RegexTrial0054 () { trials [54].Execute (); }
[Test] public void RegexTrial0055 () { trials [55].Execute (); }
[Test] public void RegexTrial0056 () { trials [56].Execute (); }
[Test] public void RegexTrial0057 () { trials [57].Execute (); }
[Test] public void RegexTrial0058 () { trials [58].Execute (); }
[Test] public void RegexTrial0059 () { trials [59].Execute (); }
[Test] public void RegexTrial0060 () { trials [60].Execute (); }
[Test] public void RegexTrial0061 () { trials [61].Execute (); }
[Test] public void RegexTrial0062 () { trials [62].Execute (); }
[Test] public void RegexTrial0063 () { trials [63].Execute (); }
[Test] public void RegexTrial0064 () { trials [64].Execute (); }
[Test] public void RegexTrial0065 () { trials [65].Execute (); }
[Test] public void RegexTrial0066 () { trials [66].Execute (); }
[Test] public void RegexTrial0067 () { trials [67].Execute (); }
[Test] public void RegexTrial0068 () { trials [68].Execute (); }
[Test] public void RegexTrial0069 () { trials [69].Execute (); }
[Test] public void RegexTrial0070 () { trials [70].Execute (); }
}
}

View File

@@ -0,0 +1,147 @@
//
// RegexReplace.cs
//
// Author:
// Raja R Harinath <rharinath@novell.com>
//
// (C) 2005, Novell Inc.
using System;
using System.Text.RegularExpressions;
using NUnit.Framework;
namespace MonoTests.System.Text.RegularExpressions {
[TestFixture]
public class RegexReplaceTest {
[Flags]
enum direction {
LTR = 1,
RTL = 2,
Both = 3
}
struct testcase {
public string original, pattern, replacement, expected;
public direction direction;
public testcase (string o, string p, string r, string e, direction d)
{
original = o;
pattern = p;
replacement = r;
expected = e;
direction = d;
}
public testcase (string o, string p, string r, string e) : this (o, p, r, e, direction.Both) {}
}
static testcase [] tests = {
// original pattern replacement expected
new testcase ("text", "x", "y", "teyt" ),
new testcase ("text", "x", "$", "te$t" ),
new testcase ("text", "x", "$1", "te$1t" ),
new testcase ("text", "x", "${1}", "te${1}t" ),
new testcase ("text", "x", "$5", "te$5t" ),
new testcase ("te(x)t", "x", "$5", "te($5)t" ),
new testcase ("text", "x", "${5", "te${5t" ),
new testcase ("text", "x", "${foo", "te${foot" ),
new testcase ("text", "(x)", "$5", "te$5t" ),
new testcase ("text", "(x)", "$1", "text" ),
new testcase ("text", "e(x)", "$1", "txt" ),
new testcase ("text", "e(x)", "$5", "t$5t" ),
new testcase ("text", "e(x)", "$4", "t$4t" ),
new testcase ("text", "e(x)", "$3", "t$3t" ),
new testcase ("text", "e(x)", "${1}", "txt" ),
new testcase ("text", "e(x)", "${3}", "t${3}t" ),
new testcase ("text", "e(x)", "${1}${3}", "tx${3}t" ),
new testcase ("text", "e(x)", "${1}${name}", "tx${name}t" ),
new testcase ("text", "e(?<foo>x)", "${1}${name}", "tx${name}t" ),
new testcase ("text", "e(?<foo>x)", "${1}${foo}", "txxt" ),
new testcase ("text", "e(?<foo>x)", "${goll}${foo}", "t${goll}xt" ),
new testcase ("text", "e(?<foo>x)", "${goll${foo}", "t${gollxt" ),
new testcase ("text", "e(?<foo>x)", "${goll${foo}}", "t${gollx}t" ),
new testcase ("text", "e(?<foo>x)", "$${foo}}", "t${foo}}t" ),
new testcase ("text", "e(?<foo>x)", "${${foo}}", "t${x}t" ),
new testcase ("text", "e(?<foo>x)", "$${foo}}", "t${foo}}t" ),
new testcase ("text", "e(?<foo>x)", "$${bfoo}}", "t${bfoo}}t" ),
new testcase ("text", "e(?<foo>x)", "$${foo}}", "t${foo}}t" ),
new testcase ("text", "e(?<foo>x)", "$${foo}", "t${foo}t" ),
new testcase ("text", "e(?<foo>x)", "$$", "t$t" ),
new testcase ("text", "(?<foo>e)(?<foo>x)", "${foo}$1$2", "txx$2t", direction.LTR),
new testcase ("text", "(?<foo>e)(?<foo>x)", "${foo}$1$2", "tee$2t", direction.RTL),
new testcase ("text", "(e)(?<foo>x)", "${foo}$1$2", "txext" ),
new testcase ("text", "(?<foo>e)(x)", "${foo}$1$2", "texet" ),
new testcase ("text", "(e)(?<foo>x)", "${foo}$1$2$+", "txexxt" ),
new testcase ("text", "(?<foo>e)(x)", "${foo}$1$2$+", "texeet" ),
new testcase ("314 1592 65358", @"\d\d\d\d|\d\d\d", "a", "a a a8", direction.LTR),
new testcase ("314 1592 65358", @"\d\d\d\d|\d\d\d", "a", "a a 6a", direction.RTL),
new testcase ("2 314 1592 65358", @"\d\d\d\d|\d\d\d", "a", "2 a a a8", direction.LTR),
new testcase ("2 314 1592 65358", @"\d\d\d\d|\d\d\d", "a", "2 a a 6a", direction.RTL),
new testcase ("<i>am not</i>", "<(.+?)>", "[$0:$1]", "[<i>:i]am not[</i>:/i]"),
new testcase ("texts", "(?<foo>e)(x)", "${foo}$1$2$_", "texetextsts" ),
new testcase ("texts", "(?<foo>e)(x)", "${foo}$1$2$`", "texetts" ),
new testcase ("texts", "(?<foo>e)(x)", "${foo}$1$2$'", "texetsts" ),
new testcase ("texts", "(?<foo>e)(x)", "${foo}$1$2$&", "texeexts" ),
//new testcase ("F2345678910L71", @"(F)(2)(3)(4)(5)(6)(?<S>7)(8)(9)(10)(L)\11", "${S}$11$1", "77F1" ),
new testcase ("F2345678910L71", @"(F)(2)(3)(4)(5)(6)(7)(8)(9)(10)(L)\11", "${S}$11$1", "F2345678910L71" ),
new testcase ("F2345678910LL1", @"(F)(2)(3)(4)(5)(6)(7)(8)(9)(10)(L)\11", "${S}$11$1", "${S}LF1", /*FIXME: this should work in RTL direction too */ direction.LTR),
new testcase ("a", "a", @"\\", @"\\"), // bug #317092
new testcase ("a", "^", "x", "xa"), // bug #324390
};
[Test]
public void ReplaceTests ()
{
string result = "";
int i = 0;
foreach (testcase test in tests) {
if ((test.direction & direction.LTR) == direction.LTR) {
try {
result = Regex.Replace (test.original, test.pattern, test.replacement);
} catch (Exception e) {
Assert.Fail ("rr#{0}ltr Exception thrown: " + e.ToString (), i);
}
Assert.AreEqual (test.expected, result, "rr#{0}ltr: {1} ~ s,{2},{3},", i,
test.original, test.pattern, test.replacement);
}
if ((test.direction & direction.RTL) == direction.RTL) {
try {
result = Regex.Replace (test.original, test.pattern, test.replacement, RegexOptions.RightToLeft);
} catch (Exception e) {
Assert.Fail ("rr#{0}rtl Exception thrown: " + e.ToString (), i);
}
Assert.AreEqual (test.expected, result, "rr#{0}rtl: {1} ~ s,{2},{3},", i,
test.original, test.pattern, test.replacement);
}
++i;
}
}
static string substitute (Match m)
{
switch (m.Value.Substring(2, m.Length - 3)) {
case "foo": return "bar";
case "hello": return "world";
default: return "ERROR";
}
}
static string resolve (string val, Regex r)
{
MatchEvaluator ev = new MatchEvaluator (substitute);
while (r.IsMatch (val))
val = r.Replace (val, ev);
return val;
}
[Test] // #321036
public void EvaluatorTests ()
{
string test = "@(foo) @(hello)";
string regex = "\\@\\([^\\)]*?\\)";
Assert.AreEqual ("bar world", resolve (test, new Regex (regex)), "ltr");
Assert.AreEqual ("bar world", resolve (test, new Regex (regex, RegexOptions.RightToLeft)), "rtl");
}
}
}

View File

@@ -0,0 +1,240 @@
using System;
using System.Text;
using System.Text.RegularExpressions;
using NUnit.Framework;
namespace MonoTests.System.Text.RegularExpressions
{
[TestFixture]
public class RegexReplaceTests
{
struct testcase
{
public string original, pattern, replacement, expected;
public testcase (string o, string p, string r, string e) {
original = o;
pattern = p;
replacement = r;
expected = e;
}
public void Execute () {
string result;
try {
result = Regex.Replace (original, pattern, replacement);
}
catch (Exception e) {
result = "Error.";
}
Assert.AreEqual (expected, result, "rr#: {0} ~ s,{1},{2},",
original, pattern, replacement);
}
}
[Test]
public void ReplaceTest_001 () { new testcase (@"(?(w)a|o)", @"\(\?\(\w+\).*\|?.*\)", "r", "r").Execute (); }
[Test]
public void ReplaceTest_002 () { new testcase (@"(?(w)|o)", @"\(\?\(\w+\).*\|?.*\)", "r", "r").Execute (); }
[Test]
public void ReplaceTest_003 () { new testcase (@"(?(w)a)", @"\(\?\(\w+\).*\|?.*\)", "r", "r").Execute (); }
[Test]
public void ReplaceTest_004 () { new testcase (@"(?(w)a|)", @"\(\?\(\w+\).*\|?.*\)", "r", "r").Execute (); }
[Test]
public void ReplaceTest_005 () { new testcase (@"(?(w)?|a|o)", @"\(\?\(\w+\).*\|?.*\)", "r", "r").Execute (); }
[Test]
public void ReplaceTest_006 () { new testcase (@"(?(w)||o)", @"\(\?\(\w+\).*\|?.*\)", "r", "r").Execute (); }
[Test]
public void ReplaceTest_007 () { new testcase (@"(?(w)(a)", @"\(\?\(\w+\).*\|?.*\)", "r", "r").Execute (); }
[Test]
public void ReplaceTest_008 () { new testcase (@"(?(w))\a|)", @"\(\?\(\w+\).*\|?.*\)", "r", "r").Execute (); }
[Test]
public void ReplaceTest_009 () { new testcase (@"(?(2)a|o)", @"\(\?\([^\)]+\).*\|?.*\)", "r", "r").Execute (); }
[Test]
public void ReplaceTest_010 () { new testcase (@"(?(|)a|o)", @"\(\?\([^\)]+\).*\|?.*\)", "r", "r").Execute (); }
[Test]
public void ReplaceTest_011 () { new testcase (@"a\3b", @"(?<=(?:\A|[^\\])(?:[\\]{2}){0,1073741823})\\(\d+)", @"\5", @"a\5b").Execute (); }
[Test]
public void ReplaceTest_012 () { new testcase (@"\3b", @"(?<=(?:\A|[^\\])(?:[\\]{2}){0,1073741823})\\(\d+)", @"\5", @"\5b").Execute (); }
[Test]
public void ReplaceTest_013 () { new testcase (@"\\3b", @"(?<=(?:\A|[^\\])(?:[\\]{2}){0,1073741823})\\(\d+)", @"\5", @"\\3b").Execute (); }
[Test]
public void ReplaceTest_014 () { new testcase (@"\\\3b", @"(?<=(?:\A|[^\\])(?:[\\]{2}){0,1073741823})\\(\d+)", @"\5", @"\\\5b").Execute (); }
[Test]
public void ReplaceTest_015 () { new testcase (@"a\\\\3b", @"(?<=(?:\A|[^\\])(?:[\\]{2}){0,1073741823})\\(\d+)", @"\5", @"a\\\\3b").Execute (); }
[Test]
public void ReplaceTest_016 () { new testcase (@"\\\k<g>", @"(?<=(?:\A|[^\\])(?:[\\]{2}){0,1073741823})\\k<(\w+)>", @"\5", @"\\\5").Execute (); }
[Test]
public void ReplaceTest_017 () { new testcase (@"a\\\k<g>", @"(?<=(?:\A|[^\\])(?:[\\]{2}){0,1073741823})\\k<(\w+)>", @"\5", @"a\\\5").Execute (); }
[Test]
public void ReplaceTest_018 () { new testcase (@"\\\\k'g'", @"(?<=(?:\A|[^\\])(?:[\\]{2}){0,1073741823})\\k'(\w+)'", @"\5", @"\\\\k'g'").Execute (); }
[Test]
public void ReplaceTest_019 () { new testcase (@"a\\\\k'g'", @"(?<=(?:\A|[^\\])(?:[\\]{2}){0,1073741823})\\k'(\w+)'", @"\5", @"a\\\\k'g'").Execute (); }
[Test]
public void ReplaceTest_020 () { new testcase (@"\k'g'", @"(?<=(?:\A|[^\\])(?:[\\]{2}){0,1073741823})\\k'(\w+)'", @"\5", @"\5").Execute (); }
[Test]
public void ReplaceTest_021 () { new testcase (@"(?<n1-n2>)", @"\(\?<[A-Za-z]\w*-[A-Za-z]\w*>.*\)", "r", "r").Execute (); }
[Test]
public void ReplaceTest_022 () { new testcase (@"(?'n1-n2'a)", @"\(\?'[A-Za-z]\w*-[A-Za-z]\w*'.*\)", "r", "r").Execute (); }
[Test]
public void ReplaceTest_023 () { new testcase (@"\p{Isa}", @"(?<=(?:\A|[^\\])(?:[\\]{2}){0,1073741823}\\[pP]\{)Is(?=\w+\})", "In", @"\p{Ina}").Execute (); }
[Test]
public void ReplaceTest_024 () { new testcase (@"\p{Is}", @"(?<=(?:\A|[^\\])(?:[\\]{2}){0,1073741823}\\[pP]\{)Is(?=\w+\})", "In", @"\p{Is}").Execute (); }
[Test]
public void ReplaceTest_025 () { new testcase (@"\p{Isa", @"(?<=(?:\A|[^\\])(?:[\\]{2}){0,1073741823}\\[pP]\{)Is(?=\w+\})", "In", @"\p{Isa").Execute (); }
[Test]
public void ReplaceTest_026 () { new testcase (@"a(?#|)", @"\(\?#[^\)]*\)", "", "a").Execute (); }
[Test]
public void ReplaceTest_027 () { new testcase (@"(?#|)", @"\(\?#[^\)]*\)", "", "").Execute (); }
[Test]
public void ReplaceTest_028 () { new testcase (@"(?#|)", @"\#[^\n\r]*", "", "(?").Execute (); }
[Test]
public void ReplaceTest_029 () { new testcase (@"(?inm-xs:\#)", @"(?<=(?:\A|[^\\])(?:[\\]{2}){0,1073741823}\()\?[imsx]*n[-imsx]*:[^\)]+\)", "r", @"(r").Execute (); }
[Test]
public void ReplaceTest_030 () { new testcase (@"(?ni:())", @"(?<=(?:\A|[^\\])(?:[\\]{2}){0,1073741823}\()\?[imsx]*n[-imsx]*:[^\)]+\)", "r", @"(r)").Execute (); }
[Test]
public void ReplaceTest_031 () { new testcase (@"(?x-i:)", @"(?<=(?:\A|[^\\])(?:[\\]{2}){0,1073741823}\()\?[imsx]*n[-imsx]*:[^\)]+\)", "r", @"(?x-i:)").Execute (); }
[Test]
public void ReplaceTest_032 () { new testcase (@"(?n:))", @"(?<=(?:\A|[^\\])(?:[\\]{2}){0,1073741823}\()\?[imsx]*n[-imsx]*:[^\)]+\)", "r", @"(?n:))").Execute (); }
[Test]
public void ReplaceTest_033 () { new testcase (@"(?<n1>)", @"\(\?<[A-Za-z]\w*>.*\)", "r", "r").Execute (); }
[Test]
public void ReplaceTest_034 () { new testcase (@"(?'n1'y)", @"\(\?'[A-Za-z]\w*'.*\)", "r", "r").Execute (); }
[Test]
public void ReplaceTest_035 () { new testcase (@"(?<45>y)", @"\(\?<\d+>.*\)", "r", "r").Execute (); }
[Test]
public void ReplaceTest_036 () { new testcase (@"(?'7'o)", @"\(\?'\d+'.*\)", "r", "r").Execute (); }
[Test]
public void ReplaceTest_037 () { new testcase (@"\\\(", @"(?<=(?:\A|[^\\])(?:[\\]{2}){0,1073741823})\\\(", "r", @"\\r").Execute (); }
[Test]
public void ReplaceTest_038 () { new testcase (@"a\\\(", @"(?<=(?:\A|[^\\])(?:[\\]{2}){0,1073741823})\\\(", "r", @"a\\r").Execute (); }
[Test]
public void ReplaceTest_039 () { new testcase (@"\\(", @"(?<=(?:\A|[^\\])(?:[\\]{2}){0,1073741823})\\\(", "r", @"\\(").Execute (); }
[Test]
public void ReplaceTest_040 () { new testcase (@"a\\(", @"(?<=(?:\A|[^\\])(?:[\\]{2}){0,1073741823})\\\(", "r", @"a\\(").Execute (); }
[Test]
public void ReplaceTest_041 () { new testcase (@"\(", @"(?<=(?:\A|[^\\])(?:[\\]{2}){0,1073741823})\\\(", "r", @"r").Execute (); }
[Test]
public void ReplaceTest_042 () { new testcase (@"a\(", @"(?<=(?:\A|[^\\])(?:[\\]{2}){0,1073741823})\\\(", "r", @"ar").Execute (); }
[Test]
public void ReplaceTest_043 () { new testcase (@"?:", @"(?:^\?[:imnsx=!>-]|^\?<[!=])", "r", "r").Execute (); }
[Test]
public void ReplaceTest_044 () { new testcase (@"?<!", @"(?:^\?[:imnsx=!>-]|^\?<[!=])", "r", "r").Execute (); }
[Test]
public void ReplaceTest_045 () { new testcase (@"?-", @"(?:^\?[:imnsx=!>-]|^\?<[!=])", "r", "r").Execute (); }
[Test]
public void ReplaceTest_046 () { new testcase (@"\\(?<n>", @"(?<=(?:\A|[^\\])(?:[\\]{2}){0,1073741823}\()\?<[A-Za-z]\w*>", "r", @"\\(r").Execute (); }
[Test]
public void ReplaceTest_047 () { new testcase (@"a\\(?'n'", @"(?<=(?:\A|[^\\])(?:[\\]{2}){0,1073741823}\()\?'[A-Za-z]\w*'", "r", @"a\\(r").Execute (); }
[Test]
public void ReplaceTest_048 () { new testcase (@"\\\\(?<2>", @"(?<=(?:\A|[^\\])(?:[\\]{2}){0,1073741823}\()\?<\d+>", "r", @"\\\\(r").Execute (); }
[Test]
public void ReplaceTest_049 () { new testcase (@"(?'2'", @"(?<=(?:\A|[^\\])(?:[\\]{2}){0,1073741823}\()\?'\d+'", "r", "(r").Execute (); }
[Test]
public void ReplaceTest_050 () { new testcase (@"\\[\b]", @"(?<=(?:\A|[^\\])(?:[\\]{2})*(?:\[|\[[^\[\]]*[^\[\]\\])(?:[\\]{2})*)\\b(?=[^\[\]]*\])", @"\\u0008", @"\\[\\u0008]").Execute (); }
[Test]
public void ReplaceTest_051 () { new testcase (@"\\[a\bb]", @"(?<=(?:\A|[^\\])(?:[\\]{2})*(?:\[|\[[^\[\]]*[^\[\]\\])(?:[\\]{2})*)\\b(?=[^\[\]]*\])", @"\\u0008", @"\\[a\\u0008b]").Execute (); }
[Test]
public void ReplaceTest_052 () { new testcase (@"\[\b]", @"(?<=(?:\A|[^\\])(?:[\\]{2})*(?:\[|\[[^\[\]]*[^\[\]\\])(?:[\\]{2})*)\\b(?=[^\[\]]*\])", @"\\u0008", @"\[\b]").Execute (); }
[Test]
public void ReplaceTest_053 () { new testcase (@"\\[\\b]", @"(?<=(?:\A|[^\\])(?:[\\]{2})*(?:\[|\[[^\[\]]*[^\[\]\\])(?:[\\]{2})*)\\b(?=[^\[\]]*\])", @"\\u0008", @"\\[\\b]").Execute (); }
[Test]
public void ReplaceTest_054 () { new testcase (@"\\[\\\b]", @"(?<=(?:\A|[^\\])(?:[\\]{2})*(?:\[|\[[^\[\]]*[^\[\]\\])(?:[\\]{2})*)\\b(?=[^\[\]]*\])", @"\\u0008", @"\\[\\\\u0008]").Execute (); }
[Test]
public void ReplaceTest_055 () { new testcase (@"[[]", @"(?<=(?:\A|[^\\])(?:[\\]{2})*(?:\[|\[[^\[\]]*[^\[\]\\])(?:[\\]{2})*)\[(?=[^\[\]]*\])", @"\\[", @"[\\[]").Execute (); }
[Test]
public void ReplaceTest_056 () { new testcase (@"\[[]", @"(?<=(?:\A|[^\\])(?:[\\]{2})*(?:\[|\[[^\[\]]*[^\[\]\\])(?:[\\]{2})*)\[(?=[^\[\]]*\])", @"\\[", @"\[[]").Execute (); }
[Test]
public void ReplaceTest_057 () { new testcase (@"\\[\\[]", @"(?<=(?:\A|[^\\])(?:[\\]{2})*(?:\[|\[[^\[\]]*[^\[\]\\])(?:[\\]{2})*)\[(?=[^\[\]]*\])", @"\\[", @"\\[\\\\[]").Execute (); }
[Test]
public void ReplaceTest_058 () { new testcase (@"\\[\\\[]", @"(?<=(?:\A|[^\\])(?:[\\]{2})*(?:\[|\[[^\[\]]*[^\[\]\\])(?:[\\]{2})*)\[(?=[^\[\]]*\])", @"\\[", @"\\[\\\[]").Execute (); }
[Test]
public void ReplaceTest_059 () { new testcase (@"\\{", @"(?<=(?:\A|[^\\])(?:[\\]{2})*)\{(?!\d\d*(,(\d\d*)?)?\})", @"\\{", @"\\\\{").Execute (); }
[Test]
public void ReplaceTest_060 () { new testcase (@"\\{", @"(?<=(?:\A|[^\\])(?:[\\]{2})*)\{(?!\d\d*(,(\d\d*)?)?\})", @"\\{", @"\\\\{").Execute (); }
[Test]
public void ReplaceTest_061 () { new testcase (@"\\{1,2}", @"(?<=(?:\A|[^\\])(?:[\\]{2})*)\{(?!\d\d*(,(\d\d*)?)?\})", @"\\{", @"\\{1,2}").Execute (); }
[Test]
public void ReplaceTest_062 () { new testcase (@"\\{1}", @"(?<=(?:\A|[^\\])(?:[\\]{2})*)\{(?!\d\d*(,(\d\d*)?)?\})", @"\\{", @"\\{1}").Execute (); }
[Test]
public void ReplaceTest_063 () { new testcase (@"\\{1,}", @"(?<=(?:\A|[^\\])(?:[\\]{2})*)\{(?!\d\d*(,(\d\d*)?)?\})", @"\\{", @"\\{1,}").Execute (); }
[Test]
public void ReplaceTest_064 () { new testcase (@"\{1", @"(?<=(?:\A|[^\\])(?:[\\]{2})*)\{(?!\d\d*(,(\d\d*)?)?\})", @"\\{", @"\{1").Execute (); }
[Test]
public void ReplaceTest_065 () { new testcase (@"\\}", @"(?<!(\A|[^\\])(\\{2})*\{\d\d*(,(\d\d*)?)?)\}", @"\\}", @"\\\\}").Execute (); }
[Test]
public void ReplaceTest_066 () { new testcase (@"{\\}", @"(?<!(\A|[^\\])(\\{2})*\{\d\d*(,(\d\d*)?)?)\}", @"\\}", @"{\\\\}").Execute (); }
[Test]
public void ReplaceTest_067 () { new testcase (@"{1,2}", @"(?<!(\A|[^\\])(\\{2})*\{\d\d*(,(\d\d*)?)?)\}", @"\\}", @"{1,2}").Execute (); }
[Test]
public void ReplaceTest_068 () { new testcase (@"\\{1}", @"(?<!(\A|[^\\])(\\{2})*\{\d\d*(,(\d\d*)?)?)\}", @"\\}", @"\\{1}").Execute (); }
[Test]
public void ReplaceTest_069 () { new testcase (@"\\{1\}", @"(?<!(\A|[^\\])(\\{2})*\{\d\d*(,(\d\d*)?)?)\}", @"\\}", @"\\{1\\\}").Execute (); }
[Test]
public void ReplaceTest_070 () { new testcase (@"\{1}", @"(?<!(\A|[^\\])(\\{2})*\{\d\d*(,(\d\d*)?)?)\}", @"\\}", @"\{1\\}").Execute (); }
[Test]
public void ReplaceTest_071 () { new testcase (@"{1,}", @"(?<!(\A|[^\\])(\\{2})*\{\d\d*(,(\d\d*)?)?)\}", @"\\}", @"{1,}").Execute (); }
[Test]
public void ReplaceTest_072 () { new testcase (@"\0", @"(?<=(?:\A|[^\\])(?:[\\]{2})*)\\0(?!\d)", @"\\u0000", @"\\u0000").Execute (); }
[Test]
public void ReplaceTest_073 () { new testcase (@"\03", @"(?<=(?:\A|[^\\])(?:[\\]{2})*)\\0(?!\d)", @"\\u0000", @"\03").Execute (); }
[Test]
public void ReplaceTest_074 () { new testcase (@"\\0", @"(?<=(?:\A|[^\\])(?:[\\]{2})*)\\0(?!\d)", @"\\u0000", @"\\0").Execute (); }
[Test]
public void ReplaceTest_075 () { new testcase (@"\\\0a", @"(?<=(?:\A|[^\\])(?:[\\]{2})*)\\0(?!\d)", @"\\u0000", @"\\\\u0000a").Execute (); }
[Test]
public void ReplaceTest_076 () { new testcase (@"a(?<=b*c)", @"\(\?\<[=!][^\)]*(?:[\*\+]|\{\d+,\}).*\)", @"r", @"ar").Execute (); }
[Test]
public void ReplaceTest_077 () { new testcase (@"a(?<=b*c)", @"\(\?\<[=!][^\)]*(?:[\*\+]|\{\d+,\}).*\)", @"r", @"ar").Execute (); }
[Test]
public void ReplaceTest_078 () { new testcase (@"a(?<=b*c)", @"\(\?\<[=!][^\)]*(?:[\*\+]|\{\d+,\}).*\)", @"r", @"ar").Execute (); }
[Test]
public void ReplaceTest_079 () { new testcase (@"a(?<=b+c)", @"\(\?\<[=!][^\)]*(?:[\*\+]|\{\d+,\}).*\)", @"r", @"ar").Execute (); }
[Test]
public void ReplaceTest_080 () { new testcase (@"a(?<!b+c)", @"\(\?\<[=!][^\)]*(?:[\*\+]|\{\d+,\}).*\)", @"r", @"ar").Execute (); }
[Test]
public void ReplaceTest_081 () { new testcase (@"a(?<!b*c)", @"\(\?\<[=!][^\)]*(?:[\*\+]|\{\d+,\}).*\)", @"r", @"ar").Execute (); }
[Test]
public void ReplaceTest_082 () { new testcase (@"(?<!b{1}c))", @"\(\?\<[=!][^\)]*(?:[\*\+]|\{\d+,\}).*\)", @"r", @"(?<!b{1}c))").Execute (); }
[Test]
public void ReplaceTest_083 () { new testcase (@"(?<!b{1,}c)", @"\(\?\<[=!][^\)]*(?:[\*\+]|\{\d+,\}).*\)", @"r", @"r").Execute (); }
[Test]
public void ReplaceTest_084 () { new testcase (@"(?<!b{1,4}c)", @"\(\?\<[=!][^\)]*(?:[\*\+]|\{\d+,\}).*\)", @"r", @"(?<!b{1,4}c)").Execute (); }
[Test]
public void ReplaceTest_085 () { new testcase (@"\p{Isa}", @"(?<=\\[pP]\{)Is(?=\w+\})", "In", @"\p{Ina}").Execute (); }
[Test]
public void ReplaceTest_086 () { new testcase (@"\p{Is}", @"(?<=\\[pP]\{)Is(?=\w+\})", "In", @"\p{Is}").Execute (); }
[Test]
public void ReplaceTest_087 () { new testcase (@"\p{Isa", @"(?<=\\[pP]\{)Is(?=\w+\})", "In", @"\p{Isa").Execute (); }
[Test]
public void ReplaceTest_088 () { new testcase (@"a\3b", @"\\(\d+)", @"\5", @"a\5b").Execute (); }
[Test]
public void ReplaceTest_089 () { new testcase (@"\3b", @"\\(\d+)", @"\5", @"\5b").Execute (); }
[Test]
public void ReplaceTest_090 () { new testcase (@"\\3b", @"(?<=\\)\\(\d)", @"\5", @"\\5b").Execute (); }
[Test]
public void ReplaceTest_091 () { new testcase (@"\\\3b", @"(?<=\\\\)\\(\d)", @"\5", @"\\\5b").Execute (); }
[Test]
public void ReplaceTest_092 () { new testcase (@"a\\\\3b", @"(?<=(\\){0,5})\\(\d)", @"\5", @"a\\\\5b").Execute (); }
[Test]
public void ReplaceTest_093 () { new testcase (@"\\\k<g>", @"(?<=(?:\A|[^\\])(?:[\\]{2}){0,1073741823})\\k<(\w)>", @"\5", @"\\\5").Execute (); }
[Test]
public void ReplaceTest_094 () { new testcase (@"a\\\k<g>", @"(?<=(?:\A|[^\\])(?:[\\]{2}){0,1073741823})\\k<(\w)>", @"\5", @"a\\\5").Execute (); }
[Test]
public void ReplaceTest_095 () { new testcase (@"\\\\k'g'", @"(?<=(?:\A|[^\\])(?:[\\]{2}){0,1073741823})\\k'(\w)'", @"\5", @"\\\\k'g'").Execute (); }
[Test]
public void ReplaceTest_096 () { new testcase (@"a\\\\k'g'", @"(?<=(?:\A|[^\\])(?:[\\]{2}){0,1073741823})\\k'(\w)'", @"\5", @"a\\\\k'g'").Execute (); }
[Test]
public void ReplaceTest_097 () { new testcase (@"\k'g'", @"(?<=(?:\A|[^\\])(?:[\\]{2}){0,1073741823})\\k'(\w)'", @"\5", @"\5").Execute (); }
[Test]
public void ReplaceTest_098 () { new testcase (@"\\(?<={1}", @"(\A|((\A|[^\\])([\\]{2})*\((\?([:>=!]|<([=!]|(\w+>))))?))\{\d+(,(\d+)?)?\}", @"\5", @"\5").Execute (); }
[Test]
public void ReplaceTest_099 () { new testcase (@"{1}", @"(\A|((\A|[^\\])([\\]{2})*\((\?([:>=!]|<([=!]|(\w+>))))?))\{\d+(,(\d+)?)?\}", @"r", @"r").Execute (); }
[Test]
public void ReplaceTest_100 () { new testcase (@"({1}", @"(\A|((\A|[^\\])([\\]{2})*\((\?([:>=!]|<([=!]|(\w+>))))?))\{\d+(,(\d+)?)?\}", @"r", @"r").Execute (); }
[Test]
public void ReplaceTest_101 () { new testcase (@"(?{1}", @"(\A|((\A|[^\\])([\\]{2})*\((\?([:>=!]|<([=!]|(\w+>))))?))\{\d+(,(\d+)?)?\}", @"r", @"(?{1}").Execute (); }
[Test]
public void ReplaceTest_102 () { new testcase (@"(?:{1}", @"(\A|((\A|[^\\])([\\]{2})*\((\?([:>=!]|<([=!]|(\w+>))))?))\{\d+(,(\d+)?)?\}", @"r", @"r").Execute (); }
[Test]
public void ReplaceTest_103 () { new testcase (@"\({1}", @"(\A|((\A|[^\\])([\\]{2})*\((\?([:>=!]|<([=!]|(\w+>))))?))\{\d+(,(\d+)?)?\}", @"r", @"\({1}").Execute (); }
}
}

View File

@@ -0,0 +1,179 @@
using System;
using System.Text;
using System.Text.RegularExpressions;
using NUnit.Framework;
namespace MonoTests.System.Text.RegularExpressions
{
[TestFixture]
public class RegexResultTests
{
struct testcase
{
public string original, pattern, replacement, expected;
public testcase (string o, string p, string r, string e) {
original = o;
pattern = p;
replacement = r;
expected = e;
}
public void Execute () {
string result;
try {
Match match = Regex.Match (original, pattern);
result = match.Result (replacement);
}
catch (Exception e) {
result = "Error.";
}
Assert.AreEqual (expected, result, "rr#: {0} ~ s,{1},{2},",
original, pattern, replacement);
}
}
static testcase [] tests = {
// original pattern replacement expected
new testcase ("F2345678910L71", @"(F)(2)(3)(4)(5)(6)(7)(8)(9)(10)(L)\11", "${S}$11$1", "Error." ),//0
new testcase ("F2345678910LL1", @"(F)(2)(3)(4)(5)(6)(7)(8)(9)(10)(L)\11", "${S}$11$1", "${S}LF" ),//1
new testcase ("texts", "(?<foo>e)(x)", "${foo}$1$2$&", "exeex" ),//2
new testcase ("texts", "(?<foo>e)(x)", "${foo}$1$2$_", "exetexts" ),//3
new testcase ("texts", "(?<foo>e)(x)", "${foo}$1$2$`", "exet" ),//4
new testcase ("texts", "(?<foo>e)(x)", "${foo}$1$2$'", "exets" ),//5
new testcase ("text", "x", "y", "y" ),//6
new testcase ("text", "x", "$", "$" ),//7
new testcase ("text", "x", "$1", "$1" ),//8
new testcase ("text", "x", "${1}", "${1}" ),//9
new testcase ("text", "x", "$5", "$5" ),//10
new testcase ("te(x)t", "x", "$5", "$5" ),//11
new testcase ("text", "x", "${5", "${5" ),//12
new testcase ("text", "x", "${foo", "${foo" ),//13
new testcase ("text", "(x)", "$5", "$5" ),//14
new testcase ("text", "(x)", "$1", "x" ),//15
new testcase ("text", "e(x)", "$1", "x" ),//16
new testcase ("text", "e(x)", "$5", "$5" ),//17
new testcase ("text", "e(x)", "$4", "$4" ),//18
new testcase ("text", "e(x)", "$3", "$3" ),//19
new testcase ("text", "e(x)", "${1}", "x" ),//20
new testcase ("text", "e(x)", "${3}", "${3}" ),//21
new testcase ("text", "e(x)", "${1}${3}", "x${3}" ),//22
new testcase ("text", "e(x)", "${1}${name}", "x${name}" ),//23
new testcase ("text", "e(?<foo>x)", "${1}${name}", "x${name}" ),//24
new testcase ("text", "e(?<foo>x)", "${1}${foo}", "xx" ),//25
new testcase ("text", "e(?<foo>x)", "${goll}${foo}", "${goll}x" ),//26
new testcase ("text", "e(?<foo>x)", "${goll${foo}", "${gollx" ),//27
new testcase ("text", "e(?<foo>x)", "${goll${foo}}", "${gollx}" ),//28
new testcase ("text", "e(?<foo>x)", "$${foo}}", "${foo}}" ),//29
new testcase ("text", "e(?<foo>x)", "${${foo}}", "${x}" ),//30
new testcase ("text", "e(?<foo>x)", "$${foo}}", "${foo}}" ),//31
new testcase ("text", "e(?<foo>x)", "$${bfoo}}", "${bfoo}}" ),//32
new testcase ("text", "e(?<foo>x)", "$${foo}}", "${foo}}" ),//33
new testcase ("text", "e(?<foo>x)", "$${foo}", "${foo}" ),//34
new testcase ("text", "e(?<foo>x)", "$$", "$" ),//35
new testcase ("text", "(?<foo>e)(?<foo>x)", "${foo}$1$2", "xx$2" ),//36
new testcase ("text", "(e)(?<foo>x)", "${foo}$1$2", "xex" ),//37
new testcase ("text", "(?<foo>e)(x)", "${foo}$1$2", "exe" ),//38
new testcase ("text", "(e)(?<foo>x)", "${foo}$1$2$+", "xexx" ),//39
new testcase ("text", "(?<foo>e)(x)", "${foo}$1$2$+", "exee" ),//40
new testcase ("314 1592 65358", @"\d\d\d\d|\d\d\d", "a", "a" ),//41
new testcase ("2 314 1592 65358", @"\d\d\d\d|\d\d\d", "a", "a" ),//42
new testcase ("<i>am not</i>", "<(.+?)>", "[$0:$1]", "[<i>:i]"),//43
new testcase ("F2345678910L71", @"(F)(2)(3)(4)(5)(6)(?<S>7)(8)(9)(10)(L)\11", "${S}$11$1", "77F" ),//44
new testcase ("a", "a", @"\\", @"\\"), // bug #317092 //45
};
[Test]
public void ResultTest_000 () { tests [0].Execute (); }
[Test]
public void ResultTest_001 () { tests [1].Execute (); }
[Test]
public void ResultTest_002 () { tests [2].Execute (); }
[Test]
public void ResultTest_003 () { tests [3].Execute (); }
[Test]
public void ResultTest_004 () { tests [4].Execute (); }
[Test]
public void ResultTest_005 () { tests [5].Execute (); }
[Test]
public void ResultTest_006 () { tests [6].Execute (); }
[Test]
public void ResultTest_007 () { tests [7].Execute (); }
[Test]
public void ResultTest_008 () { tests [8].Execute (); }
[Test]
public void ResultTest_009 () { tests [9].Execute (); }
[Test]
public void ResultTest_010 () { tests [10].Execute (); }
[Test]
public void ResultTest_011 () { tests [11].Execute (); }
[Test]
public void ResultTest_012 () { tests [12].Execute (); }
[Test]
public void ResultTest_013 () { tests [13].Execute (); }
[Test]
public void ResultTest_014 () { tests [14].Execute (); }
[Test]
public void ResultTest_015 () { tests [15].Execute (); }
[Test]
public void ResultTest_016 () { tests [16].Execute (); }
[Test]
public void ResultTest_017 () { tests [17].Execute (); }
[Test]
public void ResultTest_018 () { tests [18].Execute (); }
[Test]
public void ResultTest_019 () { tests [19].Execute (); }
[Test]
public void ResultTest_020 () { tests [20].Execute (); }
[Test]
public void ResultTest_021 () { tests [21].Execute (); }
[Test]
public void ResultTest_022 () { tests [22].Execute (); }
[Test]
public void ResultTest_023 () { tests [23].Execute (); }
[Test]
public void ResultTest_024 () { tests [24].Execute (); }
[Test]
public void ResultTest_025 () { tests [25].Execute (); }
[Test]
public void ResultTest_026 () { tests [26].Execute (); }
[Test]
public void ResultTest_027 () { tests [27].Execute (); }
[Test]
public void ResultTest_028 () { tests [28].Execute (); }
[Test]
public void ResultTest_029 () { tests [29].Execute (); }
[Test]
public void ResultTest_030 () { tests [30].Execute (); }
[Test]
public void ResultTest_031 () { tests [31].Execute (); }
[Test]
public void ResultTest_032 () { tests [32].Execute (); }
[Test]
public void ResultTest_033 () { tests [33].Execute (); }
[Test]
public void ResultTest_034 () { tests [34].Execute (); }
[Test]
public void ResultTest_035 () { tests [35].Execute (); }
[Test]
public void ResultTest_036 () { tests [36].Execute (); }
[Test]
public void ResultTest_037 () { tests [37].Execute (); }
[Test]
public void ResultTest_038 () { tests [38].Execute (); }
[Test]
public void ResultTest_039 () { tests [39].Execute (); }
[Test]
public void ResultTest_040 () { tests [40].Execute (); }
[Test]
public void ResultTest_041 () { tests [41].Execute (); }
[Test]
public void ResultTest_042 () { tests [42].Execute (); }
[Test]
public void ResultTest_043 () { tests [43].Execute (); }
[Test]
[Category("NotWorking")]
public void ResultTest_044 () { tests [44].Execute (); }
[Test]
public void ResultTest_045 () { tests [45].Execute (); }
}
}

View File

@@ -0,0 +1,154 @@
//
// RegexRunnerCas.cs
// - CAS unit tests for System.Text.RegularExpressions.RegexRunner
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if !MOBILE
using NUnit.Framework;
using System;
using System.Reflection;
using System.Security;
using System.Security.Permissions;
using System.Text.RegularExpressions;
namespace MonoCasTests.System.Text.RegularExpressions {
class TestRegexRunner : RegexRunner {
public TestRegexRunner ()
{
}
protected override bool FindFirstChar ()
{
return false;
}
protected override void Go ()
{
}
protected override void InitTrackCount ()
{
}
// easier to test from inside
public void Test ()
{
// abstract (and protected) stuff
Assert.IsFalse (this.FindFirstChar (), "FindFirstChar");
Go ();
InitTrackCount ();
// protected stuff
Assert.IsNull (runcrawl, "runcrawl");
runcrawl = new int[3] { 0, 0, 0 };
Assert.AreEqual (0, runcrawlpos, "runcrawlpos");
runcrawlpos = 1;
Assert.IsNull (runmatch, "runmatch");
runmatch = Match.Empty;
Assert.IsNull (runregex, "runregex");
runregex = new Regex (String.Empty);
Assert.IsNull (runstack, "runstack");
runstack = new int[3] { 0, 0, 0 };
Assert.AreEqual (0, runstackpos, "runstackpos");
runstackpos = 1;
Assert.IsNull (runtext, "runtext");
runtext = "mono";
Assert.AreEqual (0, runtextbeg, "runtextbeg");
runtextbeg = 1;
Assert.AreEqual (0, runtextend, "runtextend");
runtextend = 1;
Assert.AreEqual (0, runtextpos, "runtextpos");
runtextpos = 1;
Assert.AreEqual (0, runtextstart, "runtextstart");
runtextstart = 1;
Assert.IsNull (runtrack, "runtrack");
runtrack = new int[3] { 0, 0, 0 };
Assert.AreEqual (0, runtrackcount, "runtrackcount");
runtrackcount = 1;
Assert.AreEqual (0, runtrackpos, "runtrackpos");
runtrackpos = 1;
Capture (0, 0, 0);
Assert.IsTrue (CharInSet ('a', "a", ""), "CharInSet");
Crawl (1);
Assert.AreEqual (4, Crawlpos (), "Crawlpos");
DoubleCrawl ();
DoubleStack ();
DoubleTrack ();
EnsureStorage ();
Assert.IsFalse (IsBoundary (0, 0, 0), "IsBoundary");
Assert.IsFalse (IsECMABoundary (0, 0, 0), "IsECMABoundary");
Assert.IsTrue (IsMatched (0), "IsMatched");
Assert.AreEqual (0, MatchIndex (0), "MatchIndex");
Assert.AreEqual (0, MatchLength (0), "MatchLength");
Assert.AreEqual (1, Popcrawl (), "Popcrawl");
TransferCapture (0, 0, 0, 0);
Uncapture ();
Assert.IsNotNull (Scan (new Regex (String.Empty), "mono", 0, 0, 0, 0, true), "Scan");
#if NET_2_0
Assert.IsTrue (CharInSet ('a', "a", String.Empty), "CharInSet");
#endif
}
}
[TestFixture]
[Category ("CAS")]
public class RegexRunnerCas {
[SetUp]
public void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
[Category ("NotWorking")]
public void Deny_Unrestricted ()
{
TestRegexRunner runner = new TestRegexRunner ();
runner.Test ();
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void LinkDemand_Deny_Unrestricted ()
{
ConstructorInfo ci = typeof (TestRegexRunner).GetConstructor (new Type[0]);
Assert.IsNotNull (ci, "default .ctor");
Assert.IsNotNull (ci.Invoke (null), "invoke");
}
}
}
#endif

Some files were not shown because too many files have changed in this diff Show More