Skip to content

Commit

Permalink
Move test to main test file
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasWanke committed Sep 13, 2023
1 parent 677c198 commit 3c4d1f2
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 38 deletions.
45 changes: 45 additions & 0 deletions test/recurrence_rule_test.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import 'package:intl/date_symbol_data_local.dart';
import 'package:intl/intl.dart';
import 'package:rrule/rrule.dart';
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';

void main() {
late final RruleL10n l10n;
setUpAll(() async => l10n = await RruleL10nEn.create());

group('copyWith', () {
test('until can be adjusted', () {
expect(
Expand Down Expand Up @@ -204,4 +212,41 @@ void main() {
equals(start),
);
});
group(
'#59: It cannot parse its own strings when current locale does not use Latin numbers',
() {
setUp(() async {
Intl.defaultLocale = 'ar';
await initializeDateFormatting();
});

tearDown(() async {
Intl.defaultLocale = 'en';
await initializeDateFormatting();
});

final rrule = RecurrenceRule(
frequency: Frequency.daily,
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',
codec: const RecurrenceRuleStringCodec(
toStringOptions: RecurrenceRuleToStringOptions(isTimeUtc: true),
),
value: rrule,
string: string,
);

testText(
'TextCodec',
text: text,
string: string,
l10n: () => l10n,
);
},
);
}
21 changes: 0 additions & 21 deletions test/rrule_ical_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ void main() {
required DateTime start,
required Iterable<DateTime> expected,
bool isInfinite = false,
bool testNonLatin = false,
}) {
utils.testRrule(
description,
Expand All @@ -29,29 +28,9 @@ void main() {
expected: expected,
isInfinite: isInfinite,
l10n: () => l10n,
testNonLatin: testNonLatin,
);
}

// Non-latin tests
testRrule(
'Daily until December 24, 1997 - Non-Latin',
string: 'RRULE:FREQ=DAILY;UNTIL=19971224T000000Z',
text: 'Daily, until Wednesday, December 24, 1997 12:00:00 AM',
rrule: RecurrenceRule(
frequency: Frequency.daily,
until: DateTime.utc(1997, 12, 24),
),
start: DateTime.utc(1997, 9, 2, 9, 0, 0),
expected: [
...2.until(31).map((d) => DateTime.utc(1997, 9, d, 9, 0, 0)),
...1.until(32).map((d) => DateTime.utc(1997, 10, d, 9, 0, 0)),
...1.until(31).map((d) => DateTime.utc(1997, 11, d, 9, 0, 0)),
...1.until(24).map((d) => DateTime.utc(1997, 12, d, 9, 0, 0)),
],
testNonLatin: true,
);

// All examples taken from https://tools.ietf.org/html/rfc5545#section-3.8.5.3.
// - Some RRULE-strings had some fields reordered to match the production rule
// (recur-rule-part) order and remain consistent. The original string is
Expand Down
17 changes: 0 additions & 17 deletions test/utils.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import 'package:intl/date_symbol_data_local.dart';
import 'package:intl/intl.dart';
import 'package:meta/meta.dart';
import 'package:rrule/rrule.dart';
import 'package:test/test.dart';
Expand All @@ -19,23 +17,8 @@ void testRrule(
required Iterable<DateTime> expected,
bool isInfinite = false,
required RruleL10n Function() l10n,
bool testNonLatin = false,
}) {
group(description, () {
setUp(() async {
if (testNonLatin) {
Intl.defaultLocale = 'ar';
await initializeDateFormatting();
}
});

tearDown(() async {
if (testNonLatin) {
Intl.defaultLocale = 'en';
await initializeDateFormatting();
}
});

testStringCodec(
'StringCodec',
codec: const RecurrenceRuleStringCodec(
Expand Down

0 comments on commit 3c4d1f2

Please sign in to comment.