Skip to content

Commit

Permalink
some stringifying unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stevesea committed Nov 12, 2024
1 parent a2e8f9f commit cdbca81
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ linter:
- comment_references
- directives_ordering
- invalid_case_patterns
- leading_newlines_in_multiline_strings
- missing_code_block_language_in_doc_comment
- no_self_assignments
- omit_local_variable_types
Expand Down
31 changes: 31 additions & 0 deletions test/dart_dice_parser_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,37 @@ void main() {
});
}

test('toString', () {
// mocked responses should return rolls of 6, 2, 1, 5
final dice = DiceExpression.create('4d6 #s #f #cf #cs', seededRandom);
final out = dice.roll().toString();
expect(
out,
equals(
'(((((4d6) #s ) #f ) #cf ) #cs ) ===> RollSummary(total: 14, results: [6, 2, 1, 5], metadata: {rolled: [6, 2, 1, 5], score: {successes: [6], failures: [1], critSuccesses: [6], critFailures: [1]}})',
),
);
});
test('toString', () {
// mocked responses should return rolls of 6, 2, 1, 5
final dice = DiceExpression.create('4d6 #s #f #cf #cs', seededRandom);
final out = dice.roll().toStringPretty();
expect(
out,
equals(
'''
(((((4d6) #s ) #f ) #cf ) #cs ) ===> RollSummary(total: 14, results: [6, 2, 1, 5], metadata: {rolled: [6, 2, 1, 5], score: {successes: [6], failures: [1], critSuccesses: [6], critFailures: [1]}})
(((((4d6) #s ) #f ) #cf ) #cs ) =count=> RollResult(total: 14, results: [6, 2, 1, 5], metadata: {score: {critSuccesses: [6]}})
((((4d6) #s ) #f ) #cf ) =count=> RollResult(total: 14, results: [6, 2, 1, 5], metadata: {score: {critFailures: [1]}})
(((4d6) #s ) #f ) =count=> RollResult(total: 14, results: [6, 2, 1, 5], metadata: {score: {failures: [1]}})
((4d6) #s ) =count=> RollResult(total: 14, results: [6, 2, 1, 5], metadata: {score: {successes: [6]}})
(4d6) =rollDice=> RollResult(total: 14, results: [6, 2, 1, 5], metadata: {rolled: [6, 2, 1, 5]})
'''
.trim(),
),
);
});
test('toJson', () {
// mocked responses should return rolls of 6, 2, 1, 5
final dice = DiceExpression.create('4d6', seededRandom);
Expand Down

0 comments on commit cdbca81

Please sign in to comment.