Skip to content

Commit

Permalink
Add paragrah data source to lorem resource
Browse files Browse the repository at this point in the history
  • Loading branch information
easazade committed Sep 15, 2023
1 parent 4bedb9b commit 8333924
Show file tree
Hide file tree
Showing 12 changed files with 112 additions and 20 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ Below you can see a table of all the locales and all the resources and values th
<td><small><span style='color:black'>license plate</span></small></td>
</tr>
<tr>
<td><small>lorem(2) </small></td>
<td><small><span style='color:black'>sentence</span> | <span style='color:black'>word</span></small></td>
<td><small>lorem(3) </small></td>
<td><small><span style='color:green'>paragraph 🟢</span> | <span style='color:black'>sentence</span> | <span style='color:black'>word</span></small></td>
</tr>
<tr>
<td><small>image(2) </small></td>
Expand Down Expand Up @@ -137,8 +137,8 @@ Below you can see a table of all the locales and all the resources and values th
<td><small><span style='color:black'>license plate</span></small></td>
</tr>
<tr>
<td><small>lorem(2) </small></td>
<td><small><span style='color:black'>sentence</span> | <span style='color:black'>word</span></small></td>
<td><small>lorem(3) </small></td>
<td><small><span style='color:green'>paragraph 🟢</span> | <span style='color:black'>sentence</span> | <span style='color:black'>word</span></small></td>
</tr>
<tr>
<td><small>image(2) </small></td>
Expand Down
1 change: 1 addition & 0 deletions generate_and_test.sh
Original file line number Diff line number Diff line change
@@ -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 &&
Expand Down
1 change: 1 addition & 0 deletions lib/src/base/keys.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
7 changes: 5 additions & 2 deletions lib/src/base/registered_data_sources.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -87,7 +88,8 @@ final Map<FakerXLocale, Map<String, DataSource>> 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
Expand Down Expand Up @@ -149,7 +151,8 @@ final Map<FakerXLocale, Map<String, DataSource>> 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
Expand Down
20 changes: 20 additions & 0 deletions lib/src/locales/en_us/en_us.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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);
Expand Down Expand Up @@ -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;

Expand Down
20 changes: 20 additions & 0 deletions lib/src/locales/fa_ir/fa_ir.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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);
Expand Down Expand Up @@ -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;

Expand Down
21 changes: 21 additions & 0 deletions lib/src/locales/global/datasources/lorem.dart
Original file line number Diff line number Diff line change
@@ -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<ParagraphArgs>.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('. ');
},
);
1 change: 1 addition & 0 deletions scripts/lib_imports.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
27 changes: 14 additions & 13 deletions test/en_us_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});

Expand Down
12 changes: 12 additions & 0 deletions test/manual/en_us/paragraph_test.dart
Original file line number Diff line number Diff line change
@@ -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)
});
}
12 changes: 12 additions & 0 deletions test/manual/fa_ir/paragraph_test.dart
Original file line number Diff line number Diff line change
@@ -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)
});
}

0 comments on commit 8333924

Please sign in to comment.