From 33b11429e8f6b379d136a2bbfc1a8e2d29b698a4 Mon Sep 17 00:00:00 2001 From: Brad Robinson Date: Mon, 25 Jul 2011 08:27:30 +1000 Subject: [PATCH] Added support for regex string matching asserts --- PetaTest/PetaTest.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/PetaTest/PetaTest.cs b/PetaTest/PetaTest.cs index b285697..58fc2dc 100644 --- a/PetaTest/PetaTest.cs +++ b/PetaTest/PetaTest.cs @@ -6,6 +6,7 @@ using System.Linq.Expressions; using System.IO; using System.Diagnostics; +using System.Text.RegularExpressions; namespace PetaTest { @@ -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))); @@ -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;