Skip to content

Commit

Permalink
Added support for regex string matching asserts
Browse files Browse the repository at this point in the history
  • Loading branch information
Brad Robinson committed Jul 24, 2011
1 parent c6ffb06 commit 33b1142
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions PetaTest/PetaTest.cs
Expand Up @@ -6,6 +6,7 @@
using System.Linq.Expressions;
using System.IO;
using System.Diagnostics;
using System.Text.RegularExpressions;

namespace PetaTest
{
Expand Down Expand Up @@ -219,6 +220,16 @@ public static void DoesNotContain(string str, string contains, bool ignoreCase =
() => string.Format("String does contain substring\n didn't expect: {0}\n found: {1}", Utils.FormatValue(contains), Utils.FormatValue(str)));
}

public static void Matches(string str, string regex, RegexOptions options = RegexOptions.None)
{
Throw(new Regex(regex, options).IsMatch(str), () => string.Format("String doesn't match expression\n regex: \"{0}\"\n found: {1}", regex, Utils.FormatValue(str)));
}

public static void DoesNotMatch(string str, string regex, RegexOptions options = RegexOptions.None)
{
Throw(!(new Regex(regex, options).IsMatch(str)), () => string.Format("String matches expression\n regex: \"{0}\"\n found: {1}", regex, Utils.FormatValue(str)));
}

public static void IsNull(object val)
{
Throw(val == null, () => string.Format("Object reference is not null - {0}", Utils.FormatValue(val)));
Expand Down Expand Up @@ -703,6 +714,8 @@ public void RunTest(MethodInfo Target, object instance, object[] Params)
Stats.Elapsed = sw.ElapsedMilliseconds;
Stats.Passed++;
}


catch (Exception x)
{
Stats.Elapsed = sw.ElapsedMilliseconds;
Expand Down

0 comments on commit 33b1142

Please sign in to comment.