Skip to content

Instantly share code, notes, and snippets.

@tarwn
Created March 5, 2022 15:14
Show Gist options
  • Save tarwn/ac048238c1f8f5609164c81dfd1137cc to your computer and use it in GitHub Desktop.
Save tarwn/ac048238c1f8f5609164c81dfd1137cc to your computer and use it in GitHub Desktop.
using NUnit.Framework;
using System.Text.RegularExpressions;
namespace blah
{
[TestFixture]
public class RegexTests
{
[TestCase("111111", true, Description = "Exact match")]
[TestCase("a11111", false, Description = "Letter present")]
[TestCase("99999a", false, Description = "Letter present at end")]
[TestCase(".11111", false, Description = "Symbol present")]
[TestCase("⁹11111", false, Description = "Extended character present")]
[TestCase("⁹111111", false, Description = "Extra extended character present at start")]
[TestCase("111111⁹", false, Description = "Extra extended character present at end")]
[TestCase("22222", false, Description = "Too short")]
[TestCase("333333\n", false, Description = "line feed at end")]
[TestCase("333333\r", false, Description = "cr at end")]
[TestCase("333333\n\n", false, Description = "double line feed at end")]
[TestCase("333333\r\n", false, Description = "crln at end")]
[TestCase("\n222222", false, Description = "line feed at start")]
[TestCase("222\n222", false, Description = "line feed in middle")]
[TestCase(" 444444", false, Description = "space at start")]
[TestCase("444444 ", false, Description = "space at end")]
[TestCase("111111-222222", false, Description = "longer string")]
[TestCase("111111 and 222222 and 333333", false, Description = "also longer string")]
[TestCase("1E02", false)]
[TestCase("NaN", false)]
[TestCase("Infinity", false)]
[TestCase("111,111", false)]
[TestCase("€111111", false)]
[TestCase("€11111", false)]
[TestCase("(╯°□°)╯︵ ┻━┻)", false)]
[TestCase("111111", false)]
[TestCase("₁₁₁₁₁₁", false)]
[TestCase("1️⃣1️⃣1️⃣1️⃣1️⃣1️⃣", false)]
[TestCase("1️⃣111111", false)]
[TestCase("111111️⃣", false)]
[TestCase("111111🌈", false)]
[TestCase("🌈111111", false)]
[TestCase("1🌈11111", false)]
[TestCase("Ⅳ11111", false)]
[TestCase("Ⅳ111111", false)]
public void Basic(string testString, bool expectMatch)
{
var regex = new Regex("^\\d{6}(?!\\n)$");
var isMatch = regex.IsMatch(testString);
Assert.AreEqual(expectMatch, isMatch);
}
}
}
@tarwn
Copy link
Author

tarwn commented Mar 5, 2022

Some more, just because:

        [TestCase($"111111{"\x7"}", false, Description = "bell at end")]
        [TestCase($"{"\x7"}111111", false, Description = "bell at beginning")]
        [TestCase($"111111{"\x3"}1", false, Description = "false report of end of string via text end ascii")]
        [TestCase($"111111{"\x8"}", false, Description = "backspace ascii at end of string")]
        [TestCase($"111111{"\x8"}1", false, Description = "backspace ascii of extra character")]
        [TestCase($"111111{"\x127"}", false, Description = "delete ascii at end of string")]
        [TestCase($"111111{"\x0"}", false, Description = "null ascii at end of string")]
        [TestCase($"{"\x0"}111111", false, Description = "null ascii at start of string")]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment