- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
Move text encoding test data to YAML file
1 parent
f79709d
commit 174918b
Showing
13 changed files
with
546 additions
and
854 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,118 +1,47 @@ | ||
// ignore_for_file: lines_longer_than_80_chars | ||
|
||
import 'package:meta/meta.dart'; | ||
import 'package:rrule/rrule.dart'; | ||
import 'package:rrule/src/codecs/text/encoder.dart'; | ||
import 'package:supernova/supernova.dart'; | ||
import 'package:supernova/supernova_io.dart'; | ||
import 'package:test/test.dart'; | ||
import 'package:yaml/yaml.dart'; | ||
|
||
import 'utils.dart' as utils; | ||
// ignore: avoid-top-level-members-in-tests | ||
final dataFile = File('test/codecs/text/data.yaml'); | ||
|
||
void main() { | ||
late final RruleL10n l10n; | ||
setUpAll(() async => l10n = await RruleL10nEn.create()); | ||
Future<void> main() async { | ||
final l10n = await createL10n(); | ||
|
||
@isTest | ||
void testText(String text, {required String string}) => | ||
utils.testText(text, text: text, string: string, l10n: () => l10n); | ||
final dataString = await dataFile.readAsString(); | ||
final data = (loadYaml(dataString) as Map<dynamic, dynamic>) | ||
.cast<String, Map<dynamic, dynamic>>() | ||
.mapValues((it) => it.value.cast<String, String>()); | ||
|
||
testText( | ||
'Weekly in January – March, August & September on Monday, Wednesday – Friday & Sunday', | ||
string: 'RRULE:FREQ=WEEKLY;BYMONTH=1,2,3,8,9;BYDAY=MO,WE,TH,FR,SU', | ||
); | ||
testText( | ||
'Every other week in January – March on weekdays & Sunday', | ||
string: | ||
'RRULE:FREQ=WEEKLY;INTERVAL=2;BYMONTH=1,2,3;BYDAY=MO,TU,WE,TH,FR,SU', | ||
); | ||
testText( | ||
'Monthly on every Monday – Wednesday, the 1st Thursday & Friday, the 2nd Thursday – Saturday, the 2nd-to-last Thursday, Friday & Sunday, and the last Thursday, Friday & Sunday that are also the 1st – 5th, 26th, or 3rd-to-last – last day of the month', | ||
string: | ||
'RRULE:FREQ=MONTHLY;BYDAY=MO,TU,WE,1TH,1FR,2TH,2FR,2SA,-2TH,-2FR,-2SU,-1TH,-1FR,-1SU;BYMONTHDAY=1,2,3,4,5,26,-3,-2,-1', | ||
); | ||
for (final MapEntry(key: locale, value: l10n) in l10n.entries) { | ||
group('locale: $locale', () { | ||
for (final MapEntry(key: rruleString, value: text) in data.entries) { | ||
test(rruleString, () { | ||
final rrule = RecurrenceRule.fromString(rruleString); | ||
|
||
// All remaining examples taken from https://github.com/jakubroztocil/rrule/blob/3dc698300e5861311249e85e0e237708702b055d/test/nlp.test.ts, | ||
// though with modified texts. | ||
testText( | ||
'Hourly', | ||
string: 'RRULE:FREQ=HOURLY', | ||
); | ||
testText( | ||
'Every 4 hours', | ||
string: 'RRULE:INTERVAL=4;FREQ=HOURLY', | ||
); | ||
testText( | ||
'Daily', | ||
string: 'RRULE:FREQ=DAILY', | ||
); | ||
testText( | ||
'Weekly', | ||
string: 'RRULE:FREQ=WEEKLY', | ||
); | ||
testText( | ||
'Weekly, 20 times', | ||
string: 'RRULE:FREQ=WEEKLY;COUNT=20', | ||
); | ||
testText( | ||
'Weekly, until Monday, January 1, 2007 8:00:00 AM', | ||
string: 'RRULE:FREQ=WEEKLY;UNTIL=20070101T080000Z', | ||
); | ||
testText( | ||
'Weekly on Tuesday', | ||
string: 'RRULE:FREQ=WEEKLY;BYDAY=TU', | ||
); | ||
testText( | ||
'Weekly on Monday & Wednesday', | ||
string: 'RRULE:FREQ=WEEKLY;BYDAY=MO,WE', | ||
); | ||
testText( | ||
'Weekly on weekdays', | ||
string: 'RRULE:FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR', | ||
); | ||
testText( | ||
'Every other week', | ||
string: 'RRULE:INTERVAL=2;FREQ=WEEKLY', | ||
); | ||
testText( | ||
'Monthly', | ||
string: 'RRULE:FREQ=MONTHLY', | ||
); | ||
testText( | ||
'Monthly on the 4th', | ||
string: 'RRULE:FREQ=MONTHLY;BYMONTHDAY=4', | ||
); | ||
testText( | ||
'Monthly on the 4th-to-last day', | ||
string: 'RRULE:FREQ=MONTHLY;BYMONTHDAY=-4', | ||
); | ||
testText( | ||
'Monthly on the 3rd Tuesday', | ||
string: 'RRULE:FREQ=MONTHLY;BYDAY=+3TU', | ||
); | ||
testText( | ||
'Monthly on the 3rd-to-last Tuesday', | ||
string: 'RRULE:FREQ=MONTHLY;BYDAY=-3TU', | ||
); | ||
testText( | ||
'Monthly on the last Monday', | ||
string: 'RRULE:FREQ=MONTHLY;BYDAY=-1MO', | ||
); | ||
testText( | ||
'Monthly on the 2nd-to-last Friday', | ||
string: 'RRULE:FREQ=MONTHLY;BYDAY=-2FR', | ||
); | ||
testText( | ||
'Every 6 months', | ||
string: 'RRULE:INTERVAL=6;FREQ=MONTHLY', | ||
); | ||
testText( | ||
'Annually', | ||
string: 'RRULE:FREQ=YEARLY', | ||
); | ||
testText( | ||
'Annually on the 1st Friday of the year', | ||
string: 'RRULE:FREQ=YEARLY;BYDAY=+1FR', | ||
); | ||
testText( | ||
'Annually on the 13th Friday of the year', | ||
string: 'RRULE:FREQ=YEARLY;BYDAY=+13FR', | ||
); | ||
// TODO(JonasWanke): use codec directly when supporting fromText() | ||
final textEncoder = RecurrenceRuleToTextEncoder(l10n); | ||
|
||
final localizedText = text[locale]; | ||
if (localizedText == null) { | ||
throw StateError('Missing localized text for $locale'); | ||
} | ||
|
||
expect(textEncoder.convert(rrule), text[locale]); | ||
}); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
// ignore: avoid-top-level-members-in-tests | ||
Future<Map<String, RruleL10n>> createL10n() async { | ||
return { | ||
'en': await RruleL10nEn.create(), | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import 'package:rrule/rrule.dart'; | ||
import 'package:rrule/src/codecs/text/encoder.dart'; | ||
import 'package:supernova/supernova.dart'; | ||
import 'package:yaml/yaml.dart'; | ||
import 'package:yaml_edit/yaml_edit.dart'; | ||
|
||
import 'text_test.dart'; | ||
|
||
// ignore: prefer-correct-test-file-name | ||
Future<void> main() async { | ||
final l10ns = await createL10n(); | ||
|
||
final dataEditor = YamlEditor(await dataFile.readAsString()); | ||
final data = (dataEditor.parseAt([]) as YamlMap) | ||
.cast<String, Map<dynamic, dynamic>>() | ||
.mapValues((it) => it.value.cast<String, String>()); | ||
|
||
for (final MapEntry(key: locale, value: l10n) | ||
in l10ns.entries.sortedBy((it) => it.key)) { | ||
for (final MapEntry(key: rruleString, value: text) in data.entries) { | ||
final rrule = RecurrenceRule.fromString(rruleString); | ||
|
||
// TODO(JonasWanke): use codec directly when supporting fromText() | ||
final textEncoder = RecurrenceRuleToTextEncoder(l10n); | ||
|
||
if (l10ns.length > 1 && text.containsKey(locale)) { | ||
// Remove and re-add the entry to ensure they are ordered | ||
// alphabetically. | ||
dataEditor.remove([rruleString, locale]); | ||
} | ||
dataEditor.update([rruleString, locale], textEncoder.convert(rrule)); | ||
} | ||
} | ||
|
||
await dataFile.writeAsString(dataEditor.toString()); | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters