Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 26 additions & 8 deletions Source/aweXpect/That/Strings/ThatString.Contains.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public static partial class ThatString
Quantifier quantifier = new();
StringEqualityOptions options = new();
return new StringEqualityTypeCountResult<string?, IThat<string?>>(
source.Get().ExpectationBuilder.AddConstraint((it, grammars) =>
new ContainsConstraint(it, grammars, expected, quantifier, options)),
source.Get().ExpectationBuilder.AddConstraint((expectationBuilder, it, grammars) =>
new ContainsConstraint(expectationBuilder, it, grammars, expected, quantifier, options)),
source,
quantifier,
options);
Expand All @@ -51,14 +51,15 @@ public static partial class ThatString
Quantifier quantifier = new();
StringEqualityOptions options = new();
return new StringEqualityTypeCountResult<string?, IThat<string?>>(
source.Get().ExpectationBuilder.AddConstraint((it, grammars) =>
new ContainsConstraint(it, grammars, unexpected, quantifier, options).Invert()),
source.Get().ExpectationBuilder.AddConstraint((expectationBuilder, it, grammars) =>
new ContainsConstraint(expectationBuilder, it, grammars, unexpected, quantifier, options).Invert()),
source,
quantifier,
options);
}

private sealed class ContainsConstraint(
ExpectationBuilder expectationBuilder,
string it,
ExpectationGrammars grammars,
string? expected,
Expand All @@ -83,6 +84,15 @@ public async Task<ConstraintResult> IsMetBy(string? actual, CancellationToken ca

_actualCount = await CountOccurrences(actual, expected, options);
Outcome = quantifier.Check(_actualCount, true) ?? _isNegated ? Outcome.Success : Outcome.Failure;
if (Outcome != Outcome.Success && !string.IsNullOrEmpty(actual))
{
expectationBuilder.AddContext(new ResultContext.Fixed("Actual", actual));
if (!string.IsNullOrEmpty(expected))
{
expectationBuilder.AddContext(new ResultContext.Fixed("Expected", expected));
}
}

Comment thread
vbreuss marked this conversation as resolved.
return this;
}

Expand Down Expand Up @@ -165,19 +175,27 @@ public override void AppendResult(StringBuilder stringBuilder, string? indentati
{
if (_actualCount == 0)
{
stringBuilder.Append(it).Append(" did not contain it in ");
stringBuilder.Append(it).Append(" did not contain ");
Formatter.Format(stringBuilder, expected);
stringBuilder.Append(" in ");
}
else if (_actualCount == 1)
{
stringBuilder.Append(it).Append(" contained it once in ");
stringBuilder.Append(it).Append(" contained ");
Formatter.Format(stringBuilder, expected);
stringBuilder.Append(" once in ");
}
else if (_actualCount == 2)
{
stringBuilder.Append(it).Append(" contained it twice in ");
stringBuilder.Append(it).Append(" contained ");
Formatter.Format(stringBuilder, expected);
stringBuilder.Append(" twice in ");
}
else
{
stringBuilder.Append(it).Append(" contained it ").Append(_actualCount).Append(" times in ");
stringBuilder.Append(it).Append(" contained ");
Formatter.Format(stringBuilder, expected);
stringBuilder.Append(' ').Append(_actualCount).Append(" times in ");
}

Formatter.Format(stringBuilder, _actual);
Expand Down
16 changes: 14 additions & 2 deletions Tests/aweXpect.Tests/Strings/ThatString.Contains.AtLeastTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ await That(Act).Throws<XunitException>()
.WithMessage("""
Expected that subject
contains "in" at least 5 times,
but it contained it 3 times in "In this text in between the word an investigator should find the word 'IN' multiple times."
but it contained "in" 3 times in "In this text in between the word an investigator should find the word 'IN' multiple times."

Actual:
In this text in between the word an investigator should find the word 'IN' multiple times.

Expected:
in
""");
}

Expand All @@ -51,7 +57,13 @@ await That(Act).Throws<XunitException>()
.WithMessage("""
Expected that subject
contains "text that does not occur" at least once,
but it did not contain it in "In this text in between the word an investigator should find the word 'IN' multiple times."
but it did not contain "text that does not occur" in "In this text in between the word an investigator should find the word 'IN' multiple times."

Actual:
In this text in between the word an investigator should find the word 'IN' multiple times.

Expected:
text that does not occur
""");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ await That(Act).Throws<XunitException>()
.WithMessage("""
Expected that subject
contains "in" at most twice,
but it contained it 3 times in "In this text in between the word an investigator should find the word 'IN' multiple times."
but it contained "in" 3 times in "In this text in between the word an investigator should find the word 'IN' multiple times."

Actual:
In this text in between the word an investigator should find the word 'IN' multiple times.

Expected:
in
""");
}

Expand Down
16 changes: 14 additions & 2 deletions Tests/aweXpect.Tests/Strings/ThatString.Contains.BetweenTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ await That(Act).Throws<XunitException>()
.WithMessage("""
Expected that subject
contains "in" between 4 and 9 times,
but it contained it 3 times in "In this text in between the word an investigator should find the word 'IN' multiple times."
but it contained "in" 3 times in "In this text in between the word an investigator should find the word 'IN' multiple times."

Actual:
In this text in between the word an investigator should find the word 'IN' multiple times.

Expected:
in
""");
}

Expand All @@ -38,7 +44,13 @@ await That(Act).Throws<XunitException>()
.WithMessage("""
Expected that subject
contains "in" between 1 and 2 times,
but it contained it 3 times in "In this text in between the word an investigator should find the word 'IN' multiple times."
but it contained "in" 3 times in "In this text in between the word an investigator should find the word 'IN' multiple times."

Actual:
In this text in between the word an investigator should find the word 'IN' multiple times.

Expected:
in
""");
}

Expand Down
16 changes: 14 additions & 2 deletions Tests/aweXpect.Tests/Strings/ThatString.Contains.ExactlyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,13 @@ await That(Act).Throws<XunitException>()
.WithMessage("""
Expected that subject
contains "in" exactly 4 times,
but it contained it 3 times in "In this text in between the word an investigator should find the word 'IN' multiple times."
but it contained "in" 3 times in "In this text in between the word an investigator should find the word 'IN' multiple times."

Actual:
In this text in between the word an investigator should find the word 'IN' multiple times.

Expected:
in
""");
}

Expand All @@ -67,7 +73,13 @@ await That(Act).Throws<XunitException>()
.WithMessage("""
Expected that subject
contains "in" exactly twice,
but it contained it 3 times in "In this text in between the word an investigator should find the word 'IN' multiple times."
but it contained "in" 3 times in "In this text in between the word an investigator should find the word 'IN' multiple times."

Actual:
In this text in between the word an investigator should find the word 'IN' multiple times.

Expected:
in
""");
}
}
Expand Down
16 changes: 14 additions & 2 deletions Tests/aweXpect.Tests/Strings/ThatString.Contains.LessThanTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ await That(Act).Throws<XunitException>()
.WithMessage("""
Expected that subject
contains "in" less than 3 times,
but it contained it 3 times in "In this text in between the word an investigator should find the word 'IN' multiple times."
but it contained "in" 3 times in "In this text in between the word an investigator should find the word 'IN' multiple times."

Actual:
In this text in between the word an investigator should find the word 'IN' multiple times.

Expected:
in
""");
}

Expand All @@ -51,7 +57,13 @@ await That(Act).Throws<XunitException>()
.WithMessage("""
Expected that subject
contains "in" less than once,
but it contained it 3 times in "In this text in between the word an investigator should find the word 'IN' multiple times."
but it contained "in" 3 times in "In this text in between the word an investigator should find the word 'IN' multiple times."

Actual:
In this text in between the word an investigator should find the word 'IN' multiple times.

Expected:
in
""");
}

Expand Down
16 changes: 14 additions & 2 deletions Tests/aweXpect.Tests/Strings/ThatString.Contains.MoreThanTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ await That(Act).Throws<XunitException>()
.WithMessage("""
Expected that subject
contains "text that does not occur" more than once,
but it did not contain it in "In this text in between the word an investigator should find the word 'IN' multiple times."
but it did not contain "text that does not occur" in "In this text in between the word an investigator should find the word 'IN' multiple times."

Actual:
In this text in between the word an investigator should find the word 'IN' multiple times.

Expected:
text that does not occur
""");
}

Expand Down Expand Up @@ -53,7 +59,13 @@ await That(Act).Throws<XunitException>()
.WithMessage($"""
Expected that subject
contains "in" more than {minimum} times,
but it contained it 3 times in "In this text in between the word an investigator should find the word 'IN' multiple times."
but it contained "in" 3 times in "In this text in between the word an investigator should find the word 'IN' multiple times."

Actual:
In this text in between the word an investigator should find the word 'IN' multiple times.

Expected:
in
""");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ await That(Act).Throws<XunitException>()
.WithMessage("""
Expected that subject
does not contain "investigator",
but it contained it once in "In this text in between the word an investigator should find the word 'IN' multiple times."
but it contained "investigator" once in "In this text in between the word an investigator should find the word 'IN' multiple times."

Actual:
In this text in between the word an investigator should find the word 'IN' multiple times.

Expected:
investigator
""");
}
}
Expand Down
16 changes: 14 additions & 2 deletions Tests/aweXpect.Tests/Strings/ThatString.Contains.OnceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ await That(Act).Throws<XunitException>()
.WithMessage("""
Expected that subject
contains "detective" exactly once,
but it did not contain it in "In this text in between the word an investigator should find the word 'IN' multiple times."
but it did not contain "detective" in "In this text in between the word an investigator should find the word 'IN' multiple times."

Actual:
In this text in between the word an investigator should find the word 'IN' multiple times.

Expected:
detective
""");
}

Expand All @@ -51,7 +57,13 @@ await That(Act).Throws<XunitException>()
.WithMessage("""
Expected that subject
contains "word" exactly once,
but it contained it twice in "In this text in between the word an investigator should find the word 'IN' multiple times."
but it contained "word" twice in "In this text in between the word an investigator should find the word 'IN' multiple times."

Actual:
In this text in between the word an investigator should find the word 'IN' multiple times.

Expected:
word
""");
}
}
Expand Down
24 changes: 21 additions & 3 deletions Tests/aweXpect.Tests/Strings/ThatString.Contains.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,13 @@ await That(Act).Throws<XunitException>()
.WithMessage("""
Expected that subject
contains "not" at least once,
but it did not contain it in "some text"
but it did not contain "not" in "some text"

Actual:
some text

Expected:
not
""");
}
}
Expand All @@ -99,7 +105,13 @@ await That(Act).Throws<XunitException>()
.WithMessage("""
Expected that subject
contains "in" at least 7 times ignoring case,
but it contained it 5 times in "In this text in between the word an investigator should find the word 'IN' multiple times."
but it contained "in" 5 times in "In this text in between the word an investigator should find the word 'IN' multiple times."

Actual:
In this text in between the word an investigator should find the word 'IN' multiple times.

Expected:
in
""");
}

Expand Down Expand Up @@ -151,7 +163,13 @@ await That(Act).Throws<XunitException>()
.WithMessage("""
Expected that subject
contains "in" exactly 5 times using IgnoreCaseForVocalsComparer,
but it contained it 4 times in "In this text in between the word an investigator should find the word 'IN' multiple times."
but it contained "in" 4 times in "In this text in between the word an investigator should find the word 'IN' multiple times."

Actual:
In this text in between the word an investigator should find the word 'IN' multiple times.

Expected:
in
""");
}
}
Expand Down
16 changes: 14 additions & 2 deletions Tests/aweXpect.Tests/Strings/ThatString.Contains.TwiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ await That(Act).Throws<XunitException>()
.WithMessage("""
Expected that subject
contains "investigator" exactly twice,
but it contained it once in "In this text in between the word an investigator should find the word 'IN' multiple times."
but it contained "investigator" once in "In this text in between the word an investigator should find the word 'IN' multiple times."

Actual:
In this text in between the word an investigator should find the word 'IN' multiple times.

Expected:
investigator
""");
}

Expand All @@ -51,7 +57,13 @@ await That(Act).Throws<XunitException>()
.WithMessage("""
Expected that subject
contains "in" exactly twice,
but it contained it 3 times in "In this text in between the word an investigator should find the word 'IN' multiple times."
but it contained "in" 3 times in "In this text in between the word an investigator should find the word 'IN' multiple times."

Actual:
In this text in between the word an investigator should find the word 'IN' multiple times.

Expected:
in
""");
}
}
Expand Down
Loading
Loading