public void Format_should_separate_groups_properly_when_formatting_with_custom_match(string testInput, string[] inputUsingNamespaces, string[] expectedOutputNamespaces) { // Arrange var inputUsings = inputUsingNamespaces.Select(ns => new UsingStatement() { Namespace = ns }); var rule = GroupingRule.Parse(testInput).Single(); var output = new OutputBuffer(); // Act rule.Format(output, inputUsings); // Assert var expectedUsings = expectedOutputNamespaces.Select(ns => (ns == "") ? "" : $"using {ns};"); output .GetLines() .Zip(expectedUsings) .Apply( ((string Actual, string Expected)pair, int index) => { pair.Actual.Should().Be(pair.Expected, because: $"line {index} should match"); });
public void Parse_should_parse_empty_string_as_empty_sequence(string testInput) { // Act var rules = GroupingRule.Parse(testInput); rules = rules.ToList(); // Assert rules.Should().BeEmpty(); }
public void Parse_should_parse_direct_namespace_name(string testInput, string expectedParsedNamespace) { // Act var rules = GroupingRule.Parse(testInput); rules = rules.ToList(); // Assert rules.Should().HaveCount(1); rules.Single().MatchList.Should().HaveCount(1); rules.Single().MatchList.Should().HaveElementAt(index: 0, expectedParsedNamespace); rules.Single().SubgroupingBehaviour.Should().Be(SubgroupingBehaviour.MatchRootGroup); }
public void Format_should_produce_matching_output(FormatTestCase testCase) { // Arrange var groupingRules = GroupingRule.Parse(testCase.ConfigurationString); var outputBuffer = new StringWriter(); // Act UsingStatementFormatter.Format( outputBuffer, testCase.Input, groupingRules); // Assert outputBuffer.ToString().Should().Be(testCase.ExpectedOutput); }
public void Parse_should_parse_wildcard_with_matchlist(string testInput, SubgroupingBehaviour expectedSubgroupingBehaviour, string[] expectedMatchList) { // Act var rules = GroupingRule.Parse(testInput); rules = rules.ToList(); // Assert rules.Should().HaveCount(1); var rule = rules.Single(); rule.MatchList.Should().BeEquivalentTo(expectedMatchList); rule.SubgroupingBehaviour.Should().Be(expectedSubgroupingBehaviour); }
public void Parse_should_parse_wildcard_with_no_matchlist(string testInput, SubgroupingBehaviour expectedSubgroupingBehaviour) { // Act var rules = GroupingRule.Parse(testInput); rules = rules.ToList(); // Assert rules.Should().HaveCount(1); var rule = rules.Single(); rule.MatchList.Should().HaveCount(1); rule.MatchList.Should().HaveElementAt(index: 0, "*"); rule.SubgroupingBehaviour.Should().Be(expectedSubgroupingBehaviour); }
public void Parse_should_handle_multiple_rules(string testInput) { // Act var rules = GroupingRule.Parse(testInput) .ToList(); // Assert rules.Should().HaveCount(4); rules[0].MatchList.Should().BeEquivalentTo(new[] { "System" }); rules[0].SubgroupingBehaviour.Should().Be(SubgroupingBehaviour.MatchRootGroup); rules[1].MatchList.Should().BeEquivalentTo(new[] { "Test" }); rules[1].SubgroupingBehaviour.Should().Be(SubgroupingBehaviour.MatchSubgroupsOnlyAsSeparateBlocks); rules[2].MatchList.Should().BeEquivalentTo(new[] { "A", "B" }); rules[2].SubgroupingBehaviour.Should().Be(SubgroupingBehaviour.MatchRootGroupAndSubgroupsAsSingleBlock); rules[3].MatchList.Should().BeEquivalentTo(new[] { "*" }); rules[3].SubgroupingBehaviour.Should().Be(SubgroupingBehaviour.MatchSubgroupsOnlyAsSeparateBlocks); }