public void TestMatchTermination()
{
//exponetial time
string[] s = new string[] {
"_a_aa_aa_aa@",
"_a_aa_aa__aa@",
"_a_aa_aa___aa@",
"_a_aa_aa____aa@",
//"_a_aa_aa_____aa@",
//"_a_aa_aa______aa@", //takes 1 min!!!
};
var regex = new Regex("^(_?a?_?a?_?)+$", RegexOptions.Compiled);
int t = 0;
for (int i = 0; i < s.Length; i++)
{
t = System.Environment.TickCount;
bool res = regex.IsMatch(s[i]);
t = System.Environment.TickCount - t;
TestContext.WriteLine("{0}, {1}", s[i].Length, t);
Assert.IsFalse(res);
}
Assert.IsTrue(t > 1000);
}