Skip to content

Commit

Permalink
Use raw string literals for prettier multiline strings
Browse files Browse the repository at this point in the history
  • Loading branch information
jnyrup committed Feb 24, 2024
1 parent eedb883 commit 8c2ae2a
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 48 deletions.
Expand Up @@ -94,18 +94,18 @@ public void Any_items_not_satisfying_inspector_should_throw()
// Assert
act.Should()
.Throw<XunitException>()
.WithMessage(
@"Expected customers to contain only items satisfying the inspector because we want to test nested assertions:
*At index 0:
*Expected customer.Age to be less than 21, but found 21
*Expected customer.Items to contain only items satisfying the inspector:
*At index 0:
*Expected item to be 3, but found 1
*At index 1:
*Expected item to be 3, but found 2
*At index 1:
*Expected customer.Age to be less than 21, but found 22 (difference of 1)"
);
.WithMessage("""
Expected customers to contain only items satisfying the inspector because we want to test nested assertions:
*At index 0:
*Expected customer.Age to be less than 21, but found 21
*Expected customer.Items to contain only items satisfying the inspector:
*At index 0:
*Expected item to be 3, but found 1
*At index 1:
*Expected item to be 3, but found 2
*At index 1:
*Expected customer.Age to be less than 21, but found 22 (difference of 1)
""");
}

[Fact]
Expand Down
Expand Up @@ -59,10 +59,11 @@ public void When_one_element_does_not_have_matching_predicate_Satisfy_should_thr
element => element == 2);

// Assert
act.Should().Throw<XunitException>().WithMessage(
@"Expected collection to satisfy all predicates, but:
*The following predicates did not have matching elements:
*(element == 3)");
act.Should().Throw<XunitException>().WithMessage("""
Expected collection to satisfy all predicates, but:
*The following predicates did not have matching elements:
*(element == 3)
""");
}

[Fact]
Expand Down Expand Up @@ -141,14 +142,15 @@ public void
becauseArgs: "args");

// Assert
act.Should().Throw<XunitException>().WithMessage(
@"Expected collection to satisfy all predicates because we want to test formatting (args), but:
*The following predicates did not have matching elements:
*(element.Text == ""two"") AndAlso (element.Number == 2)
*The following elements did not match any predicate:
*Index: 0, Element:*FluentAssertions.Specs.Collections.CollectionAssertionSpecs+SomeClass*{*Number = 1*Text = ""one""*}
*Index: 1, Element:*FluentAssertions.Specs.Collections.CollectionAssertionSpecs+SomeClass*{*Number = 3*Text = ""two""*}
*Index: 2, Element:*FluentAssertions.Specs.Collections.CollectionAssertionSpecs+SomeClass*{*Number = 3*Text = ""three""*}");
act.Should().Throw<XunitException>().WithMessage("""
Expected collection to satisfy all predicates because we want to test formatting (args), but:
*The following predicates did not have matching elements:
*(element.Text == "two") AndAlso (element.Number == 2)
*The following elements did not match any predicate:
*Index: 0, Element:*FluentAssertions.Specs.Collections.CollectionAssertionSpecs+SomeClass*{*Number = 1*Text = "one"*}
*Index: 1, Element:*FluentAssertions.Specs.Collections.CollectionAssertionSpecs+SomeClass*{*Number = 3*Text = "two"*}
*Index: 2, Element:*FluentAssertions.Specs.Collections.CollectionAssertionSpecs+SomeClass*{*Number = 3*Text = "three"*}
""");
}

[Fact]
Expand Down Expand Up @@ -237,11 +239,12 @@ public void When_elements_are_integers_assertion_fails_then_failure_message_must
element => element == 2);

// Assert
act.Should().Throw<XunitException>().WithMessage(
@"Expected collection to satisfy all predicates, but:
*The following elements did not match any predicate:
*Index: 0, Element: 1
*Index: 2, Element: 3");
act.Should().Throw<XunitException>().WithMessage("""
Expected collection to satisfy all predicates, but:
*The following elements did not match any predicate:
*Index: 0, Element: 1
*Index: 2, Element: 3
""");
}
}

Expand Down
Expand Up @@ -126,21 +126,21 @@ public void When_asserting_collection_does_not_satisfy_any_inspector_it_should_t
}, "because we want to test {0}", "nested assertions");

// Assert
act.Should().Throw<XunitException>().WithMessage(
@"Expected customers to satisfy all inspectors because we want to test nested assertions, but some inspectors are not satisfied:
*At index 0:
*Expected customer.Age to be less than 21, but found 21
*Expected customer.Items to satisfy all inspectors, but some inspectors are not satisfied:
*At index 0:
*Expected item to be 2, but found 1
*At index 1:
*Expected item to be 1, but found 2
*At index 1:
*Expected customer.Age to be less than 22, but found 22
*Expected customer.Items to satisfy all inspectors, but some inspectors are not satisfied:
*At index 0:
*Expected item to be 2, but found 3"
);
act.Should().Throw<XunitException>().WithMessage("""
Expected customers to satisfy all inspectors because we want to test nested assertions, but some inspectors are not satisfied:
*At index 0:
*Expected customer.Age to be less than 21, but found 21
*Expected customer.Items to satisfy all inspectors, but some inspectors are not satisfied:
*At index 0:
*Expected item to be 2, but found 1
*At index 1:
*Expected item to be 1, but found 2
*At index 1:
*Expected customer.Age to be less than 22, but found 22
*Expected customer.Items to satisfy all inspectors, but some inspectors are not satisfied:
*At index 0:
*Expected item to be 2, but found 3
""");
}

[Fact]
Expand Down
9 changes: 5 additions & 4 deletions Tests/FluentAssertions.Specs/Xml/XElementFormatterSpecs.cs
Expand Up @@ -21,10 +21,11 @@ public void When_element_has_attributes_it_should_include_them_in_the_output()
public void When_element_has_child_element_it_should_not_include_them_in_the_output()
{
// Act
var element = XElement.Parse(
@"<person name=""Martin"" age=""36"">
<child name=""Laura"" />
</person>");
var element = XElement.Parse("""
<person name="Martin" age="36">
<child name="Laura" />
</person>
""");

string result = Formatter.ToString(element);

Expand Down

0 comments on commit 8c2ae2a

Please sign in to comment.