Skip to content

Commit 84a8fe0

Browse files
authored
[flutter_markdown] fix for latest pkg:markdown part 2 (#2797)
1 parent 4cb9b29 commit 84a8fe0

File tree

3 files changed

+53
-16
lines changed

3 files changed

+53
-16
lines changed

packages/flutter_markdown/test/link_test.dart

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'package:flutter/gestures.dart';
66
import 'package:flutter/widgets.dart';
77
import 'package:flutter_markdown/flutter_markdown.dart';
88
import 'package:flutter_test/flutter_test.dart';
9+
910
import 'utils.dart';
1011

1112
void main() => defineTests();
@@ -628,7 +629,13 @@ void defineTests() {
628629
);
629630

630631
expectValidLink('link');
631-
expectLinkTap(linkTapResults, const MarkdownLink('link', 'foo\bar'));
632+
if (!newMarkdown) {
633+
// For pkg:markdown <= v6.0.1
634+
expectLinkTap(linkTapResults, const MarkdownLink('link', 'foo\bar'));
635+
} else {
636+
// For pkg:markdown > v6.0.1
637+
expectLinkTap(linkTapResults, const MarkdownLink('link', 'foo%08ar'));
638+
}
632639
},
633640
);
634641

@@ -649,8 +656,15 @@ void defineTests() {
649656
);
650657

651658
expectValidLink('link');
652-
expectLinkTap(
653-
linkTapResults, const MarkdownLink('link', 'foo%20b&auml;'));
659+
if (!newMarkdown) {
660+
// For pkg:markdown <= v6.0.1
661+
expectLinkTap(
662+
linkTapResults, const MarkdownLink('link', 'foo%20b&auml;'));
663+
} else {
664+
// For pkg:markdown > v6.0.1
665+
expectLinkTap(
666+
linkTapResults, const MarkdownLink('link', 'foo%20b%C3%A4'));
667+
}
654668
},
655669
);
656670

@@ -759,8 +773,15 @@ void defineTests() {
759773
);
760774

761775
expectValidLink('link');
762-
expectLinkTap(linkTapResults,
763-
const MarkdownLink('link', '/url', 'title %22&quot;'));
776+
if (!newMarkdown) {
777+
// For pkg:markdown <= v6.0.1
778+
expectLinkTap(linkTapResults,
779+
const MarkdownLink('link', '/url', 'title %22&quot;'));
780+
} else {
781+
// For pkg:markdown > v6.0.1
782+
expectLinkTap(linkTapResults,
783+
const MarkdownLink('link', '/url', 'title &quot;&quot;'));
784+
}
764785
},
765786
);
766787

@@ -781,8 +802,15 @@ void defineTests() {
781802
);
782803

783804
expectValidLink('link');
784-
expectLinkTap(linkTapResults,
785-
const MarkdownLink('link', '/url\u{C2A0}%22title%22'));
805+
if (!newMarkdown) {
806+
// For pkg:markdown <= v6.0.1
807+
expectLinkTap(linkTapResults,
808+
const MarkdownLink('link', '/url\u{C2A0}%22title%22'));
809+
} else {
810+
// For pkg:markdown > v6.0.1
811+
expectLinkTap(linkTapResults,
812+
const MarkdownLink('link', '/url%EC%8A%A0%22title%22'));
813+
}
786814
},
787815
);
788816

@@ -825,8 +853,17 @@ void defineTests() {
825853
);
826854

827855
expectValidLink('link');
828-
expectLinkTap(linkTapResults,
829-
const MarkdownLink('link', '/url', 'title %22and%22 title'));
856+
if (!newMarkdown) {
857+
// For pkg:markdown <= v6.0.1
858+
expectLinkTap(linkTapResults,
859+
const MarkdownLink('link', '/url', 'title %22and%22 title'));
860+
} else {
861+
// For pkg:markdown > v6.0.1
862+
expectLinkTap(
863+
linkTapResults,
864+
const MarkdownLink('link', '/url', 'title &quot;and&quot; title'),
865+
);
866+
}
830867
},
831868
);
832869

packages/flutter_markdown/test/table_test.dart

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,9 @@
55
import 'package:flutter/material.dart';
66
import 'package:flutter_markdown/flutter_markdown.dart';
77
import 'package:flutter_test/flutter_test.dart';
8-
import 'package:markdown/markdown.dart' as md show version;
98

109
import 'utils.dart';
1110

12-
// TODO(kevmoo): delete this once the min version of pkg:markdown is updated
13-
final bool _newMarkdown = md.version.compareTo('6.0.1') > 0;
14-
1511
void main() => defineTests();
1612

1713
void defineTests() {
@@ -395,7 +391,7 @@ void defineTests() {
395391

396392
expectTableSize(3, 2);
397393

398-
if (!_newMarkdown) {
394+
if (!newMarkdown) {
399395
// For pkg:markdown <= v6.0.1
400396
expect(find.byType(RichText), findsNWidgets(6));
401397
final List<String?> text = find
@@ -464,7 +460,7 @@ void defineTests() {
464460
.toList();
465461
expect(text[0], '| abc | def | | --- | | bar |');
466462
},
467-
skip: !_newMarkdown,
463+
skip: !newMarkdown,
468464
);
469465

470466
testWidgets(
@@ -489,7 +485,7 @@ void defineTests() {
489485

490486
expectTableSize(3, 2);
491487

492-
if (!_newMarkdown) {
488+
if (!newMarkdown) {
493489
// For pkg:markdown <= v6.0.1
494490
expect(find.byType(RichText), findsNWidgets(5));
495491
final List<String?> cellText = find

packages/flutter_markdown/test/utils.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ import 'package:flutter/gestures.dart';
99
import 'package:flutter/material.dart';
1010
import 'package:flutter/services.dart';
1111
import 'package:flutter_test/flutter_test.dart';
12+
import 'package:markdown/markdown.dart' as md show version;
13+
14+
// TODO(Zhiguang): delete this once the min version of pkg:markdown is updated
15+
final bool newMarkdown = md.version.compareTo('6.0.1') > 0;
1216

1317
final TextTheme textTheme = Typography.material2018()
1418
.black

0 commit comments

Comments
 (0)