Skip to content

Commit

Permalink
chore: Compile the example files into a single file example.dart.
Browse files Browse the repository at this point in the history
  • Loading branch information
vxern committed Jan 9, 2023
1 parent 6515bd5 commit 4771fbb
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 53 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.2.0+1

- Compiled the example files into a single file `example.dart`.

## 2.2.0

- Added support for the `Crawl-delay` and `Host` fields.
Expand Down
49 changes: 49 additions & 0 deletions example/parse_example.dart → example/example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,55 @@ Future<void> main() async {
print(
"Can '$userAgent' access /wordcollector/robots_txt/? ${robots.verifyCanAccess('/wordcollector/robots_txt/', userAgent: userAgent)}",
);

// Validating an invalid file will throw a `FormatException`.
try {
Robots.validate('This is an obviously invalid robots.txt file.');
} on FormatException {
print('As expected, the first file is flagged as invalid.');
}

// Validating an already valid file will not throw anything.
try {
Robots.validate('''
User-agent: *
Crawl-delay: 10
Disallow: /
Allow: /file.txt
Host: https://hosting.example.com/
Sitemap: https://example.com/sitemap.xml
''');
print('As expected also, the second file is not flagged as invalid.');
} on FormatException {
print('Welp, this was not supposed to happen.');
}

late final String contentsFromBefore;

// Validating a file with unsupported fields.
try {
Robots.validate(
contentsFromBefore = '''
User-agent: *
Some-field: abcd.txt
''',
);
} on FormatException {
print(
'This file is invalid on the grounds that it contains fields we did not '
'expect it to have.',
);
print(
"Let's fix that by including the custom field in the call to validate().",
);
try {
Robots.validate(contentsFromBefore, allowedFieldNames: {'Some-field'});
print('Aha! Now there are no issues.');
} on FormatException {
print('Welp, this also was not supposed to happen.');
}
}
}

Future<String> fetchFileContents({required String host}) async {
Expand Down
52 changes: 0 additions & 52 deletions example/validate_example.dart

This file was deleted.

2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: robots_txt
version: 2.2.0
version: 2.2.0+1

description: A complete, dependency-less and fully documented `robots.txt` ruleset parser.

Expand Down

0 comments on commit 4771fbb

Please sign in to comment.