Skip to content

Commit

Permalink
Add tests for paragrah generator in lorem resource
Browse files Browse the repository at this point in the history
  • Loading branch information
easazade committed Sep 15, 2023
1 parent 0f80715 commit 1c4bed9
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 9 deletions.
4 changes: 3 additions & 1 deletion lib/src/locales/en_us/en_us.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,15 @@ class EnUsLorem extends Lorem {
EnUsLorem(this.locale) : super(locale);

String paragraph({
int maxSentences = 1,
int maxSentences = 3,
int minSentences = 1,
}) =>
provide(
DataKeys.paragraph,
locale,
args: lorem_536.ParagraphArgs(
maxSentences: maxSentences,
minSentences: minSentences,
),
);
}
Expand Down
4 changes: 3 additions & 1 deletion lib/src/locales/fa_ir/fa_ir.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,15 @@ class FaIrLorem extends Lorem {
FaIrLorem(this.locale) : super(locale);

String paragraph({
int maxSentences = 1,
int maxSentences = 3,
int minSentences = 1,
}) =>
provide(
DataKeys.paragraph,
locale,
args: lorem_536.ParagraphArgs(
maxSentences: maxSentences,
minSentences: minSentences,
),
);
}
Expand Down
12 changes: 8 additions & 4 deletions lib/src/locales/global/datasources/lorem.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,22 @@ import 'package:faker_x/src/base/base.dart';

class ParagraphArgs {
final int maxSentences;
final int minSentences;

ParagraphArgs({this.maxSentences = 1});
ParagraphArgs({this.maxSentences = 3, this.minSentences = 1});
}

final paragraph = StringDataSource<ParagraphArgs>.withBuilder(
dataKey: DataKeys.paragraph,
locale: Locales.en_us,
builder: (ParagraphArgs args, FakerXLocale locale) {
final sentenceCount = randomInt(args.maxSentences);
return List.generate(
final sentenceCount = randomInt(args.maxSentences, min: args.minSentences);

final sentences = List.generate(
sentenceCount,
(_) => provide(DataKeys.sentence, locale),
).join('. ');
);

return sentences.join(' ');
},
);
4 changes: 3 additions & 1 deletion test/manual/en_us/paragraph_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import '../../utils.dart';

void main() {
test("en_us -> lorem -> paragraph test", () async {
// TODO: please write test manually to test FakerX.localized.en_us.lorem.paragraph(args)
for (var i = 0; i < testRepeatCount; i++) {
assertFakeValue(FakerX.localized.en_us.lorem.paragraph(maxSentences: 4));
}
});
}
5 changes: 4 additions & 1 deletion test/manual/fa_ir/paragraph_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import '../../utils.dart';

void main() {
test("fa_ir -> lorem -> paragraph test", () async {
// TODO: please write test manually to test FakerX.localized.fa_ir.lorem.paragraph(args)
for (var i = 0; i < testRepeatCount; i++) {
final sentence = FakerX.localized.fa_ir.lorem.sentence;
assertFakeValue(FakerX.localized.fa_ir.lorem.paragraph(maxSentences: 4));
}
});
}
2 changes: 1 addition & 1 deletion test/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import 'package:faker_x/src/base/utils.dart';
import 'package:test/expect.dart';

const testRepeatCount = 10000;
const testRepeatCount = 1;

void assertFakeValue(dynamic value) {
expect(value, isNotNull);
Expand Down

0 comments on commit 1c4bed9

Please sign in to comment.