From 83339242963e76c4d4b0d583f8ec65d3cded0f6c Mon Sep 17 00:00:00 2001 From: alireza easazade Date: Fri, 15 Sep 2023 20:47:44 +0330 Subject: [PATCH] Add paragrah data source to lorem resource --- CONTRIBUTING.md | 2 +- README.md | 8 +++--- generate_and_test.sh | 1 + lib/src/base/keys.dart | 1 + lib/src/base/registered_data_sources.dart | 7 +++-- lib/src/locales/en_us/en_us.dart | 20 ++++++++++++++ lib/src/locales/fa_ir/fa_ir.dart | 20 ++++++++++++++ lib/src/locales/global/datasources/lorem.dart | 21 +++++++++++++++ scripts/lib_imports.dart | 1 + test/en_us_test.dart | 27 ++++++++++--------- test/manual/en_us/paragraph_test.dart | 12 +++++++++ test/manual/fa_ir/paragraph_test.dart | 12 +++++++++ 12 files changed, 112 insertions(+), 20 deletions(-) create mode 100644 lib/src/locales/global/datasources/lorem.dart create mode 100644 test/manual/en_us/paragraph_test.dart create mode 100644 test/manual/fa_ir/paragraph_test.dart diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c20d38b..62beac9 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -297,7 +297,7 @@ class DataKeys{ } ``` -Then we the `cat_image` datasource the resource file in global directory in `lib/src/locales/global/datasources/image.dart` +Then we add the `cat_image` datasource the resource file in global directory in `lib/src/locales/global/datasources/image.dart` ```dart final cat_image = StringDataSource.withBuilder( dataKey: DataKeys.cat_image, diff --git a/README.md b/README.md index 7376460..e8efe07 100644 --- a/README.md +++ b/README.md @@ -88,8 +88,8 @@ Below you can see a table of all the locales and all the resources and values th license plate -lorem(2) -sentence | word +lorem(3) +paragraph 🟢 | sentence | word image(2) @@ -137,8 +137,8 @@ Below you can see a table of all the locales and all the resources and values th license plate -lorem(2) -sentence | word +lorem(3) +paragraph 🟢 | sentence | word image(2) diff --git a/generate_and_test.sh b/generate_and_test.sh index 1cc233b..c8e4016 100644 --- a/generate_and_test.sh +++ b/generate_and_test.sh @@ -1,6 +1,7 @@ #!/bin/bash dart scripts/regenerate_base_classes.dart +dart scripts/register_data_sources.dart.dart dart scripts/generate_all.dart && dart scripts/create_tests.dart && dart scripts/generate_example.dart && diff --git a/lib/src/base/keys.dart b/lib/src/base/keys.dart index 6e1fd57..6c32dbf 100644 --- a/lib/src/base/keys.dart +++ b/lib/src/base/keys.dart @@ -9,6 +9,7 @@ class DataKeys { static const word = 'word'; static const sentence = 'sentence'; + static const paragraph = 'paragraph'; static const job_title = 'job_title'; static const job_suffix = 'job_suffix'; diff --git a/lib/src/base/registered_data_sources.dart b/lib/src/base/registered_data_sources.dart index f41ae59..bff8627 100644 --- a/lib/src/base/registered_data_sources.dart +++ b/lib/src/base/registered_data_sources.dart @@ -25,6 +25,7 @@ import 'package:faker_x/src/locales/en_us/datasources/phone.dart' as phone_59; import 'package:faker_x/src/locales/en_us/datasources/job.dart' as job_914; import 'package:faker_x/src/locales/en_us/datasources/automotive.dart' as automotive_744; +import 'package:faker_x/src/locales/global/datasources/lorem.dart' as lorem_536; import 'package:faker_x/src/locales/en_us/datasources/lorem.dart' as lorem_915; import 'package:faker_x/src/locales/global/datasources/image.dart' as image_121; import 'package:faker_x/src/locales/global/datasources/internet.dart' @@ -87,7 +88,8 @@ final Map> registeredDataSources = { DataKeys.job_title: job_914.job_title, // en_us.automotive has 1 DataSources DataKeys.license_plate: automotive_744.license_plate, - // en_us.lorem has 2 DataSources + // en_us.lorem has 3 DataSources + DataKeys.paragraph: lorem_536.paragraph, DataKeys.sentence: lorem_915.sentence, DataKeys.word: lorem_915.word, // en_us.image has 2 DataSources @@ -149,7 +151,8 @@ final Map> registeredDataSources = { DataKeys.job_title: job_938.job_title, // fa_ir.automotive has 1 DataSources DataKeys.license_plate: automotive_31.license_plate, - // fa_ir.lorem has 2 DataSources + // fa_ir.lorem has 3 DataSources + DataKeys.paragraph: lorem_536.paragraph, DataKeys.sentence: lorem_817.sentence, DataKeys.word: lorem_817.word, // fa_ir.image has 2 DataSources diff --git a/lib/src/locales/en_us/en_us.dart b/lib/src/locales/en_us/en_us.dart index 172bbea..e735857 100644 --- a/lib/src/locales/en_us/en_us.dart +++ b/lib/src/locales/en_us/en_us.dart @@ -26,6 +26,7 @@ import 'package:faker_x/src/locales/en_us/datasources/phone.dart' as phone_59; import 'package:faker_x/src/locales/en_us/datasources/job.dart' as job_914; import 'package:faker_x/src/locales/en_us/datasources/automotive.dart' as automotive_744; +import 'package:faker_x/src/locales/global/datasources/lorem.dart' as lorem_536; import 'package:faker_x/src/locales/en_us/datasources/lorem.dart' as lorem_915; import 'package:faker_x/src/locales/global/datasources/image.dart' as image_121; import 'package:faker_x/src/locales/global/datasources/internet.dart' @@ -42,6 +43,8 @@ class EnUsCollection extends FakeCollection { EnUsJob get job => EnUsJob(locale); + EnUsLorem get lorem => EnUsLorem(locale); + EnUsImage get image => EnUsImage(locale); EnUsInternet get internet => EnUsInternet(locale); @@ -89,6 +92,23 @@ class EnUsJob extends Job { String get jobSuffix => provide(DataKeys.job_suffix, locale); } +class EnUsLorem extends Lorem { + final FakerXLocale locale; + + EnUsLorem(this.locale) : super(locale); + + String paragraph({ + required int maxSentences, + }) => + provide( + DataKeys.paragraph, + locale, + args: lorem_536.ParagraphArgs( + maxSentences: maxSentences, + ), + ); +} + class EnUsImage extends Image { final FakerXLocale locale; diff --git a/lib/src/locales/fa_ir/fa_ir.dart b/lib/src/locales/fa_ir/fa_ir.dart index aff8fef..9808586 100644 --- a/lib/src/locales/fa_ir/fa_ir.dart +++ b/lib/src/locales/fa_ir/fa_ir.dart @@ -26,6 +26,7 @@ import 'package:faker_x/src/locales/fa_ir/datasources/phone.dart' as phone_653; import 'package:faker_x/src/locales/fa_ir/datasources/job.dart' as job_938; import 'package:faker_x/src/locales/fa_ir/datasources/automotive.dart' as automotive_31; +import 'package:faker_x/src/locales/global/datasources/lorem.dart' as lorem_536; import 'package:faker_x/src/locales/fa_ir/datasources/lorem.dart' as lorem_817; import 'package:faker_x/src/locales/global/datasources/image.dart' as image_121; import 'package:faker_x/src/locales/global/datasources/internet.dart' @@ -42,6 +43,8 @@ class FaIrCollection extends FakeCollection { FaIrAutomotive get automotive => FaIrAutomotive(locale); + FaIrLorem get lorem => FaIrLorem(locale); + FaIrImage get image => FaIrImage(locale); FaIrInternet get internet => FaIrInternet(locale); @@ -79,6 +82,23 @@ class FaIrAutomotive extends Automotive { String get licensePlate => provide(DataKeys.license_plate, locale); } +class FaIrLorem extends Lorem { + final FakerXLocale locale; + + FaIrLorem(this.locale) : super(locale); + + String paragraph({ + required int maxSentences, + }) => + provide( + DataKeys.paragraph, + locale, + args: lorem_536.ParagraphArgs( + maxSentences: maxSentences, + ), + ); +} + class FaIrImage extends Image { final FakerXLocale locale; diff --git a/lib/src/locales/global/datasources/lorem.dart b/lib/src/locales/global/datasources/lorem.dart new file mode 100644 index 0000000..db17052 --- /dev/null +++ b/lib/src/locales/global/datasources/lorem.dart @@ -0,0 +1,21 @@ +import 'package:faker_x/src/base/base.dart'; + +class ParagraphArgs { + final int maxSentences; + + ParagraphArgs({ + @nonNullable required this.maxSentences, + }); +} + +final paragraph = StringDataSource.withBuilder( + dataKey: DataKeys.paragraph, + locale: Locales.en_us, + builder: (ParagraphArgs args, FakerXLocale locale) { + final sentenceCount = randomInt(args.maxSentences); + return List.generate( + sentenceCount, + (_) => provide(DataKeys.sentence, locale), + ).join('. '); + }, +); diff --git a/scripts/lib_imports.dart b/scripts/lib_imports.dart index 135dd91..45fd261 100644 --- a/scripts/lib_imports.dart +++ b/scripts/lib_imports.dart @@ -48,4 +48,5 @@ import 'package:faker_x/src/locales/global/datasources/color.dart'; import 'package:faker_x/src/locales/global/datasources/image.dart'; import 'package:faker_x/src/locales/global/datasources/internet.dart'; import 'package:faker_x/src/locales/global/datasources/location.dart'; +import 'package:faker_x/src/locales/global/datasources/lorem.dart'; import 'package:faker_x/src/locales/global/datasources/person.dart'; diff --git a/test/en_us_test.dart b/test/en_us_test.dart index 5a079b8..2c7e540 100644 --- a/test/en_us_test.dart +++ b/test/en_us_test.dart @@ -98,19 +98,20 @@ void main() { test("en_us internet test", () async { for (var i = 0; i < testRepeatCount; i++) { - assertFakeValue('disposableEmail: ' + - FakerX.localized.en_us.internet.disposableEmail); - assertFakeValue('disposableMailProvider: ' + - FakerX.localized.en_us.internet.disposableMailProvider); - assertFakeValue( - 'domainName: ' + FakerX.localized.en_us.internet.domainName); - assertFakeValue( - 'domainSuffixes: ' + FakerX.localized.en_us.internet.domainSuffixes); - assertFakeValue('email: ' + FakerX.localized.en_us.internet.email); - assertFakeValue('emoji: ' + FakerX.localized.en_us.internet.emoji); - assertFakeValue('httpUrl: ' + FakerX.localized.en_us.internet.httpUrl); - assertFakeValue('httpsUrl: ' + FakerX.localized.en_us.internet.httpsUrl); - assertFakeValue('ipv4: ' + FakerX.localized.en_us.internet.ipv4); + assertFakeValue(FakerX.localized.en_us.internet.disposableEmail); + assertFakeValue(FakerX.localized.en_us.internet.disposableMailProvider); + assertFakeValue(FakerX.localized.en_us.internet.domainName); + assertFakeValue(FakerX.localized.en_us.internet.domainSuffixes); + assertFakeValue(FakerX.localized.en_us.internet.email); + assertFakeValue(FakerX.localized.en_us.internet.emoji); + assertFakeValue(FakerX.localized.en_us.internet.httpUrl); + assertFakeValue(FakerX.localized.en_us.internet.httpsUrl); + assertFakeValue(FakerX.localized.en_us.internet.ipv4); + assertFakeValue(FakerX.localized.en_us.internet.ipv6); + assertFakeValue(FakerX.localized.en_us.internet.macAddress); + assertFakeValue(FakerX.localized.en_us.internet.mailProvider); + assertFakeValue(FakerX.localized.en_us.internet.safeEmail); + assertFakeValue(FakerX.localized.en_us.internet.userName); } }); diff --git a/test/manual/en_us/paragraph_test.dart b/test/manual/en_us/paragraph_test.dart new file mode 100644 index 0000000..32c615a --- /dev/null +++ b/test/manual/en_us/paragraph_test.dart @@ -0,0 +1,12 @@ +// ignore_for_file: unused_import + +import 'package:faker_x/faker_x.dart'; +import 'package:test/test.dart'; + +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) + }); +} diff --git a/test/manual/fa_ir/paragraph_test.dart b/test/manual/fa_ir/paragraph_test.dart new file mode 100644 index 0000000..306e065 --- /dev/null +++ b/test/manual/fa_ir/paragraph_test.dart @@ -0,0 +1,12 @@ +// ignore_for_file: unused_import + +import 'package:faker_x/faker_x.dart'; +import 'package:test/test.dart'; + +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) + }); +}