Skip to content

Commit

Permalink
Move text encoding test data to YAML file
Browse files Browse the repository at this point in the history
JonasWanke committed Dec 31, 2024
1 parent f79709d commit 174918b
Showing 13 changed files with 546 additions and 854 deletions.
2 changes: 2 additions & 0 deletions lib/src/codecs/text/l10n/en.dart
Original file line number Diff line number Diff line change
@@ -10,6 +10,8 @@ class RruleL10nEn extends RruleL10n {
const RruleL10nEn._();

static Future<RruleL10nEn> create() async {
// TODO(JonasWanke): Move `initializeDateFormatting(…)` call to the
// library's user
await initializeDateFormatting('en');
return const RruleL10nEn._();
}
2 changes: 2 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -19,3 +19,5 @@ dev_dependencies:
path: supernova
ref: 6da7cfcf12aa2755ed9f7e1a59458c600ef3e1d0
test: ^1.16.8
yaml: ^3.1.2
yaml_edit: ^2.2.2
112 changes: 0 additions & 112 deletions test/codecs/text/daily_test.dart

This file was deleted.

408 changes: 408 additions & 0 deletions test/codecs/text/data.yaml

Large diffs are not rendered by default.

119 changes: 0 additions & 119 deletions test/codecs/text/monthly_test.dart

This file was deleted.

145 changes: 37 additions & 108 deletions test/codecs/text/text_test.dart
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(),
};
}
36 changes: 36 additions & 0 deletions test/codecs/text/update_data.dart
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());
}
22 changes: 0 additions & 22 deletions test/codecs/text/utils.dart

This file was deleted.

69 changes: 0 additions & 69 deletions test/codecs/text/weekly_test.dart

This file was deleted.

380 changes: 0 additions & 380 deletions test/codecs/text/yearly_test.dart

This file was deleted.

7 changes: 3 additions & 4 deletions test/recurrence_rule_test.dart
Original file line number Diff line number Diff line change
@@ -7,8 +7,8 @@ import 'package:rrule/src/cache.dart';
import 'package:rrule/src/utils.dart';
import 'package:test/test.dart';

import 'codecs/text/utils.dart';
import 'codecs/utils.dart';
import 'utils.dart';

void main() {
late final RruleL10n l10n;
@@ -258,7 +258,6 @@ void main() {
until: DateTime.utc(1997, 12, 24),
);
const string = 'RRULE:FREQ=DAILY;UNTIL=19971224T000000Z';
const text = 'Daily, until Wednesday, December 24, 1997 12:00:00 AM';

testStringCodec(
'StringCodec',
@@ -269,9 +268,9 @@ void main() {
string: string,
);

testText(
testTextEn(
'TextCodec',
text: text,
textEn: 'Daily, until Wednesday, December 24, 1997 12:00:00 AM',
string: string,
l10n: () => l10n,
);
72 changes: 36 additions & 36 deletions test/rrule_ical_test.dart
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ void main() {
void testRrule(
String description, {
required String string,
String? text,
String? textEn,
required RecurrenceRule rrule,
required DateTime start,
required Iterable<DateTime> expected,
@@ -24,7 +24,7 @@ void main() {
utils.testRrule(
description,
string: string,
text: text,
textEn: textEn,
rrule: rrule,
start: start,
expected: expected,
@@ -37,11 +37,11 @@ void main() {
// - Some RRULE-strings had some fields reordered to match the production rule
// (recur-rule-part) order and remain consistent. The original string is
// prepended as a comment.
// - The `text` was added manually.
// - The `textEn` was added manually.
testRrule(
'Daily for 10 occurrences',
string: 'RRULE:FREQ=DAILY;COUNT=10',
text: 'Daily, 10 times',
textEn: 'Daily, 10 times',
rrule: RecurrenceRule(
frequency: Frequency.daily,
count: 10,
@@ -52,7 +52,7 @@ void main() {
testRrule(
'Daily until December 24, 1997',
string: 'RRULE:FREQ=DAILY;UNTIL=19971224T000000Z',
text: 'Daily, until Wednesday, December 24, 1997 12:00:00 AM',
textEn: 'Daily, until Wednesday, December 24, 1997 12:00:00 AM',
rrule: RecurrenceRule(
frequency: Frequency.daily,
until: DateTime.utc(1997, 12, 24),
@@ -68,7 +68,7 @@ void main() {
testRrule(
'Every other day - forever',
string: 'RRULE:FREQ=DAILY;INTERVAL=2',
text: 'Every other day',
textEn: 'Every other day',
rrule: RecurrenceRule(
frequency: Frequency.daily,
interval: 2,
@@ -90,7 +90,7 @@ void main() {
'Every 10 days, 5 occurrences',
// RRULE:FREQ=DAILY;INTERVAL=10;COUNT=5
string: 'RRULE:FREQ=DAILY;COUNT=5;INTERVAL=10',
text: 'Every 10 days, 5 times',
textEn: 'Every 10 days, 5 times',
rrule: RecurrenceRule(
frequency: Frequency.daily,
count: 5,
@@ -111,7 +111,7 @@ void main() {
// RRULE:FREQ=YEARLY;UNTIL=20000131T140000Z;BYMONTH=1;BYDAY=SU,MO,TU,WE,TH,FR,SA
string:
'RRULE:FREQ=YEARLY;UNTIL=20000131T140000Z;BYDAY=MO,TU,WE,TH,FR,SA,SU;BYMONTH=1',
text:
textEn:
'Annually on weekdays, every Saturday & Sunday in January, until Monday, January 31, 2000 2:00:00 PM',
rrule: RecurrenceRule(
frequency: Frequency.yearly,
@@ -133,7 +133,7 @@ void main() {
testRrule(
'with frequency daily',
string: 'RRULE:FREQ=DAILY;UNTIL=20000131T140000Z;BYMONTH=1',
text: 'Daily in January, until Monday, January 31, 2000 2:00:00 PM',
textEn: 'Daily in January, until Monday, January 31, 2000 2:00:00 PM',
rrule: RecurrenceRule(
frequency: Frequency.daily,
until: DateTime.utc(2000, 01, 31, 14, 0, 0),
@@ -146,7 +146,7 @@ void main() {
testRrule(
'Weekly for 10 occurrences',
string: 'RRULE:FREQ=WEEKLY;COUNT=10',
text: 'Weekly, 10 times',
textEn: 'Weekly, 10 times',
rrule: RecurrenceRule(
frequency: Frequency.weekly,
count: 10,
@@ -161,7 +161,7 @@ void main() {
testRrule(
'Weekly until December 24, 1997',
string: 'RRULE:FREQ=WEEKLY;UNTIL=19971224T000000Z',
text: 'Weekly, until Wednesday, December 24, 1997 12:00:00 AM',
textEn: 'Weekly, until Wednesday, December 24, 1997 12:00:00 AM',
rrule: RecurrenceRule(
frequency: Frequency.weekly,
until: DateTime.utc(1997, 12, 24),
@@ -179,7 +179,7 @@ void main() {
testRrule(
'Every other week - forever',
string: 'RRULE:FREQ=WEEKLY;INTERVAL=2;WKST=SU',
text: 'Every other week',
textEn: 'Every other week',
rrule: RecurrenceRule(
frequency: Frequency.weekly,
interval: 2,
@@ -206,7 +206,7 @@ void main() {
'with until',
// RRULE:FREQ=WEEKLY;UNTIL=19971007T000000Z;WKST=SU;BYDAY=TU,TH
string: 'RRULE:FREQ=WEEKLY;UNTIL=19971007T000000Z;BYDAY=TU,TH;WKST=SU',
text:
textEn:
'Weekly on Tuesday & Thursday, until Tuesday, October 7, 1997 12:00:00 AM',
rrule: RecurrenceRule(
frequency: Frequency.weekly,
@@ -224,7 +224,7 @@ void main() {
'with count',
// RRULE:FREQ=WEEKLY;COUNT=10;WKST=SU;BYDAY=TU,TH
string: 'RRULE:FREQ=WEEKLY;COUNT=10;BYDAY=TU,TH;WKST=SU',
text: 'Weekly on Tuesday & Thursday, 10 times',
textEn: 'Weekly on Tuesday & Thursday, 10 times',
rrule: RecurrenceRule(
frequency: Frequency.weekly,
count: 10,
@@ -243,7 +243,7 @@ void main() {
// RRULE:FREQ=WEEKLY;INTERVAL=2;UNTIL=19971224T000000Z;WKST=SU;BYDAY=MO,WE,FR
string:
'RRULE:FREQ=WEEKLY;UNTIL=19971224T000000Z;INTERVAL=2;BYDAY=MO,WE,FR;WKST=SU',
text:
textEn:
'Every other week on Monday, Wednesday & Friday, until Wednesday, December 24, 1997 12:00:00 AM',
rrule: RecurrenceRule(
frequency: Frequency.weekly,
@@ -271,7 +271,7 @@ void main() {
'Every other week on Tuesday and Thursday, for 8 occurrences',
// RRULE:FREQ=WEEKLY;INTERVAL=2;COUNT=8;WKST=SU;BYDAY=TU,TH
string: 'RRULE:FREQ=WEEKLY;COUNT=8;INTERVAL=2;BYDAY=TU,TH;WKST=SU',
text: 'Every other week on Tuesday & Thursday, 8 times',
textEn: 'Every other week on Tuesday & Thursday, 8 times',
rrule: RecurrenceRule(
frequency: Frequency.weekly,
count: 8,
@@ -292,7 +292,7 @@ void main() {
testRrule(
'Monthly on the first Friday for 10 occurrences',
string: 'RRULE:FREQ=MONTHLY;COUNT=10;BYDAY=1FR',
text: 'Monthly on the 1st Friday, 10 times',
textEn: 'Monthly on the 1st Friday, 10 times',
rrule: RecurrenceRule(
frequency: Frequency.monthly,
count: 10,
@@ -315,7 +315,7 @@ void main() {
testRrule(
'Monthly on the first Friday until December 24, 1997',
string: 'RRULE:FREQ=MONTHLY;UNTIL=19971224T000000Z;BYDAY=1FR',
text:
textEn:
'Monthly on the 1st Friday, until Wednesday, December 24, 1997 12:00:00 AM',
rrule: RecurrenceRule(
frequency: Frequency.monthly,
@@ -334,7 +334,7 @@ void main() {
'Every other month on the first and last Sunday of the month for 10 occurrences',
// RRULE:FREQ=MONTHLY;INTERVAL=2;COUNT=10;BYDAY=1SU,-1SU
string: 'RRULE:FREQ=MONTHLY;COUNT=10;INTERVAL=2;BYDAY=-1SU,1SU',
text: 'Every other month on the 1st & last Sunday, 10 times',
textEn: 'Every other month on the 1st & last Sunday, 10 times',
rrule: RecurrenceRule(
frequency: Frequency.monthly,
count: 10,
@@ -356,7 +356,7 @@ void main() {
testRrule(
'Monthly on the second-to-last Monday of the month for 6 months',
string: 'RRULE:FREQ=MONTHLY;COUNT=6;BYDAY=-2MO',
text: 'Monthly on the 2nd-to-last Monday, 6 times',
textEn: 'Monthly on the 2nd-to-last Monday, 6 times',
rrule: RecurrenceRule(
frequency: Frequency.monthly,
count: 6,
@@ -375,7 +375,7 @@ void main() {
testRrule(
'Monthly on the third-to-the-last day of the month, forever',
string: 'RRULE:FREQ=MONTHLY;BYMONTHDAY=-3',
text: 'Monthly on the 3rd-to-last day',
textEn: 'Monthly on the 3rd-to-last day',
rrule: RecurrenceRule(
frequency: Frequency.monthly,
byMonthDays: const [-3],
@@ -394,7 +394,7 @@ void main() {
testRrule(
'Monthly on the 2nd and 15th of the month for 10 occurrences',
string: 'RRULE:FREQ=MONTHLY;COUNT=10;BYMONTHDAY=2,15',
text: 'Monthly on the 2nd & 15th, 10 times',
textEn: 'Monthly on the 2nd & 15th, 10 times',
rrule: RecurrenceRule(
frequency: Frequency.monthly,
count: 10,
@@ -413,7 +413,7 @@ void main() {
'Monthly on the first and last day of the month for 10 occurrences:',
// RRULE:FREQ=MONTHLY;COUNT=10;BYMONTHDAY=1,-1
string: 'RRULE:FREQ=MONTHLY;COUNT=10;BYMONTHDAY=-1,1',
text: 'Monthly on the 1st & last day, 10 times',
textEn: 'Monthly on the 1st & last day, 10 times',
rrule: RecurrenceRule(
frequency: Frequency.monthly,
count: 10,
@@ -434,7 +434,7 @@ void main() {
// RRULE:FREQ=MONTHLY;INTERVAL=18;COUNT=10;BYMONTHDAY=10,11,12,13,14,15
string:
'RRULE:FREQ=MONTHLY;COUNT=10;INTERVAL=18;BYMONTHDAY=10,11,12,13,14,15',
text: 'Every 18 months on the 10th – 15th, 10 times',
textEn: 'Every 18 months on the 10th – 15th, 10 times',
rrule: RecurrenceRule(
frequency: Frequency.monthly,
count: 10,
@@ -450,7 +450,7 @@ void main() {
testRrule(
'Every Tuesday, every other month',
string: 'RRULE:FREQ=MONTHLY;INTERVAL=2;BYDAY=TU',
text: 'Every other month on every Tuesday',
textEn: 'Every other month on every Tuesday',
rrule: RecurrenceRule(
frequency: Frequency.monthly,
interval: 2,
@@ -468,7 +468,7 @@ void main() {
testRrule(
'Yearly in June and July for 10 occurrences',
string: 'RRULE:FREQ=YEARLY;COUNT=10;BYMONTH=6,7',
text: 'Annually in June & July, 10 times',
textEn: 'Annually in June & July, 10 times',
rrule: RecurrenceRule(
frequency: Frequency.yearly,
count: 10,
@@ -483,7 +483,7 @@ void main() {
'Every other year on January, February, and March for 10 occurrences',
// RRULE:FREQ=YEARLY;INTERVAL=2;COUNT=10;BYMONTH=1,2,3
string: 'RRULE:FREQ=YEARLY;COUNT=10;INTERVAL=2;BYMONTH=1,2,3',
text: 'Every other year in January – March, 10 times',
textEn: 'Every other year in January – March, 10 times',
rrule: RecurrenceRule(
frequency: Frequency.yearly,
count: 10,
@@ -502,7 +502,7 @@ void main() {
'Every third year on the 1st, 100th, and 200th day for 10 occurrences',
// RRULE:FREQ=YEARLY;INTERVAL=3;COUNT=10;BYYEARDAY=1,100,200
string: 'RRULE:FREQ=YEARLY;COUNT=10;INTERVAL=3;BYYEARDAY=1,100,200',
text: 'Every 3 years on the 1st, 100th & 200th day of the year, 10 times',
textEn: 'Every 3 years on the 1st, 100th & 200th day of the year, 10 times',
rrule: RecurrenceRule(
frequency: Frequency.yearly,
count: 10,
@@ -526,7 +526,7 @@ void main() {
testRrule(
'Every 20th Monday of the year, forever',
string: 'RRULE:FREQ=YEARLY;BYDAY=20MO',
text: 'Annually on the 20th Monday of the year',
textEn: 'Annually on the 20th Monday of the year',
rrule: RecurrenceRule(
frequency: Frequency.yearly,
byWeekDays: [ByWeekDayEntry(DateTime.monday, 20)],
@@ -543,7 +543,7 @@ void main() {
'Monday of week number 20 (where the default start of the week is Monday), forever',
// RRULE:FREQ=YEARLY;BYWEEKNO=20;BYDAY=MO
string: 'RRULE:FREQ=YEARLY;BYDAY=MO;BYWEEKNO=20',
text: 'Annually on Monday in the 20th week of the year',
textEn: 'Annually on Monday in the 20th week of the year',
rrule: RecurrenceRule(
frequency: Frequency.yearly,
byWeekDays: [ByWeekDayEntry(DateTime.monday)],
@@ -561,7 +561,7 @@ void main() {
'Every Thursday in March, forever',
// RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=TH
string: 'RRULE:FREQ=YEARLY;BYDAY=TH;BYMONTH=3',
text: 'Annually on every Thursday in March',
textEn: 'Annually on every Thursday in March',
rrule: RecurrenceRule(
frequency: Frequency.yearly,
byWeekDays: [ByWeekDayEntry(DateTime.thursday)],
@@ -578,7 +578,7 @@ void main() {
testRrule(
'Every Thursday, but only during June, July, and August, forever',
string: 'RRULE:FREQ=YEARLY;BYDAY=TH;BYMONTH=6,7,8',
text: 'Annually on every Thursday in June – August',
textEn: 'Annually on every Thursday in June – August',
rrule: RecurrenceRule(
frequency: Frequency.yearly,
byWeekDays: [ByWeekDayEntry(DateTime.thursday)],
@@ -603,7 +603,7 @@ void main() {
testRrule(
'Every Friday the 13th, forever',
string: 'RRULE:FREQ=MONTHLY;BYDAY=FR;BYMONTHDAY=13',
text: 'Monthly on every Friday that are also the 13th',
textEn: 'Monthly on every Friday that are also the 13th',
rrule: RecurrenceRule(
frequency: Frequency.monthly,
byWeekDays: [ByWeekDayEntry(DateTime.friday)],
@@ -622,7 +622,7 @@ void main() {
testRrule(
'The first Saturday that follows the first Sunday of the month, forever',
string: 'RRULE:FREQ=MONTHLY;BYDAY=SA;BYMONTHDAY=7,8,9,10,11,12,13',
text: 'Monthly on every Saturday that are also the 7th – 13th',
textEn: 'Monthly on every Saturday that are also the 7th – 13th',
rrule: RecurrenceRule(
frequency: Frequency.monthly,
byWeekDays: [ByWeekDayEntry(DateTime.saturday)],
@@ -648,7 +648,7 @@ void main() {
// RRULE:FREQ=YEARLY;INTERVAL=4;BYMONTH=11;BYDAY=TU;BYMONTHDAY=2,3,4,5,6,7,8
string:
'RRULE:FREQ=YEARLY;INTERVAL=4;BYDAY=TU;BYMONTHDAY=2,3,4,5,6,7,8;BYMONTH=11',
text:
textEn:
'Every 4 years on every Tuesday that are also the 2nd – 8th day of the month and that are also in November',
rrule: RecurrenceRule(
frequency: Frequency.yearly,
@@ -836,7 +836,7 @@ void main() {
testRrule(
'An example where an invalid date (i.e., February 30) is ignored',
string: 'RRULE:FREQ=MONTHLY;COUNT=5;BYMONTHDAY=15,30',
text: 'Monthly on the 15th & 30th, 5 times',
textEn: 'Monthly on the 15th & 30th, 5 times',
rrule: RecurrenceRule(
frequency: Frequency.monthly,
count: 5,
26 changes: 22 additions & 4 deletions test/utils.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'package:meta/meta.dart';
import 'package:rrule/rrule.dart';
import 'package:rrule/src/codecs/text/encoder.dart';
import 'package:test/test.dart';

import 'codecs/text/utils.dart';
import 'codecs/utils.dart';
import 'iteration/utils.dart';

@@ -11,7 +11,7 @@ import 'iteration/utils.dart';
void testRrule(
String description, {
required String string,
required String? text,
required String? textEn,
required RecurrenceRule rrule,
required DateTime start,
required Iterable<DateTime> expected,
@@ -30,8 +30,8 @@ void testRrule(
testJsonCodec('JsonCodec', rrule);

// TODO(JonasWanke): Remove the condition when all properties are supported.
if (text != null) {
testText('TextCodec', text: text, string: string, l10n: l10n);
if (textEn != null) {
testTextEn('TextCodec', textEn: textEn, string: string, l10n: l10n);
}

testRecurring(
@@ -43,3 +43,21 @@ void testRrule(
);
});
}

@isTest
// ignore: avoid-top-level-members-in-tests
void testTextEn(
String description, {
required String textEn,
required String string,
required RruleL10n Function() l10n,
}) {
test(description, () async {
const stringCodec = RecurrenceRuleStringCodec();
final rrule = stringCodec.decode(string);

// TODO(JonasWanke): use codec directly when supporting fromText()
final textEncoder = RecurrenceRuleToTextEncoder(l10n());
expect(textEncoder.convert(rrule), textEn);
});
}

0 comments on commit 174918b

Please sign in to comment.