diff --git a/lib/src/codecs/text/l10n/en.dart b/lib/src/codecs/text/l10n/en.dart index 68efa6d..5cb8de3 100644 --- a/lib/src/codecs/text/l10n/en.dart +++ b/lib/src/codecs/text/l10n/en.dart @@ -10,6 +10,8 @@ class RruleL10nEn extends RruleL10n { const RruleL10nEn._(); static Future create() async { + // TODO(JonasWanke): Move `initializeDateFormatting(…)` call to the + // library's user await initializeDateFormatting('en'); return const RruleL10nEn._(); } diff --git a/pubspec.yaml b/pubspec.yaml index efeda9a..39347a8 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -19,3 +19,5 @@ dev_dependencies: path: supernova ref: 6da7cfcf12aa2755ed9f7e1a59458c600ef3e1d0 test: ^1.16.8 + yaml: ^3.1.2 + yaml_edit: ^2.2.2 diff --git a/test/codecs/text/daily_test.dart b/test/codecs/text/daily_test.dart deleted file mode 100644 index 1c33868..0000000 --- a/test/codecs/text/daily_test.dart +++ /dev/null @@ -1,112 +0,0 @@ -// ignore_for_file: lines_longer_than_80_chars - -import 'package:meta/meta.dart'; -import 'package:rrule/rrule.dart'; -import 'package:test/test.dart'; - -import 'utils.dart' as utils; - -void main() { - late final RruleL10n l10n; - setUpAll(() async => l10n = await RruleL10nEn.create()); - - @isTest - void testText(String text, {required String string}) => - utils.testText(text, text: text, string: string, l10n: () => l10n); - - testText( - 'Daily on Monday', - string: 'RRULE:FREQ=DAILY;BYDAY=MO', - ); - testText( - 'Every other day on Monday', - string: 'RRULE:FREQ=DAILY;INTERVAL=2;BYDAY=MO', - ); - testText( - 'Every 4 days on Monday', - string: 'RRULE:FREQ=DAILY;INTERVAL=4;BYDAY=MO', - ); - - // 0/1 digits in the comment before a text function mean whether each of - // bySetPositions, byMonths, byMonthDays & byWeekDays (in that order) is - // included. - - // 0000 - testText( - 'Daily', - string: 'RRULE:FREQ=DAILY', - ); - // 0001 - testText( - 'Daily on Monday & Thursday', - string: 'RRULE:FREQ=DAILY;BYDAY=MO,TH', - ); - // 0010 - testText( - 'Daily on the 1st & last day of the month', - string: 'RRULE:FREQ=DAILY;BYMONTHDAY=1,-1', - ); - // 0011 - testText( - 'Daily on Monday & Thursday that are also the 1st or last day of the month', - string: 'RRULE:FREQ=DAILY;BYMONTHDAY=1,-1;BYDAY=MO,TH', - ); - // 0100 - testText( - 'Daily in January & December', - string: 'RRULE:FREQ=DAILY;BYMONTH=1,12', - ); - // 0101 - testText( - 'Daily in January & December on Monday & Thursday', - string: 'RRULE:FREQ=DAILY;BYMONTH=1,12;BYDAY=MO,TH', - ); - // 0110 - testText( - 'Daily in January & December on the 1st & last day of the month', - string: 'RRULE:FREQ=DAILY;BYMONTH=1,12;BYMONTHDAY=1,-1', - ); - // 0111 - testText( - 'Daily in January & December on Monday & Thursday that are also the 1st or last day of the month', - string: 'RRULE:FREQ=DAILY;BYMONTH=1,12;BYMONTHDAY=1,-1;BYDAY=MO,TH', - ); - - // 1000: invalid - // 1001 - testText( - 'Daily on the 1st & 2nd-to-last instance of Monday & Thursday', - string: 'RRULE:FREQ=DAILY;BYSETPOS=1,-2;BYDAY=MO,TH', - ); - // 1010 - testText( - 'Daily on the 1st & 2nd-to-last instance of the 1st & last day of the month', - string: 'RRULE:FREQ=DAILY;BYSETPOS=1,-2;BYMONTHDAY=1,-1', - ); - // 1011 - testText( - 'Daily on the 1st & 2nd-to-last instance of Monday & Thursday that are also the 1st or last day of the month', - string: 'RRULE:FREQ=DAILY;BYSETPOS=1,-2;BYMONTHDAY=1,-1;BYDAY=MO,TH', - ); - // 1100 - testText( - 'Daily in January & December on the 1st & 2nd-to-last instance', - string: 'RRULE:FREQ=DAILY;BYSETPOS=1,-2;BYMONTH=1,12', - ); - // 1101 - testText( - 'Daily in January & December on the 1st & 2nd-to-last instance of Monday & Thursday', - string: 'RRULE:FREQ=DAILY;BYSETPOS=1,-2;BYMONTH=1,12;BYDAY=MO,TH', - ); - // 1110 - testText( - 'Daily in January & December on the 1st & 2nd-to-last instance of the 1st & last day of the month', - string: 'RRULE:FREQ=DAILY;BYSETPOS=1,-2;BYMONTH=1,12;BYMONTHDAY=1,-1', - ); - // 1111 - testText( - 'Daily in January & December on the 1st & 2nd-to-last instance of Monday & Thursday that are also the 1st or last day of the month', - string: - 'RRULE:FREQ=DAILY;BYSETPOS=1,-2;BYMONTH=1,12;BYMONTHDAY=1,-1;BYDAY=MO,TH', - ); -} diff --git a/test/codecs/text/data.yaml b/test/codecs/text/data.yaml new file mode 100644 index 0000000..fc4eb8b --- /dev/null +++ b/test/codecs/text/data.yaml @@ -0,0 +1,408 @@ +RRULE:FREQ=WEEKLY;BYMONTH=1,2,3,8,9;BYDAY=MO,WE,TH,FR,SU: + en: "Weekly in January – March, August & September on Monday, Wednesday – Friday & Sunday" +RRULE:FREQ=WEEKLY;INTERVAL=2;BYMONTH=1,2,3;BYDAY=MO,TU,WE,TH,FR,SU: + en: Every other week in January – March on weekdays & Sunday +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: + en: "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" + +# Daily + +RRULE:FREQ=DAILY;BYDAY=MO: + en: Daily on Monday +RRULE:FREQ=DAILY;INTERVAL=2;BYDAY=MO: + en: Every other day on Monday +RRULE:FREQ=DAILY;INTERVAL=4;BYDAY=MO: + en: Every 4 days on Monday + +# 0/1 digits in the comment before a text function mean whether each of +# bySetPositions, byMonths, byMonthDays & byWeekDays (in that order) is +# included. + +# 0000 +RRULE:FREQ=DAILY: + en: Daily +# 0001 +RRULE:FREQ=DAILY;BYDAY=MO,TH: + en: Daily on Monday & Thursday +# 0010 +RRULE:FREQ=DAILY;BYMONTHDAY=1,-1: + en: Daily on the 1st & last day of the month +# 0011 +RRULE:FREQ=DAILY;BYMONTHDAY=1,-1;BYDAY=MO,TH: + en: Daily on Monday & Thursday that are also the 1st or last day of the month +# 0100 +RRULE:FREQ=DAILY;BYMONTH=1,12: + en: Daily in January & December +# 0101 +RRULE:FREQ=DAILY;BYMONTH=1,12;BYDAY=MO,TH: + en: Daily in January & December on Monday & Thursday +# 0110 +RRULE:FREQ=DAILY;BYMONTH=1,12;BYMONTHDAY=1,-1: + en: Daily in January & December on the 1st & last day of the month +# 0111 +RRULE:FREQ=DAILY;BYMONTH=1,12;BYMONTHDAY=1,-1;BYDAY=MO,TH: + en: Daily in January & December on Monday & Thursday that are also the 1st or last day of the month +# 1000: invalid +# 1001 +RRULE:FREQ=DAILY;BYSETPOS=1,-2;BYDAY=MO,TH: + en: Daily on the 1st & 2nd-to-last instance of Monday & Thursday +# 1010 +RRULE:FREQ=DAILY;BYSETPOS=1,-2;BYMONTHDAY=1,-1: + en: Daily on the 1st & 2nd-to-last instance of the 1st & last day of the month +# 1011 +RRULE:FREQ=DAILY;BYSETPOS=1,-2;BYMONTHDAY=1,-1;BYDAY=MO,TH: + en: Daily on the 1st & 2nd-to-last instance of Monday & Thursday that are also the 1st or last day of the month +# 1100 +RRULE:FREQ=DAILY;BYSETPOS=1,-2;BYMONTH=1,12: + en: Daily in January & December on the 1st & 2nd-to-last instance +# 1101 +RRULE:FREQ=DAILY;BYSETPOS=1,-2;BYMONTH=1,12;BYDAY=MO,TH: + en: Daily in January & December on the 1st & 2nd-to-last instance of Monday & Thursday +# 1110 +RRULE:FREQ=DAILY;BYSETPOS=1,-2;BYMONTH=1,12;BYMONTHDAY=1,-1: + en: Daily in January & December on the 1st & 2nd-to-last instance of the 1st & last day of the month +# 1111 +RRULE:FREQ=DAILY;BYSETPOS=1,-2;BYMONTH=1,12;BYMONTHDAY=1,-1;BYDAY=MO,TH: + en: Daily in January & December on the 1st & 2nd-to-last instance of Monday & Thursday that are also the 1st or last day of the month + +# Weekly + +RRULE:FREQ=WEEKLY;BYDAY=MO: + en: Weekly on Monday +RRULE:FREQ=WEEKLY;INTERVAL=2;BYDAY=MO: + en: Every other week on Monday +RRULE:FREQ=WEEKLY;INTERVAL=4;BYDAY=MO: + en: Every 4 weeks on Monday + +# 0/1 digits in the comment before a text function mean whether each of +# bySetPositions, byMonths & byWeekDays (in that order) is included. + +# 000 +RRULE:FREQ=WEEKLY: + en: Weekly +# 001 +RRULE:FREQ=WEEKLY;BYDAY=MO,TH: + en: Weekly on Monday & Thursday +# 010 +RRULE:FREQ=WEEKLY;BYMONTH=1,12: + en: Weekly in January & December +# 011 +RRULE:FREQ=WEEKLY;BYMONTH=1,12;BYDAY=MO,TH: + en: Weekly in January & December on Monday & Thursday +# 100: invalid +# 101 +RRULE:FREQ=WEEKLY;BYSETPOS=1,-2;BYDAY=MO,TH: + en: Weekly on the 1st & 2nd-to-last instance of Monday & Thursday +# 110 +RRULE:FREQ=WEEKLY;BYSETPOS=1,-2;BYMONTH=1,12: + en: Weekly in January & December on the 1st & 2nd-to-last instance +# 111 +RRULE:FREQ=WEEKLY;BYSETPOS=1,-2;BYMONTH=1,12;BYDAY=MO,TH: + en: Weekly in January & December on the 1st & 2nd-to-last instance of Monday & Thursday + +# Monthly + +RRULE:FREQ=MONTHLY;BYDAY=MO: + en: Monthly on every Monday +RRULE:FREQ=MONTHLY;INTERVAL=2;BYDAY=MO: + en: Every other month on every Monday +RRULE:FREQ=MONTHLY;INTERVAL=4;BYDAY=MO: + en: Every 4 months on every Monday + +# https://github.com/JonasWanke/rrule/issues/13 +RRULE:FREQ=MONTHLY;INTERVAL=1;BYSETPOS=-1;BYDAY=MO,TU,WE,TH,FR,SA,SU: + en: Monthly on the last day + +# 0/1 digits in the comment before a text function mean whether each of +# bySetPositions, byMonths, byMonthDays & byWeekDays (in that order) is +# included. + +# 0000 +RRULE:FREQ=MONTHLY: + en: Monthly +# 0001 +RRULE:FREQ=MONTHLY;BYDAY=MO,-1TH: + en: Monthly on every Monday & the last Thursday +# 0010 +RRULE:FREQ=MONTHLY;BYMONTHDAY=1,-1: + en: Monthly on the 1st & last day +# 0011 +RRULE:FREQ=MONTHLY;BYMONTHDAY=1,-1;BYDAY=MO,-1TH: + en: Monthly on every Monday & the last Thursday that are also the 1st or last day of the month +# 0100 +RRULE:FREQ=MONTHLY;BYMONTH=1,12: + en: Monthly in January & December +# 0101 +RRULE:FREQ=MONTHLY;BYMONTH=1,12;BYDAY=MO,-1TH: + en: Monthly in January & December on every Monday & the last Thursday +# 0110 +RRULE:FREQ=MONTHLY;BYMONTH=1,12;BYMONTHDAY=1,-1: + en: Monthly in January & December on the 1st & last day +# 0111 +RRULE:FREQ=MONTHLY;BYMONTH=1,12;BYMONTHDAY=1,-1;BYDAY=MO,-1TH: + en: Monthly in January & December on every Monday & the last Thursday that are also the 1st or last day of the month +# 1000: invalid +# 1001 +RRULE:FREQ=MONTHLY;BYSETPOS=1,-2;BYDAY=MO,-1TH: + en: Monthly on the 1st & 2nd-to-last instance of every Monday & the last Thursday +# 1010 +RRULE:FREQ=MONTHLY;BYSETPOS=1,-2;BYMONTHDAY=1,-1: + en: Monthly on the 1st & 2nd-to-last instance of the 1st & last day +# 1011 +RRULE:FREQ=MONTHLY;BYSETPOS=1,-2;BYMONTHDAY=1,-1;BYDAY=MO,-1TH: + en: Monthly on the 1st & 2nd-to-last instance of every Monday & the last Thursday that are also the 1st or last day of the month +# 1100 +RRULE:FREQ=MONTHLY;BYSETPOS=1,-2;BYMONTH=1,12: + en: Monthly in January & December on the 1st & 2nd-to-last instance +# 1101 +RRULE:FREQ=MONTHLY;BYSETPOS=1,-2;BYMONTH=1,12;BYDAY=MO,-1TH: + en: Monthly in January & December on the 1st & 2nd-to-last instance of every Monday & the last Thursday +# 1110 +RRULE:FREQ=MONTHLY;BYSETPOS=1,-2;BYMONTH=1,12;BYMONTHDAY=1,-1: + en: Monthly in January & December on the 1st & 2nd-to-last instance of the 1st & last day +# 1111 +RRULE:FREQ=MONTHLY;BYSETPOS=1,-2;BYMONTH=1,12;BYMONTHDAY=1,-1;BYDAY=MO,-1TH: + en: Monthly in January & December on the 1st & 2nd-to-last instance of every Monday & the last Thursday that are also the 1st or last day of the month + +# Yearly + +RRULE:FREQ=YEARLY;BYDAY=MO: + en: Annually on every Monday +RRULE:FREQ=YEARLY;INTERVAL=2;BYDAY=MO: + en: Every other year on every Monday +RRULE:FREQ=YEARLY;INTERVAL=4;BYDAY=MO: + en: Every 4 years on every Monday + +# 0/1 digits in the comment before a text function mean whether each of +# bySetPositions, byMonths, byWeeks, byYearDays, byMonthDays & byWeekDays +# (in that order) is included. + +# 000000 +RRULE:FREQ=YEARLY: + en: Annually +# 000001 +RRULE:FREQ=YEARLY;BYDAY=MO,-1TH: + en: Annually on every Monday & the last Thursday of the year +# 000010 +RRULE:FREQ=YEARLY;BYMONTHDAY=1,-1: + en: Annually on the 1st & last day of the month +# 000011 +RRULE:FREQ=YEARLY;BYMONTHDAY=1,-1;BYDAY=MO,-1TH: + en: Annually on every Monday & the last Thursday of the year that are also the 1st or last day of the month +# 000100 +RRULE:FREQ=YEARLY;BYYEARDAY=1,-1: + en: Annually on the 1st & last day of the year +# 000101 +RRULE:FREQ=YEARLY;BYYEARDAY=1,-1;BYDAY=MO,-1TH: + en: Annually on every Monday & the last Thursday of the year that are also the 1st or last day of the year +# 000110 +RRULE:FREQ=YEARLY;BYYEARDAY=1,-1;BYMONTHDAY=1,-1: + en: Annually on the 1st & last day of the month that are also the 1st or last day of the year +# 000111 +RRULE:FREQ=YEARLY;BYYEARDAY=1,-1;BYMONTHDAY=1,-1;BYDAY=MO,-1TH: + en: Annually on every Monday & the last Thursday of the year that are also the 1st or last day of the month and that are also the 1st or last day of the year +# 001000 +RRULE:FREQ=YEARLY;BYWEEKNO=1,-1: + en: Annually in the 1st & last week of the year +# 001001 +RRULE:FREQ=YEARLY;BYWEEKNO=1,-1;BYDAY=MO,WE: + en: Annually on every Monday & Wednesday in the 1st & last week of the year +# 001010 +RRULE:FREQ=YEARLY;BYWEEKNO=1,-1;BYMONTHDAY=1,-1: + en: Annually on the 1st & last day of the month that are also in the 1st or last week of the year +# 001011 +RRULE:FREQ=YEARLY;BYWEEKNO=1,-1;BYMONTHDAY=1,-1;BYDAY=MO,WE: + en: Annually on every Monday & Wednesday that are also the 1st or last day of the month and that are also in the 1st or last week of the year +# 001100 +RRULE:FREQ=YEARLY;BYWEEKNO=1,-1;BYYEARDAY=1,-1: + en: Annually on the 1st & last day of the year that are also in the 1st or last week of the year +# 001101 +RRULE:FREQ=YEARLY;BYWEEKNO=1,-1;BYYEARDAY=1,-1;BYDAY=MO,WE: + en: Annually on every Monday & Wednesday that are also the 1st or last day of the year and that are also in the 1st or last week of the year +# 001110 +RRULE:FREQ=YEARLY;BYWEEKNO=1,-1;BYYEARDAY=1,-1;BYMONTHDAY=1,-1: + en: Annually on the 1st & last day of the month that are also the 1st or last day of the year and that are also in the 1st or last week of the year +# 001111 +RRULE:FREQ=YEARLY;BYWEEKNO=1,-1;BYYEARDAY=1,-1;BYMONTHDAY=1,-1;BYDAY=MO,WE: + en: "Annually on every Monday & Wednesday that are also the 1st or last day of the month, that are also the 1st or last day of the year, and that are also in the 1st or last week of the year" +# 010000 +RRULE:FREQ=YEARLY;BYMONTH=1,12: + en: Annually in January & December +# 010001 +RRULE:FREQ=YEARLY;BYMONTH=1,12;BYDAY=MO,-1TH: + en: Annually on every Monday & the last Thursday of the month in January & December +# 010010 +RRULE:FREQ=YEARLY;BYMONTH=1,12;BYMONTHDAY=1,-1: + en: Annually on the 1st & last day of the month in January & December +# 010011 +# TODO(JonasWanke): the 1st or last day in January or December +RRULE:FREQ=YEARLY;BYMONTH=1,12;BYMONTHDAY=1,-1;BYDAY=MO,-1TH: + en: Annually on every Monday & the last Thursday of the year that are also the 1st or last day of the month and that are also in January or December +# 010100 +RRULE:FREQ=YEARLY;BYMONTH=1,12;BYYEARDAY=1,-1: + en: Annually on the 1st & last day of the year that are also in January or December +# 010101 +RRULE:FREQ=YEARLY;BYMONTH=1,12;BYYEARDAY=1,-1;BYDAY=MO,-1TH: + en: Annually on every Monday & the last Thursday of the year that are also the 1st or last day of the year and that are also in January or December +# 010110 +RRULE:FREQ=YEARLY;BYMONTH=1,12;BYYEARDAY=1,-1;BYMONTHDAY=1,-1: + en: Annually on the 1st & last day of the month that are also the 1st or last day of the year and that are also in January or December +# 010111 +RRULE:FREQ=YEARLY;BYMONTH=1,12;BYYEARDAY=1,-1;BYMONTHDAY=1,-1;BYDAY=MO,-1TH: + en: "Annually on every Monday & the last Thursday of the year that are also the 1st or last day of the month, that are also the 1st or last day of the year, and that are also in January or December" +# 011000 +RRULE:FREQ=YEARLY;BYMONTH=1,12;BYWEEKNO=1,-1: + en: Annually in the 1st & last week of the year that are also in January or December +# 011001 +RRULE:FREQ=YEARLY;BYMONTH=1,12;BYWEEKNO=1,-1;BYDAY=MO,WE: + en: Annually on every Monday & Wednesday in the 1st & last week of the year that are also in January or December +# 011010 +RRULE:FREQ=YEARLY;BYMONTH=1,12;BYWEEKNO=1,-1;BYMONTHDAY=1,-1: + en: Annually on the 1st & last day of the month that are also in the 1st or last week of the year and that are also in January or December +# 011011 +RRULE:FREQ=YEARLY;BYMONTH=1,12;BYWEEKNO=1,-1;BYMONTHDAY=1,-1;BYDAY=MO,WE: + en: "Annually on every Monday & Wednesday that are also the 1st or last day of the month, that are also in the 1st or last week of the year, and that are also in January or December" +# 011100 +RRULE:FREQ=YEARLY;BYMONTH=1,12;BYWEEKNO=1,-1;BYYEARDAY=1,-1: + en: Annually on the 1st & last day of the year that are also in the 1st or last week of the year and that are also in January or December +# 011101 +RRULE:FREQ=YEARLY;BYMONTH=1,12;BYWEEKNO=1,-1;BYYEARDAY=1,-1;BYDAY=MO,WE: + en: "Annually on every Monday & Wednesday that are also the 1st or last day of the year, that are also in the 1st or last week of the year, and that are also in January or December" +# 011110 +RRULE:FREQ=YEARLY;BYMONTH=1,12;BYWEEKNO=1,-1;BYYEARDAY=1,-1;BYMONTHDAY=1,-1: + en: "Annually on the 1st & last day of the month that are also the 1st or last day of the year, that are also in the 1st or last week of the year, and that are also in January or December" +# 011111 +RRULE:FREQ=YEARLY;BYMONTH=1,12;BYWEEKNO=1,-1;BYYEARDAY=1,-1;BYMONTHDAY=1,-1;BYDAY=MO,WE: + en: "Annually on every Monday & Wednesday that are also the 1st or last day of the month, that are also the 1st or last day of the year, that are also in the 1st or last week of the year, and that are also in January or December" +# 100000: invalid +# 100001 +RRULE:FREQ=YEARLY;BYSETPOS=1,-2;BYDAY=MO,-1TH: + en: Annually on the 1st & 2nd-to-last instance of every Monday & the last Thursday of the year +# 100010 +RRULE:FREQ=YEARLY;BYSETPOS=1,-2;BYMONTHDAY=1,-1: + en: Annually on the 1st & 2nd-to-last instance of the 1st & last day of the month +# 100011 +RRULE:FREQ=YEARLY;BYSETPOS=1,-2;BYMONTHDAY=1,-1;BYDAY=MO,-1TH: + en: Annually on the 1st & 2nd-to-last instance of every Monday & the last Thursday of the year that are also the 1st or last day of the month +# 100100 +RRULE:FREQ=YEARLY;BYSETPOS=1,-2;BYYEARDAY=1,-1: + en: Annually on the 1st & 2nd-to-last instance of the 1st & last day of the year +# 100101 +RRULE:FREQ=YEARLY;BYSETPOS=1,-2;BYYEARDAY=1,-1;BYDAY=MO,-1TH: + en: Annually on the 1st & 2nd-to-last instance of every Monday & the last Thursday of the year that are also the 1st or last day of the year +# 100110 +RRULE:FREQ=YEARLY;BYSETPOS=1,-2;BYYEARDAY=1,-1;BYMONTHDAY=1,-1: + en: Annually on the 1st & 2nd-to-last instance of the 1st & last day of the month that are also the 1st or last day of the year +# 100111 +RRULE:FREQ=YEARLY;BYSETPOS=1,-2;BYYEARDAY=1,-1;BYMONTHDAY=1,-1;BYDAY=MO,-1TH: + en: Annually on the 1st & 2nd-to-last instance of every Monday & the last Thursday of the year that are also the 1st or last day of the month and that are also the 1st or last day of the year +# 101000 +RRULE:FREQ=YEARLY;BYSETPOS=1,-2;BYWEEKNO=1,-1: + en: Annually on the 1st & 2nd-to-last instance of the 1st & last week of the year +# 101001 +RRULE:FREQ=YEARLY;BYSETPOS=1,-2;BYWEEKNO=1,-1;BYDAY=MO,WE: + en: Annually on the 1st & 2nd-to-last instance of every Monday & Wednesday in the 1st & last week of the year +# 101010 +RRULE:FREQ=YEARLY;BYSETPOS=1,-2;BYWEEKNO=1,-1;BYMONTHDAY=1,-1: + en: Annually on the 1st & 2nd-to-last instance of the 1st & last day of the month that are also in the 1st or last week of the year +# 101011 +RRULE:FREQ=YEARLY;BYSETPOS=1,-2;BYWEEKNO=1,-1;BYMONTHDAY=1,-1;BYDAY=MO,WE: + en: Annually on the 1st & 2nd-to-last instance of every Monday & Wednesday that are also the 1st or last day of the month and that are also in the 1st or last week of the year +# 101100 +RRULE:FREQ=YEARLY;BYSETPOS=1,-2;BYWEEKNO=1,-1;BYYEARDAY=1,-1: + en: Annually on the 1st & 2nd-to-last instance of the 1st & last day of the year that are also in the 1st or last week of the year +# 101101 +RRULE:FREQ=YEARLY;BYSETPOS=1,-2;BYWEEKNO=1,-1;BYYEARDAY=1,-1;BYDAY=MO,WE: + en: Annually on the 1st & 2nd-to-last instance of every Monday & Wednesday that are also the 1st or last day of the year and that are also in the 1st or last week of the year +# 101110 +RRULE:FREQ=YEARLY;BYSETPOS=1,-2;BYWEEKNO=1,-1;BYYEARDAY=1,-1;BYMONTHDAY=1,-1: + en: Annually on the 1st & 2nd-to-last instance of the 1st & last day of the month that are also the 1st or last day of the year and that are also in the 1st or last week of the year +# 101111 +RRULE:FREQ=YEARLY;BYSETPOS=1,-2;BYWEEKNO=1,-1;BYYEARDAY=1,-1;BYMONTHDAY=1,-1;BYDAY=MO,WE: + en: "Annually on the 1st & 2nd-to-last instance of every Monday & Wednesday that are also the 1st or last day of the month, that are also the 1st or last day of the year, and that are also in the 1st or last week of the year" +# 110000 +RRULE:FREQ=YEARLY;BYSETPOS=1,-2;BYMONTH=1,12: + en: Annually on the 1st & 2nd-to-last instance of January & December +# 110001 +RRULE:FREQ=YEARLY;BYSETPOS=1,-2;BYMONTH=1,12;BYDAY=MO,-1TH: + en: Annually on the 1st & 2nd-to-last instance of every Monday & the last Thursday of the month in January & December +# 110010 +RRULE:FREQ=YEARLY;BYSETPOS=1,-2;BYMONTH=1,12;BYMONTHDAY=1,-1: + en: Annually on the 1st & 2nd-to-last instance of the 1st & last day of the month in January & December +# 110011 +RRULE:FREQ=YEARLY;BYSETPOS=1,-2;BYMONTH=1,12;BYMONTHDAY=1,-1;BYDAY=MO,-1TH: + en: Annually on the 1st & 2nd-to-last instance of every Monday & the last Thursday of the year that are also the 1st or last day of the month and that are also in January or December +# 110100 +RRULE:FREQ=YEARLY;BYSETPOS=1,-2;BYMONTH=1,12;BYYEARDAY=1,-1: + en: Annually on the 1st & 2nd-to-last instance of the 1st & last day of the year that are also in January or December +# 110101 +RRULE:FREQ=YEARLY;BYSETPOS=1,-2;BYMONTH=1,12;BYYEARDAY=1,-1;BYDAY=MO,-1TH: + en: Annually on the 1st & 2nd-to-last instance of every Monday & the last Thursday of the year that are also the 1st or last day of the year and that are also in January or December +# 110110 +RRULE:FREQ=YEARLY;BYSETPOS=1,-2;BYMONTH=1,12;BYYEARDAY=1,-1;BYMONTHDAY=1,-1: + en: Annually on the 1st & 2nd-to-last instance of the 1st & last day of the month that are also the 1st or last day of the year and that are also in January or December +# 110111 +RRULE:FREQ=YEARLY;BYSETPOS=1,-2;BYMONTH=1,12;BYYEARDAY=1,-1;BYMONTHDAY=1,-1;BYDAY=MO,-1TH: + en: "Annually on the 1st & 2nd-to-last instance of every Monday & the last Thursday of the year that are also the 1st or last day of the month, that are also the 1st or last day of the year, and that are also in January or December" +# 111000 +RRULE:FREQ=YEARLY;BYSETPOS=1,-2;BYMONTH=1,12;BYWEEKNO=1,-1: + en: Annually on the 1st & 2nd-to-last instance of the 1st & last week of the year that are also in January or December +# 111001 +RRULE:FREQ=YEARLY;BYSETPOS=1,-2;BYMONTH=1,12;BYWEEKNO=1,-1;BYDAY=MO,WE: + en: Annually on the 1st & 2nd-to-last instance of every Monday & Wednesday in the 1st & last week of the year that are also in January or December +# 111010 +RRULE:FREQ=YEARLY;BYSETPOS=1,-2;BYMONTH=1,12;BYWEEKNO=1,-1;BYMONTHDAY=1,-1: + en: Annually on the 1st & 2nd-to-last instance of the 1st & last day of the month that are also in the 1st or last week of the year and that are also in January or December +# 111011 +RRULE:FREQ=YEARLY;BYSETPOS=1,-2;BYMONTH=1,12;BYWEEKNO=1,-1;BYMONTHDAY=1,-1;BYDAY=MO,WE: + en: "Annually on the 1st & 2nd-to-last instance of every Monday & Wednesday that are also the 1st or last day of the month, that are also in the 1st or last week of the year, and that are also in January or December" +# 111100 +RRULE:FREQ=YEARLY;BYSETPOS=1,-2;BYMONTH=1,12;BYWEEKNO=1,-1;BYYEARDAY=1,-1: + en: Annually on the 1st & 2nd-to-last instance of the 1st & last day of the year that are also in the 1st or last week of the year and that are also in January or December +# 111101 +RRULE:FREQ=YEARLY;BYSETPOS=1,-2;BYMONTH=1,12;BYWEEKNO=1,-1;BYYEARDAY=1,-1;BYDAY=MO,WE: + en: "Annually on the 1st & 2nd-to-last instance of every Monday & Wednesday that are also the 1st or last day of the year, that are also in the 1st or last week of the year, and that are also in January or December" +# 111110 +RRULE:FREQ=YEARLY;BYSETPOS=1,-2;BYMONTH=1,12;BYWEEKNO=1,-1;BYYEARDAY=1,-1;BYMONTHDAY=1,-1: + en: "Annually on the 1st & 2nd-to-last instance of the 1st & last day of the month that are also the 1st or last day of the year, that are also in the 1st or last week of the year, and that are also in January or December" +# 111111 +RRULE:FREQ=YEARLY;BYSETPOS=1,-2;BYMONTH=1,12;BYWEEKNO=1,-1;BYYEARDAY=1,-1;BYMONTHDAY=1,-1;BYDAY=MO,WE: + en: "Annually on the 1st & 2nd-to-last instance of every Monday & Wednesday that are also the 1st or last day of the month, that are also the 1st or last day of the year, that are also in the 1st or last week of the year, and that are also in January or December" + +# All remaining examples taken from https://github.com/jakubroztocil/rrule/blob/3dc698300e5861311249e85e0e237708702b055d/test/nlp.test.ts, +# though with modified texts. +RRULE:FREQ=HOURLY: + en: Hourly +RRULE:INTERVAL=4;FREQ=HOURLY: + en: Every 4 hours +RRULE:FREQ=WEEKLY;COUNT=20: + en: "Weekly, 20 times" +RRULE:FREQ=WEEKLY;UNTIL=20070101T080000Z: + en: "Weekly, until Monday, January 1, 2007 8:00:00 AM" +RRULE:FREQ=WEEKLY;BYDAY=TU: + en: Weekly on Tuesday +RRULE:FREQ=WEEKLY;BYDAY=MO,WE: + en: Weekly on Monday & Wednesday +RRULE:FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR: + en: Weekly on weekdays +RRULE:INTERVAL=2;FREQ=WEEKLY: + en: Every other week +RRULE:FREQ=MONTHLY;BYMONTHDAY=4: + en: Monthly on the 4th +RRULE:FREQ=MONTHLY;BYMONTHDAY=-4: + en: Monthly on the 4th-to-last day +RRULE:FREQ=MONTHLY;BYDAY=+3TU: + en: Monthly on the 3rd Tuesday +RRULE:FREQ=MONTHLY;BYDAY=-3TU: + en: Monthly on the 3rd-to-last Tuesday +RRULE:FREQ=MONTHLY;BYDAY=-1MO: + en: Monthly on the last Monday +RRULE:FREQ=MONTHLY;BYDAY=-2FR: + en: Monthly on the 2nd-to-last Friday +RRULE:INTERVAL=6;FREQ=MONTHLY: + en: Every 6 months +RRULE:FREQ=YEARLY;BYDAY=+1FR: + en: Annually on the 1st Friday of the year +RRULE:FREQ=YEARLY;BYDAY=+13FR: + en: Annually on the 13th Friday of the year + diff --git a/test/codecs/text/monthly_test.dart b/test/codecs/text/monthly_test.dart deleted file mode 100644 index 4cfdd70..0000000 --- a/test/codecs/text/monthly_test.dart +++ /dev/null @@ -1,119 +0,0 @@ -// ignore_for_file: lines_longer_than_80_chars - -import 'package:meta/meta.dart'; -import 'package:rrule/rrule.dart'; -import 'package:test/test.dart'; - -import 'utils.dart' as utils; - -void main() { - late final RruleL10n l10n; - setUpAll(() async => l10n = await RruleL10nEn.create()); - - @isTest - void testText(String text, {required String string}) => - utils.testText(text, text: text, string: string, l10n: () => l10n); - - testText( - 'Monthly on every Monday', - string: 'RRULE:FREQ=MONTHLY;BYDAY=MO', - ); - testText( - 'Every other month on every Monday', - string: 'RRULE:FREQ=MONTHLY;INTERVAL=2;BYDAY=MO', - ); - testText( - 'Every 4 months on every Monday', - string: 'RRULE:FREQ=MONTHLY;INTERVAL=4;BYDAY=MO', - ); - - // https://github.com/JonasWanke/rrule/issues/13 - testText( - 'Monthly on the last day', - string: - 'RRULE:FREQ=MONTHLY;INTERVAL=1;BYSETPOS=-1;BYDAY=MO,TU,WE,TH,FR,SA,SU', - ); - - // 0/1 digits in the comment before a text function mean whether each of - // bySetPositions, byMonths, byMonthDays & byWeekDays (in that order) is - // included. - - // 0000 - testText( - 'Monthly', - string: 'RRULE:FREQ=MONTHLY', - ); - // 0001 - testText( - 'Monthly on every Monday & the last Thursday', - string: 'RRULE:FREQ=MONTHLY;BYDAY=MO,-1TH', - ); - // 0010 - testText( - 'Monthly on the 1st & last day', - string: 'RRULE:FREQ=MONTHLY;BYMONTHDAY=1,-1', - ); - // 0011 - testText( - 'Monthly on every Monday & the last Thursday that are also the 1st or last day of the month', - string: 'RRULE:FREQ=MONTHLY;BYMONTHDAY=1,-1;BYDAY=MO,-1TH', - ); - // 0100 - testText( - 'Monthly in January & December', - string: 'RRULE:FREQ=MONTHLY;BYMONTH=1,12', - ); - // 0101 - testText( - 'Monthly in January & December on every Monday & the last Thursday', - string: 'RRULE:FREQ=MONTHLY;BYMONTH=1,12;BYDAY=MO,-1TH', - ); - // 0110 - testText( - 'Monthly in January & December on the 1st & last day', - string: 'RRULE:FREQ=MONTHLY;BYMONTH=1,12;BYMONTHDAY=1,-1', - ); - // 0111 - testText( - 'Monthly in January & December on every Monday & the last Thursday that are also the 1st or last day of the month', - string: 'RRULE:FREQ=MONTHLY;BYMONTH=1,12;BYMONTHDAY=1,-1;BYDAY=MO,-1TH', - ); - - // 1000: invalid - // 1001 - testText( - 'Monthly on the 1st & 2nd-to-last instance of every Monday & the last Thursday', - string: 'RRULE:FREQ=MONTHLY;BYSETPOS=1,-2;BYDAY=MO,-1TH', - ); - // 1010 - testText( - 'Monthly on the 1st & 2nd-to-last instance of the 1st & last day', - string: 'RRULE:FREQ=MONTHLY;BYSETPOS=1,-2;BYMONTHDAY=1,-1', - ); - // 1011 - testText( - 'Monthly on the 1st & 2nd-to-last instance of every Monday & the last Thursday that are also the 1st or last day of the month', - string: 'RRULE:FREQ=MONTHLY;BYSETPOS=1,-2;BYMONTHDAY=1,-1;BYDAY=MO,-1TH', - ); - // 1100 - testText( - 'Monthly in January & December on the 1st & 2nd-to-last instance', - string: 'RRULE:FREQ=MONTHLY;BYSETPOS=1,-2;BYMONTH=1,12', - ); - // 1101 - testText( - 'Monthly in January & December on the 1st & 2nd-to-last instance of every Monday & the last Thursday', - string: 'RRULE:FREQ=MONTHLY;BYSETPOS=1,-2;BYMONTH=1,12;BYDAY=MO,-1TH', - ); - // 1110 - testText( - 'Monthly in January & December on the 1st & 2nd-to-last instance of the 1st & last day', - string: 'RRULE:FREQ=MONTHLY;BYSETPOS=1,-2;BYMONTH=1,12;BYMONTHDAY=1,-1', - ); - // 1111 - testText( - 'Monthly in January & December on the 1st & 2nd-to-last instance of every Monday & the last Thursday that are also the 1st or last day of the month', - string: - 'RRULE:FREQ=MONTHLY;BYSETPOS=1,-2;BYMONTH=1,12;BYMONTHDAY=1,-1;BYDAY=MO,-1TH', - ); -} diff --git a/test/codecs/text/text_test.dart b/test/codecs/text/text_test.dart index 8bbb501..ab5067a 100644 --- a/test/codecs/text/text_test.dart +++ b/test/codecs/text/text_test.dart @@ -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 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) + .cast>() + .mapValues((it) => it.value.cast()); - 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> createL10n() async { + return { + 'en': await RruleL10nEn.create(), + }; } diff --git a/test/codecs/text/update_data.dart b/test/codecs/text/update_data.dart new file mode 100644 index 0000000..1767593 --- /dev/null +++ b/test/codecs/text/update_data.dart @@ -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 main() async { + final l10ns = await createL10n(); + + final dataEditor = YamlEditor(await dataFile.readAsString()); + final data = (dataEditor.parseAt([]) as YamlMap) + .cast>() + .mapValues((it) => it.value.cast()); + + 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()); +} diff --git a/test/codecs/text/utils.dart b/test/codecs/text/utils.dart deleted file mode 100644 index a6beb05..0000000 --- a/test/codecs/text/utils.dart +++ /dev/null @@ -1,22 +0,0 @@ -import 'package:meta/meta.dart'; -import 'package:rrule/rrule.dart'; -import 'package:rrule/src/codecs/text/encoder.dart'; -import 'package:test/test.dart'; - -@isTest -// ignore: avoid-top-level-members-in-tests -void testText( - String description, { - required String text, - 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), text); - }); -} diff --git a/test/codecs/text/weekly_test.dart b/test/codecs/text/weekly_test.dart deleted file mode 100644 index 6a1619d..0000000 --- a/test/codecs/text/weekly_test.dart +++ /dev/null @@ -1,69 +0,0 @@ -// ignore_for_file: lines_longer_than_80_chars - -import 'package:meta/meta.dart'; -import 'package:rrule/rrule.dart'; -import 'package:test/test.dart'; - -import 'utils.dart' as utils; - -void main() { - late final RruleL10n l10n; - setUpAll(() async => l10n = await RruleL10nEn.create()); - - @isTest - void testText(String text, {required String string}) => - utils.testText(text, text: text, string: string, l10n: () => l10n); - - testText( - 'Weekly on Monday', - string: 'RRULE:FREQ=WEEKLY;BYDAY=MO', - ); - testText( - 'Every other week on Monday', - string: 'RRULE:FREQ=WEEKLY;INTERVAL=2;BYDAY=MO', - ); - testText( - 'Every 4 weeks on Monday', - string: 'RRULE:FREQ=WEEKLY;INTERVAL=4;BYDAY=MO', - ); - - // 0/1 digits in the comment before a text function mean whether each of - // bySetPositions, byMonths & byWeekDays (in that order) is included. - - // 000 - testText( - 'Weekly', - string: 'RRULE:FREQ=WEEKLY', - ); - // 001 - testText( - 'Weekly on Monday & Thursday', - string: 'RRULE:FREQ=WEEKLY;BYDAY=MO,TH', - ); - // 010 - testText( - 'Weekly in January & December', - string: 'RRULE:FREQ=WEEKLY;BYMONTH=1,12', - ); - // 011 - testText( - 'Weekly in January & December on Monday & Thursday', - string: 'RRULE:FREQ=WEEKLY;BYMONTH=1,12;BYDAY=MO,TH', - ); - // 100: invalid - // 101 - testText( - 'Weekly on the 1st & 2nd-to-last instance of Monday & Thursday', - string: 'RRULE:FREQ=WEEKLY;BYSETPOS=1,-2;BYDAY=MO,TH', - ); - // 110 - testText( - 'Weekly in January & December on the 1st & 2nd-to-last instance', - string: 'RRULE:FREQ=WEEKLY;BYSETPOS=1,-2;BYMONTH=1,12', - ); - // 111 - testText( - 'Weekly in January & December on the 1st & 2nd-to-last instance of Monday & Thursday', - string: 'RRULE:FREQ=WEEKLY;BYSETPOS=1,-2;BYMONTH=1,12;BYDAY=MO,TH', - ); -} diff --git a/test/codecs/text/yearly_test.dart b/test/codecs/text/yearly_test.dart deleted file mode 100644 index b4a7a7a..0000000 --- a/test/codecs/text/yearly_test.dart +++ /dev/null @@ -1,380 +0,0 @@ -// ignore_for_file: lines_longer_than_80_chars - -import 'package:meta/meta.dart'; -import 'package:rrule/rrule.dart'; -import 'package:test/test.dart'; - -import 'utils.dart' as utils; - -void main() { - late final RruleL10n l10n; - setUpAll(() async => l10n = await RruleL10nEn.create()); - - @isTest - void testText(String text, {required String string}) => - utils.testText(text, text: text, string: string, l10n: () => l10n); - - testText( - 'Annually on every Monday', - string: 'RRULE:FREQ=YEARLY;BYDAY=MO', - ); - testText( - 'Every other year on every Monday', - string: 'RRULE:FREQ=YEARLY;INTERVAL=2;BYDAY=MO', - ); - testText( - 'Every 4 years on every Monday', - string: 'RRULE:FREQ=YEARLY;INTERVAL=4;BYDAY=MO', - ); - - // 0/1 digits in the comment before a text function mean whether each of - // bySetPositions, byMonths, byWeeks, byYearDays, byMonthDays & byWeekDays - // (in that order) is included. - - // 000000 - testText( - 'Annually', - string: 'RRULE:FREQ=YEARLY', - ); - // 000001 - testText( - 'Annually on every Monday & the last Thursday of the year', - string: 'RRULE:FREQ=YEARLY;BYDAY=MO,-1TH', - ); - // 000010 - testText( - 'Annually on the 1st & last day of the month', - string: 'RRULE:FREQ=YEARLY;BYMONTHDAY=1,-1', - ); - // 000011 - testText( - 'Annually on every Monday & the last Thursday of the year that are also the 1st or last day of the month', - string: 'RRULE:FREQ=YEARLY;BYMONTHDAY=1,-1;BYDAY=MO,-1TH', - ); - // 000100 - testText( - 'Annually on the 1st & last day of the year', - string: 'RRULE:FREQ=YEARLY;BYYEARDAY=1,-1', - ); - // 000101 - testText( - 'Annually on every Monday & the last Thursday of the year that are also the 1st or last day of the year', - string: 'RRULE:FREQ=YEARLY;BYYEARDAY=1,-1;BYDAY=MO,-1TH', - ); - // 000110 - testText( - 'Annually on the 1st & last day of the month that are also the 1st or last day of the year', - string: 'RRULE:FREQ=YEARLY;BYYEARDAY=1,-1;BYMONTHDAY=1,-1', - ); - // 000111 - testText( - 'Annually on every Monday & the last Thursday of the year that are also the 1st or last day of the month and that are also the 1st or last day of the year', - string: 'RRULE:FREQ=YEARLY;BYYEARDAY=1,-1;BYMONTHDAY=1,-1;BYDAY=MO,-1TH', - ); - - // 001000 - testText( - 'Annually in the 1st & last week of the year', - string: 'RRULE:FREQ=YEARLY;BYWEEKNO=1,-1', - ); - // 001001 - testText( - 'Annually on every Monday & Wednesday in the 1st & last week of the year', - string: 'RRULE:FREQ=YEARLY;BYWEEKNO=1,-1;BYDAY=MO,WE', - ); - // 001010 - testText( - 'Annually on the 1st & last day of the month that are also in the 1st or last week of the year', - string: 'RRULE:FREQ=YEARLY;BYWEEKNO=1,-1;BYMONTHDAY=1,-1', - ); - // 001011 - testText( - 'Annually on every Monday & Wednesday that are also the 1st or last day of the month and that are also in the 1st or last week of the year', - string: 'RRULE:FREQ=YEARLY;BYWEEKNO=1,-1;BYMONTHDAY=1,-1;BYDAY=MO,WE', - ); - // 001100 - testText( - 'Annually on the 1st & last day of the year that are also in the 1st or last week of the year', - string: 'RRULE:FREQ=YEARLY;BYWEEKNO=1,-1;BYYEARDAY=1,-1', - ); - // 001101 - testText( - 'Annually on every Monday & Wednesday that are also the 1st or last day of the year and that are also in the 1st or last week of the year', - string: 'RRULE:FREQ=YEARLY;BYWEEKNO=1,-1;BYYEARDAY=1,-1;BYDAY=MO,WE', - ); - // 001110 - testText( - 'Annually on the 1st & last day of the month that are also the 1st or last day of the year and that are also in the 1st or last week of the year', - string: 'RRULE:FREQ=YEARLY;BYWEEKNO=1,-1;BYYEARDAY=1,-1;BYMONTHDAY=1,-1', - ); - // 001111 - testText( - 'Annually on every Monday & Wednesday that are also the 1st or last day of the month, that are also the 1st or last day of the year, and that are also in the 1st or last week of the year', - string: - 'RRULE:FREQ=YEARLY;BYWEEKNO=1,-1;BYYEARDAY=1,-1;BYMONTHDAY=1,-1;BYDAY=MO,WE', - ); - - // 010000 - testText( - 'Annually in January & December', - string: 'RRULE:FREQ=YEARLY;BYMONTH=1,12', - ); - // 010001 - testText( - 'Annually on every Monday & the last Thursday of the month in January & December', - string: 'RRULE:FREQ=YEARLY;BYMONTH=1,12;BYDAY=MO,-1TH', - ); - // 010010 - testText( - 'Annually on the 1st & last day of the month in January & December', - string: 'RRULE:FREQ=YEARLY;BYMONTH=1,12;BYMONTHDAY=1,-1', - ); - // 010011 - // TODO(JonasWanke): the 1st or last day in January or December - testText( - 'Annually on every Monday & the last Thursday of the year that are also the 1st or last day of the month and that are also in January or December', - string: 'RRULE:FREQ=YEARLY;BYMONTH=1,12;BYMONTHDAY=1,-1;BYDAY=MO,-1TH', - ); - // 010100 - testText( - 'Annually on the 1st & last day of the year that are also in January or December', - string: 'RRULE:FREQ=YEARLY;BYMONTH=1,12;BYYEARDAY=1,-1', - ); - // 010101 - testText( - 'Annually on every Monday & the last Thursday of the year that are also the 1st or last day of the year and that are also in January or December', - string: 'RRULE:FREQ=YEARLY;BYMONTH=1,12;BYYEARDAY=1,-1;BYDAY=MO,-1TH', - ); - // 010110 - testText( - 'Annually on the 1st & last day of the month that are also the 1st or last day of the year and that are also in January or December', - string: 'RRULE:FREQ=YEARLY;BYMONTH=1,12;BYYEARDAY=1,-1;BYMONTHDAY=1,-1', - ); - // 010111 - testText( - 'Annually on every Monday & the last Thursday of the year that are also the 1st or last day of the month, that are also the 1st or last day of the year, and that are also in January or December', - string: - 'RRULE:FREQ=YEARLY;BYMONTH=1,12;BYYEARDAY=1,-1;BYMONTHDAY=1,-1;BYDAY=MO,-1TH', - ); - - // 011000 - testText( - 'Annually in the 1st & last week of the year that are also in January or December', - string: 'RRULE:FREQ=YEARLY;BYMONTH=1,12;BYWEEKNO=1,-1', - ); - // 011001 - testText( - 'Annually on every Monday & Wednesday in the 1st & last week of the year that are also in January or December', - string: 'RRULE:FREQ=YEARLY;BYMONTH=1,12;BYWEEKNO=1,-1;BYDAY=MO,WE', - ); - // 011010 - testText( - 'Annually on the 1st & last day of the month that are also in the 1st or last week of the year and that are also in January or December', - string: 'RRULE:FREQ=YEARLY;BYMONTH=1,12;BYWEEKNO=1,-1;BYMONTHDAY=1,-1', - ); - // 011011 - testText( - 'Annually on every Monday & Wednesday that are also the 1st or last day of the month, that are also in the 1st or last week of the year, and that are also in January or December', - string: - 'RRULE:FREQ=YEARLY;BYMONTH=1,12;BYWEEKNO=1,-1;BYMONTHDAY=1,-1;BYDAY=MO,WE', - ); - // 011100 - testText( - 'Annually on the 1st & last day of the year that are also in the 1st or last week of the year and that are also in January or December', - string: 'RRULE:FREQ=YEARLY;BYMONTH=1,12;BYWEEKNO=1,-1;BYYEARDAY=1,-1', - ); - // 011101 - testText( - 'Annually on every Monday & Wednesday that are also the 1st or last day of the year, that are also in the 1st or last week of the year, and that are also in January or December', - string: - 'RRULE:FREQ=YEARLY;BYMONTH=1,12;BYWEEKNO=1,-1;BYYEARDAY=1,-1;BYDAY=MO,WE', - ); - // 011110 - testText( - 'Annually on the 1st & last day of the month that are also the 1st or last day of the year, that are also in the 1st or last week of the year, and that are also in January or December', - string: - 'RRULE:FREQ=YEARLY;BYMONTH=1,12;BYWEEKNO=1,-1;BYYEARDAY=1,-1;BYMONTHDAY=1,-1', - ); - // 011111 - testText( - 'Annually on every Monday & Wednesday that are also the 1st or last day of the month, that are also the 1st or last day of the year, that are also in the 1st or last week of the year, and that are also in January or December', - string: - 'RRULE:FREQ=YEARLY;BYMONTH=1,12;BYWEEKNO=1,-1;BYYEARDAY=1,-1;BYMONTHDAY=1,-1;BYDAY=MO,WE', - ); - - // 100000: invalid - // 100001 - testText( - 'Annually on the 1st & 2nd-to-last instance of every Monday & the last Thursday of the year', - string: 'RRULE:FREQ=YEARLY;BYSETPOS=1,-2;BYDAY=MO,-1TH', - ); - // 100010 - testText( - 'Annually on the 1st & 2nd-to-last instance of the 1st & last day of the month', - string: 'RRULE:FREQ=YEARLY;BYSETPOS=1,-2;BYMONTHDAY=1,-1', - ); - // 100011 - testText( - 'Annually on the 1st & 2nd-to-last instance of every Monday & the last Thursday of the year that are also the 1st or last day of the month', - string: 'RRULE:FREQ=YEARLY;BYSETPOS=1,-2;BYMONTHDAY=1,-1;BYDAY=MO,-1TH', - ); - // 100100 - testText( - 'Annually on the 1st & 2nd-to-last instance of the 1st & last day of the year', - string: 'RRULE:FREQ=YEARLY;BYSETPOS=1,-2;BYYEARDAY=1,-1', - ); - // 100101 - testText( - 'Annually on the 1st & 2nd-to-last instance of every Monday & the last Thursday of the year that are also the 1st or last day of the year', - string: 'RRULE:FREQ=YEARLY;BYSETPOS=1,-2;BYYEARDAY=1,-1;BYDAY=MO,-1TH', - ); - // 100110 - testText( - 'Annually on the 1st & 2nd-to-last instance of the 1st & last day of the month that are also the 1st or last day of the year', - string: 'RRULE:FREQ=YEARLY;BYSETPOS=1,-2;BYYEARDAY=1,-1;BYMONTHDAY=1,-1', - ); - // 100111 - testText( - 'Annually on the 1st & 2nd-to-last instance of every Monday & the last Thursday of the year that are also the 1st or last day of the month and that are also the 1st or last day of the year', - string: - 'RRULE:FREQ=YEARLY;BYSETPOS=1,-2;BYYEARDAY=1,-1;BYMONTHDAY=1,-1;BYDAY=MO,-1TH', - ); - - // 101000 - testText( - 'Annually on the 1st & 2nd-to-last instance of the 1st & last week of the year', - string: 'RRULE:FREQ=YEARLY;BYSETPOS=1,-2;BYWEEKNO=1,-1', - ); - // 101001 - testText( - 'Annually on the 1st & 2nd-to-last instance of every Monday & Wednesday in the 1st & last week of the year', - string: 'RRULE:FREQ=YEARLY;BYSETPOS=1,-2;BYWEEKNO=1,-1;BYDAY=MO,WE', - ); - // 101010 - testText( - 'Annually on the 1st & 2nd-to-last instance of the 1st & last day of the month that are also in the 1st or last week of the year', - string: 'RRULE:FREQ=YEARLY;BYSETPOS=1,-2;BYWEEKNO=1,-1;BYMONTHDAY=1,-1', - ); - // 101011 - testText( - 'Annually on the 1st & 2nd-to-last instance of every Monday & Wednesday that are also the 1st or last day of the month and that are also in the 1st or last week of the year', - string: - 'RRULE:FREQ=YEARLY;BYSETPOS=1,-2;BYWEEKNO=1,-1;BYMONTHDAY=1,-1;BYDAY=MO,WE', - ); - // 101100 - testText( - 'Annually on the 1st & 2nd-to-last instance of the 1st & last day of the year that are also in the 1st or last week of the year', - string: 'RRULE:FREQ=YEARLY;BYSETPOS=1,-2;BYWEEKNO=1,-1;BYYEARDAY=1,-1', - ); - // 101101 - testText( - 'Annually on the 1st & 2nd-to-last instance of every Monday & Wednesday that are also the 1st or last day of the year and that are also in the 1st or last week of the year', - string: - 'RRULE:FREQ=YEARLY;BYSETPOS=1,-2;BYWEEKNO=1,-1;BYYEARDAY=1,-1;BYDAY=MO,WE', - ); - // 101110 - testText( - 'Annually on the 1st & 2nd-to-last instance of the 1st & last day of the month that are also the 1st or last day of the year and that are also in the 1st or last week of the year', - string: - 'RRULE:FREQ=YEARLY;BYSETPOS=1,-2;BYWEEKNO=1,-1;BYYEARDAY=1,-1;BYMONTHDAY=1,-1', - ); - // 101111 - testText( - 'Annually on the 1st & 2nd-to-last instance of every Monday & Wednesday that are also the 1st or last day of the month, that are also the 1st or last day of the year, and that are also in the 1st or last week of the year', - string: - 'RRULE:FREQ=YEARLY;BYSETPOS=1,-2;BYWEEKNO=1,-1;BYYEARDAY=1,-1;BYMONTHDAY=1,-1;BYDAY=MO,WE', - ); - - // 110000 - testText( - 'Annually on the 1st & 2nd-to-last instance of January & December', - string: 'RRULE:FREQ=YEARLY;BYSETPOS=1,-2;BYMONTH=1,12', - ); - // 110001 - testText( - 'Annually on the 1st & 2nd-to-last instance of every Monday & the last Thursday of the month in January & December', - string: 'RRULE:FREQ=YEARLY;BYSETPOS=1,-2;BYMONTH=1,12;BYDAY=MO,-1TH', - ); - // 110010 - testText( - 'Annually on the 1st & 2nd-to-last instance of the 1st & last day of the month in January & December', - string: 'RRULE:FREQ=YEARLY;BYSETPOS=1,-2;BYMONTH=1,12;BYMONTHDAY=1,-1', - ); - // 110011 - testText( - 'Annually on the 1st & 2nd-to-last instance of every Monday & the last Thursday of the year that are also the 1st or last day of the month and that are also in January or December', - string: - 'RRULE:FREQ=YEARLY;BYSETPOS=1,-2;BYMONTH=1,12;BYMONTHDAY=1,-1;BYDAY=MO,-1TH', - ); - // 110100 - testText( - 'Annually on the 1st & 2nd-to-last instance of the 1st & last day of the year that are also in January or December', - string: 'RRULE:FREQ=YEARLY;BYSETPOS=1,-2;BYMONTH=1,12;BYYEARDAY=1,-1', - ); - // 110101 - testText( - 'Annually on the 1st & 2nd-to-last instance of every Monday & the last Thursday of the year that are also the 1st or last day of the year and that are also in January or December', - string: - 'RRULE:FREQ=YEARLY;BYSETPOS=1,-2;BYMONTH=1,12;BYYEARDAY=1,-1;BYDAY=MO,-1TH', - ); - // 110110 - testText( - 'Annually on the 1st & 2nd-to-last instance of the 1st & last day of the month that are also the 1st or last day of the year and that are also in January or December', - string: - 'RRULE:FREQ=YEARLY;BYSETPOS=1,-2;BYMONTH=1,12;BYYEARDAY=1,-1;BYMONTHDAY=1,-1', - ); - // 110111 - testText( - 'Annually on the 1st & 2nd-to-last instance of every Monday & the last Thursday of the year that are also the 1st or last day of the month, that are also the 1st or last day of the year, and that are also in January or December', - string: - 'RRULE:FREQ=YEARLY;BYSETPOS=1,-2;BYMONTH=1,12;BYYEARDAY=1,-1;BYMONTHDAY=1,-1;BYDAY=MO,-1TH', - ); - - // 111000 - testText( - 'Annually on the 1st & 2nd-to-last instance of the 1st & last week of the year that are also in January or December', - string: 'RRULE:FREQ=YEARLY;BYSETPOS=1,-2;BYMONTH=1,12;BYWEEKNO=1,-1', - ); - // 111001 - testText( - 'Annually on the 1st & 2nd-to-last instance of every Monday & Wednesday in the 1st & last week of the year that are also in January or December', - string: - 'RRULE:FREQ=YEARLY;BYSETPOS=1,-2;BYMONTH=1,12;BYWEEKNO=1,-1;BYDAY=MO,WE', - ); - // 111010 - testText( - 'Annually on the 1st & 2nd-to-last instance of the 1st & last day of the month that are also in the 1st or last week of the year and that are also in January or December', - string: - 'RRULE:FREQ=YEARLY;BYSETPOS=1,-2;BYMONTH=1,12;BYWEEKNO=1,-1;BYMONTHDAY=1,-1', - ); - // 111011 - testText( - 'Annually on the 1st & 2nd-to-last instance of every Monday & Wednesday that are also the 1st or last day of the month, that are also in the 1st or last week of the year, and that are also in January or December', - string: - 'RRULE:FREQ=YEARLY;BYSETPOS=1,-2;BYMONTH=1,12;BYWEEKNO=1,-1;BYMONTHDAY=1,-1;BYDAY=MO,WE', - ); - // 111100 - testText( - 'Annually on the 1st & 2nd-to-last instance of the 1st & last day of the year that are also in the 1st or last week of the year and that are also in January or December', - string: - 'RRULE:FREQ=YEARLY;BYSETPOS=1,-2;BYMONTH=1,12;BYWEEKNO=1,-1;BYYEARDAY=1,-1', - ); - // 111101 - testText( - 'Annually on the 1st & 2nd-to-last instance of every Monday & Wednesday that are also the 1st or last day of the year, that are also in the 1st or last week of the year, and that are also in January or December', - string: - 'RRULE:FREQ=YEARLY;BYSETPOS=1,-2;BYMONTH=1,12;BYWEEKNO=1,-1;BYYEARDAY=1,-1;BYDAY=MO,WE', - ); - // 111110 - testText( - 'Annually on the 1st & 2nd-to-last instance of the 1st & last day of the month that are also the 1st or last day of the year, that are also in the 1st or last week of the year, and that are also in January or December', - string: - 'RRULE:FREQ=YEARLY;BYSETPOS=1,-2;BYMONTH=1,12;BYWEEKNO=1,-1;BYYEARDAY=1,-1;BYMONTHDAY=1,-1', - ); - // 111111 - testText( - 'Annually on the 1st & 2nd-to-last instance of every Monday & Wednesday that are also the 1st or last day of the month, that are also the 1st or last day of the year, that are also in the 1st or last week of the year, and that are also in January or December', - string: - 'RRULE:FREQ=YEARLY;BYSETPOS=1,-2;BYMONTH=1,12;BYWEEKNO=1,-1;BYYEARDAY=1,-1;BYMONTHDAY=1,-1;BYDAY=MO,WE', - ); -} diff --git a/test/recurrence_rule_test.dart b/test/recurrence_rule_test.dart index 5ec46ca..4294d32 100644 --- a/test/recurrence_rule_test.dart +++ b/test/recurrence_rule_test.dart @@ -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, ); diff --git a/test/rrule_ical_test.dart b/test/rrule_ical_test.dart index f1c4ce1..97647c0 100644 --- a/test/rrule_ical_test.dart +++ b/test/rrule_ical_test.dart @@ -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 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, diff --git a/test/utils.dart b/test/utils.dart index ebf90e5..e8c6faf 100644 --- a/test/utils.dart +++ b/test/utils.dart @@ -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 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); + }); +}