|
| 1 | +using System; |
| 2 | +using System.Linq; |
| 3 | +using FluentAssertions; |
| 4 | +using GitHub.Unity.Helpers; |
| 5 | +using NUnit.Framework; |
| 6 | + |
| 7 | +namespace UnitTests |
| 8 | +{ |
| 9 | + [TestFixture] |
| 10 | + public class BranchNameValidatorTests |
| 11 | + { |
| 12 | + [TestCase(true, "feature1", TestName = "Branch name is valid")] |
| 13 | + [TestCase(true, "feature-1", TestName = "Branch name with hyphen is valid")] |
| 14 | + [TestCase(true, "feature.1", TestName = "Branch name can contain dots")] |
| 15 | + [TestCase(true, "feature..1", TestName = "Branch name cannot contain consecutive dots")] |
| 16 | + [TestCase(false, "feature 1", TestName = "Branch name cannot contain a space")] |
| 17 | + [TestCase(false, "feature~1", TestName = "Branch name cannot contain a ~")] |
| 18 | + [TestCase(false, "feature^1", TestName = "Branch name cannot contain a ^")] |
| 19 | + [TestCase(false, "feature:1", TestName = "Branch name cannot contain a :")] |
| 20 | + [TestCase(false, "feature?1", TestName = "Branch name cannot contain a ?")] |
| 21 | + [TestCase(false, "feature*1", TestName = "Branch name cannot contain a *")] |
| 22 | + [TestCase(false, "feature[1", TestName = "Branch name cannot contain a [")] |
| 23 | + [TestCase(false, "/feature1", TestName = "Branch name cannot begin with a slash")] |
| 24 | + [TestCase(false, "feature1/", TestName = "Branch name cannot end with a slash")] |
| 25 | + [TestCase(false, "feature1.", TestName = "Branch name cannot end with a dot")] |
| 26 | + [TestCase(false, "feature1.lock", TestName = "Branch name cannot end with .lock")] |
| 27 | + [TestCase(true, "a", TestName = "Single character is valid")] |
| 28 | + [TestCase(false, "@", TestName = "Single character cannot be @")] |
| 29 | + [TestCase(false, ".", TestName = "Single character cannot be [period]")] |
| 30 | + [TestCase(true, "features/feature-1", TestName = "Folder and branch name is valid")] |
| 31 | + [TestCase(true, "features\\feature-1", TestName = "Backslash is not a valid character")] |
| 32 | + [TestCase(true, ".hidden", TestName = "Branch name is valid when starting with [period]")] |
| 33 | + [TestCase(false, ".features/feature-1", TestName = "Folder and branch name is not valid when starting with [period]")] |
| 34 | + [TestCase(false, "features//feature-1", TestName = "Multiple consecutive slashes are not valid")] |
| 35 | + [TestCase(false, null, TestName = "null string is not valid")] |
| 36 | + [TestCase(false, "", TestName = "Empty string is not valid")] |
| 37 | + [TestCase(false, "/", TestName = "Single slash is not valid")] |
| 38 | + [TestCase(false, "asdf@{", TestName = "Sequence @{ is not valid")] |
| 39 | + public void TestFeatureString(bool isValid, string branch) |
| 40 | + { |
| 41 | + BranchNameValidator.IsBranchNameValid(branch).Should().Be(isValid); |
| 42 | + } |
| 43 | + |
| 44 | + [TestCase(true, 45, 45, 45, TestName = "Can test with ascii values")] |
| 45 | + [TestCase(false, 45, 45, 39, TestName = "No individual ASCII value should be < octal(40)")] |
| 46 | + [TestCase(false, 45, 45, 177, TestName = "No individual ASCII value should = octal(177)")] |
| 47 | + public void TestFeatureStringFromAsciiArray(bool isValid, params int[] asciiValues) |
| 48 | + { |
| 49 | + var branch = new string(asciiValues.Select(Convert.ToChar).ToArray()); |
| 50 | + BranchNameValidator.IsBranchNameValid(branch).Should().Be(isValid); |
| 51 | + } |
| 52 | + } |
| 53 | +} |
0 commit comments