Skip to content

Commit 85f224e

Browse files
authored
test(copy): cover punctuation edges, escaping and link policy
Cover punctuation-only boundary lines, HTML escaping, allowed HTTPS destinations and unsupported local targets. All 160 focused Flutter tests and 60 infrastructure contract tests pass; full flutter analyze is clean.
1 parent 7976492 commit 85f224e

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

‎test/text_book/view/selection/selected_text_copy_test.dart‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,55 @@ void main() {
6262
);
6363
});
6464

65+
test(
66+
'preserves the link when the selection ends on visible punctuation',
67+
() {
68+
expect(
69+
resolveHtmlTextForSelection(
70+
plainText: 'first\n.',
71+
selectedIndex: 0,
72+
selectionLineStart: 0,
73+
selectionLineEnd: 1,
74+
sourceContent: const ['<a href="one">first</a>', '.'],
75+
),
76+
'<a href="one">first</a>\n.',
77+
);
78+
},
79+
);
80+
81+
test('escapes displayed punctuation and link attributes in rich HTML', () {
82+
expect(
83+
resolveHtmlTextForSelection(
84+
plainText: '<first> & last',
85+
selectedIndex: 0,
86+
selectionLineStart: 0,
87+
selectionLineEnd: 1,
88+
sourceContent: const [
89+
'<a href="https://example.org/?x=1&amp;y=2">&lt;first&gt;</a>',
90+
'&amp; last',
91+
],
92+
),
93+
'<a href="https://example.org/?x=1&amp;y=2">&lt;first&gt;</a> '
94+
'&amp; last',
95+
);
96+
});
97+
98+
test('keeps link text when the source destination is not allowed', () {
99+
expect(
100+
resolveHtmlTextForSelection(
101+
plainText: 'first\nlast',
102+
selectedIndex: 0,
103+
selectionLineStart: 0,
104+
selectionLineEnd: 1,
105+
sourceContent: const [
106+
'<a href="file:///fixtures/reference.txt">first</a>',
107+
'<a href="https://example.org/reference">last</a>',
108+
],
109+
),
110+
'<a>first</a>\n<a href="https://example.org/reference">last</a>',
111+
);
112+
});
113+
65114
test('ignores matches outside either end of the known source range', () {
66115
expect(
67116
resolveHtmlTextForSelection(

0 commit comments

Comments
 (0)