assertLadderResult function
Asserts that actual matches the expected value in fixture.
Supports three fixture keys:
expectedContains— assertsactual.toString()contains the string.expectedSorted— sorts both sides before JSON comparison.expected— exact JSON equality.
Implementation
void assertLadderResult(Object? actual, Map<String, dynamic> fixture) {
final expectedContains = fixture['expectedContains'] as String?;
if (expectedContains != null) {
expect(
actual.toString(),
contains(expectedContains),
reason: 'Fixture #${fixture['id']}: expected value to contain '
'"$expectedContains", got: "$actual"',
);
return;
}
var expected = fixture['expected'];
final expectedSorted = fixture['expectedSorted'] as bool? ?? false;
var sortedActual = actual;
if (expectedSorted) {
if (actual is List) {
sortedActual = [...actual]..sort((a, b) => '$a'.compareTo('$b'));
}
if (expected is List) {
expected = [...expected]..sort((a, b) => '$a'.compareTo('$b'));
}
}
expect(
jsonEncode(sortedActual),
jsonEncode(expected),
reason: 'Fixture #${fixture['id']}: '
'expected ${jsonEncode(expected)}, '
'got ${jsonEncode(sortedActual)}',
);
}