Skip to content

Commit

Permalink
Merge branch 'master' of github.com:drager/faker
Browse files Browse the repository at this point in the history
  • Loading branch information
drager committed Jun 28, 2019
2 parents 4bde762 + 48a17c2 commit 2b46f51
Show file tree
Hide file tree
Showing 8 changed files with 1,108 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ main() {
faker.person.suffix();
// Sr.
faker.lorem.sentence();
// Nec nam aliquam sem et
}
```

Expand Down
858 changes: 858 additions & 0 deletions lib/src/data/lorem/sentences.dart

Large diffs are not rendered by default.

169 changes: 169 additions & 0 deletions lib/src/data/lorem/words.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
const words = [
'a',
'ac',
'accumsan',
'adipiscing',
'aenean',
'aliquam',
'aliquet',
'amet',
'ante',
'arcu',
'at',
'auctor',
'augue',
'bibendum',
'blandit',
'commodo',
'condimentum',
'congue',
'consectetur',
'consequat',
'convallis',
'cras',
'cum',
'curabitur',
'cursus',
'dapibus',
'diam',
'dictum',
'dictumst',
'dignissim',
'dis',
'dolor',
'donec',
'dui',
'duis',
'egestas',
'eget',
'eleifend',
'elementum',
'elit',
'enim',
'erat',
'eros',
'est',
'et',
'etiam',
'eu',
'euismod',
'facilisi',
'facilisis',
'fames',
'faucibus',
'felis',
'fermentum',
'feugiat',
'fringilla',
'fusce',
'gravida',
'habitant',
'habitasse',
'hac',
'hendrerit',
'iaculis',
'id',
'imperdiet',
'in',
'integer',
'interdum',
'ipsum',
'justo',
'lacinia',
'lacus',
'laoreet',
'lectus',
'leo',
'libero',
'ligula',
'lobortis',
'lorem',
'luctus',
'maecenas',
'magna',
'magnis',
'malesuada',
'massa',
'mattis',
'mauris',
'metus',
'mi',
'molestie',
'mollis',
'montes',
'morbi',
'mus',
'nam',
'nascetur',
'natoque',
'nec',
'neque',
'netus',
'nibh',
'nisi',
'nisl',
'non',
'nulla',
'nullam',
'nunc',
'odio',
'orci',
'ornare',
'parturient',
'pellentesque',
'penatibus',
'pharetra',
'phasellus',
'placerat',
'platea',
'porta',
'porttitor',
'posuere',
'potenti',
'praesent',
'pretium',
'proin',
'pulvinar',
'purus',
'quam',
'quis',
'quisque',
'rhoncus',
'ridiculus',
'risus',
'sagittis',
'sapien',
'scelerisque',
'sed',
'sem',
'semper',
'senectus',
'sit',
'sociis',
'sodales',
'sollicitudin',
'suscipit',
'suspendisse',
'tellus',
'tempor',
'tempus',
'tincidunt',
'tortor',
'tristique',
'turpis',
'ullamcorper',
'ultrices',
'ultricies',
'urna',
'ut',
'varius',
'vel',
'velit',
'venenatis',
'vestibulum',
'vitae',
'vivamus',
'viverra',
'volutpat',
'vulputate',
];
4 changes: 4 additions & 0 deletions lib/src/faker.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'package:faker/src/lorem.dart';

import 'address.dart';
import 'company.dart';
import 'conference.dart';
Expand All @@ -21,6 +23,7 @@ class Faker {
final Guid guid;
final Internet internet;
final Job job;
final Lorem lorem;
final Person person;
final Sport sport;
final RandomGenerator randomGenerator;
Expand All @@ -34,6 +37,7 @@ class Faker {
guid = const Guid(),
internet = const Internet(),
job = const Job(),
lorem = const Lorem(),
person = const Person(),
sport = const Sport(),
randomGenerator = const RandomGenerator();
Expand Down
45 changes: 45 additions & 0 deletions lib/src/lorem.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import 'data/lorem/words.dart' as word_list;
import 'data/lorem/sentences.dart' as sentence_list;
import 'random_generator.dart';

class Lorem {
const Lorem();

/// Generates a word.
///
/// Example:
/// ```dart
/// faker.lorem.word();
/// ```
String word() => random.element(word_list.words);

/// Generates a list of random words. The number of words is determined
/// by the `numberOfWords` parameter.
///
/// Example:
/// ```dart
/// faker.lorem.words(3);
/// ```
List<String> words(numberOfWords) {
return Iterable<int>.generate(numberOfWords).map((_) => word()).toList();
}

/// Generates a random sentence.
///
/// Example:
/// ```dart
/// faker.lorem.sentence();
/// ```
String sentence() => random.element(sentence_list.sentences);

/// Generates a list of random sentences. The size of the list of determined
/// by the `numberOfSentences` parameter.
///
/// Example:
/// ```dart
/// faker.lorem.sentences(5);
/// ```
List<String> sentences(numberOfSentences) {
return Iterable<int>.generate(numberOfSentences).map((_) => word()).toList();
}
}
2 changes: 1 addition & 1 deletion lib/src/random_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class RandomGenerator {
const RandomGenerator();

/// Plucks a random element from the given [list].
element(List list) {
T element<T>(List<T> list) {
return list[_rng.nextInt(list.length)];
}

Expand Down
2 changes: 2 additions & 0 deletions test/runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'specs/food.dart' as food;
import 'specs/guid.dart' as guid;
import 'specs/internet.dart' as internet;
import 'specs/job.dart' as job;
import 'specs/lorem.dart' as lorem;
import 'specs/person.dart' as person;
import 'specs/sport.dart' as sport;
import 'specs/random_generator.dart' as random;
Expand All @@ -19,6 +20,7 @@ main() {
guid.main();
internet.main();
job.main();
lorem.main();
person.main();
sport.main();
random.main();
Expand Down
26 changes: 26 additions & 0 deletions test/specs/lorem.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import 'package:faker/faker.dart';
import 'package:test/test.dart';

main() {
group('Lorem', (){
group('words', () {
test('should be able to generate single word', () {
expect(faker.lorem.word(), matches(new RegExp(r'^[\w-^]+$')));
});

test('should be able to generate word list', () {
expect(faker.lorem.words(3), hasLength(3));
});
});

group('senetences', () {
test('should be able to generate sentence', () {
expect(faker.lorem.sentence(), matches(new RegExp(r'^[\w^ ]+\.$')));
});

test('should be able to generate sentence list', () {
expect(faker.lorem.sentences(3), hasLength(3));
});
});
});
}

0 comments on commit 2b46f51

Please sign in to comment.