@@ -18,116 +18,115 @@ void main() {
1818 ),
1919 );
2020 });
21+ testWidgets ('Test new parser (hacky workaround to get BuildContext)' , (WidgetTester tester) async {
22+ await tester.pumpWidget (
23+ Builder (
24+ builder: (BuildContext context) {
25+ testNewParser (context);
2126
22- testNewParser ();
27+ // The builder function must return a widget.
28+ return Placeholder ();
29+ },
30+ ),
31+ );
32+ });
2333}
2434
25- void testNewParser () {
26- test ("Html Parser works correctly" , () {
27- HtmlParser .parseHTML ("<b>Hello, World!</b>" );
28- });
35+ void testNewParser (BuildContext context) {
36+ HtmlParser .parseHTML ("<b>Hello, World!</b>" );
2937
30- test ("lexDomTree works correctly" , () {
31- StyledElement tree = HtmlParser .lexDomTree (
32- HtmlParser .parseHTML (
33- "Hello! <b>Hello, World!</b><i>Hello, New World!</i>" ),
34- [],
35- [],
36- null ,
37- );
38- print (tree.toString ());
39- });
38+ StyledElement tree = HtmlParser .lexDomTree (
39+ HtmlParser .parseHTML (
40+ "Hello! <b>Hello, World!</b><i>Hello, New World!</i>" ),
41+ [],
42+ [],
43+ null ,
44+ context,
45+ );
46+ print (tree.toString ());
4047
41- test ( "InteractableElements work correctly" , () {
42- StyledElement tree = HtmlParser .lexDomTree (
43- HtmlParser . parseHTML (
44- "Hello, World! <a href='https://example.com'>This is a link</a>" ) ,
45- [],
46- [] ,
47- null );
48- print (tree. toString () );
49- } );
48+ tree = HtmlParser . lexDomTree (
49+ HtmlParser .parseHTML (
50+ "Hello, World! <a href='https://example.com'>This is a link</a>" ),
51+ [] ,
52+ [],
53+ null ,
54+ context,
55+ );
56+ print (tree. toString () );
5057
51- test ("ContentElements work correctly" , () {
52- StyledElement tree = HtmlParser .lexDomTree (
53- HtmlParser .parseHTML ("<img src='https://image.example.com' />" ),
54- [],
55- [],
56- null ,
57- );
58- print (tree.toString ());
59- });
58+ tree = HtmlParser .lexDomTree (
59+ HtmlParser .parseHTML ("<img src='https://image.example.com' />" ),
60+ [],
61+ [],
62+ null ,
63+ context,
64+ );
65+ print (tree.toString ());
6066
61- test ("Nesting of elements works correctly" , () {
62- StyledElement tree = HtmlParser .lexDomTree (
63- HtmlParser .parseHTML (
64- "<div><div><div><div><a href='link'>Link</a><div>Hello, World! <b>Bold and <i>Italic</i></b></div></div></div></div></div>" ),
65- [],
66- [],
67- null ,
68- );
69- print (tree.toString ());
70- });
67+ tree = HtmlParser .lexDomTree (
68+ HtmlParser .parseHTML (
69+ "<div><div><div><div><a href='link'>Link</a><div>Hello, World! <b>Bold and <i>Italic</i></b></div></div></div></div></div>" ),
70+ [],
71+ [],
72+ null ,
73+ context,
74+ );
75+ print (tree.toString ());
7176
72- test ("Video Content Source Parser works correctly" , () {
73- ReplacedElement videoContentElement = parseReplacedElement (
74- HtmlParser .parseHTML ("""
77+ ReplacedElement videoContentElement = parseReplacedElement (
78+ HtmlParser .parseHTML ("""
7579 <video width="320" height="240" controls>
7680 <source src="movie.mp4" type="video/mp4">
7781 <source src="movie.ogg" type="video/ogg">
7882 Your browser does not support the video tag.
7983 </video>
8084 """ ).getElementsByTagName ("video" )[0 ],
81- null ,
82- );
85+ null ,
86+ );
8387
84- expect (videoContentElement, isA <VideoContentElement >());
85- if (videoContentElement is VideoContentElement ) {
86- expect (videoContentElement.showControls, equals (true ),
87- reason: "Controls isn't working" );
88- expect (videoContentElement.src, hasLength (2 ),
89- reason: "Not enough sources..." );
90- }
91- });
88+ expect (videoContentElement, isA <VideoContentElement >());
89+ if (videoContentElement is VideoContentElement ) {
90+ expect (videoContentElement.showControls, equals (true ),
91+ reason: "Controls isn't working" );
92+ expect (videoContentElement.src, hasLength (2 ),
93+ reason: "Not enough sources..." );
94+ }
9295
93- test ("Audio Content Source Parser works correctly" , () {
94- ReplacedElement audioContentElement = parseReplacedElement (
95- HtmlParser .parseHTML ("""
96+ ReplacedElement audioContentElement = parseReplacedElement (
97+ HtmlParser .parseHTML ("""
9698 <audio controls>
9799 <source src='audio.mp3' type='audio/mpeg'>
98100 <source src='audio.wav' type='audio/wav'>
99101 Your browser does not support the audio tag.
100102 </audio>
101103 """ ).getElementsByTagName ("audio" )[0 ],
102- null ,
103- );
104- expect (audioContentElement, isA <AudioContentElement >());
105- if (audioContentElement is AudioContentElement ) {
106- expect (audioContentElement.showControls, equals (true ),
107- reason: "Controls isn't working" );
108- expect (audioContentElement.src, hasLength (2 ),
109- reason: "Not enough sources..." );
110- }
111- });
104+ null ,
105+ );
106+ expect (audioContentElement, isA <AudioContentElement >());
107+ if (audioContentElement is AudioContentElement ) {
108+ expect (audioContentElement.showControls, equals (true ),
109+ reason: "Controls isn't working" );
110+ expect (audioContentElement.src, hasLength (2 ),
111+ reason: "Not enough sources..." );
112+ }
112113
113- test ("Test style merging" , () {
114- Style style1 = Style (
115- display: Display .BLOCK ,
116- fontWeight: FontWeight .bold,
117- );
114+ Style style1 = Style (
115+ display: Display .BLOCK ,
116+ fontWeight: FontWeight .bold,
117+ );
118118
119- Style style2 = Style (
120- before: "* " ,
121- direction: TextDirection .rtl,
122- fontStyle: FontStyle .italic,
123- );
119+ Style style2 = Style (
120+ before: "* " ,
121+ direction: TextDirection .rtl,
122+ fontStyle: FontStyle .italic,
123+ );
124124
125- Style finalStyle = style1.merge (style2);
125+ Style finalStyle = style1.merge (style2);
126126
127- expect (finalStyle.display, equals (Display .BLOCK ));
128- expect (finalStyle.before, equals ("* " ));
129- expect (finalStyle.direction, equals (TextDirection .rtl));
130- expect (finalStyle.fontStyle, equals (FontStyle .italic));
131- expect (finalStyle.fontWeight, equals (FontWeight .bold));
132- });
127+ expect (finalStyle.display, equals (Display .BLOCK ));
128+ expect (finalStyle.before, equals ("* " ));
129+ expect (finalStyle.direction, equals (TextDirection .rtl));
130+ expect (finalStyle.fontStyle, equals (FontStyle .italic));
131+ expect (finalStyle.fontWeight, equals (FontWeight .bold));
133132}
0 commit comments