Преглед изворни кода

Added support for regex string matching asserts

Brad Robinson пре 13 година
родитељ
комит
33b11429e8
1 измењених фајлова са 13 додато и 0 уклоњено
  1. 13 0
      PetaTest/PetaTest.cs

+ 13 - 0
PetaTest/PetaTest.cs

@@ -6,6 +6,7 @@ using System.Reflection;
 using System.Linq.Expressions;
 using System.IO;
 using System.Diagnostics;
+using System.Text.RegularExpressions;
 
 namespace PetaTest
 {
@@ -219,6 +220,16 @@ namespace PetaTest
 				() => 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 @@ namespace PetaTest
 				Stats.Elapsed = sw.ElapsedMilliseconds;
 				Stats.Passed++;
 			}
+			
+			
 			catch (Exception x)
 			{
 				Stats.Elapsed = sw.ElapsedMilliseconds;