Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(184)

Side by Side Diff: packages/html/test/parser_feature_test.dart

Issue 2990843002: Removed fixed dependencies (Closed)
Patch Set: Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « packages/html/test/dom_test.dart ('k') | packages/html/test/run_all.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /// Additional feature tests that aren't based on test data. 1 /// Additional feature tests that aren't based on test data.
2 library parser_feature_test; 2 library parser_feature_test;
3 3
4 import 'package:unittest/unittest.dart'; 4 import 'package:unittest/unittest.dart';
5 import 'package:html/dom.dart'; 5 import 'package:html/dom.dart';
6 import 'package:html/parser.dart'; 6 import 'package:html/parser.dart';
7 import 'package:html/src/constants.dart'; 7 import 'package:html/src/constants.dart';
8 import 'package:html/src/encoding_parser.dart'; 8 import 'package:html/src/encoding_parser.dart';
9 import 'package:html/src/treebuilder.dart'; 9 import 'package:html/src/treebuilder.dart';
10 import 'package:source_span/source_span.dart'; 10 import 'package:source_span/source_span.dart';
11 11
12 main() { 12 main() {
13 _testElementSpans(); 13 _testElementSpans();
14 test('doctype is cloneable', () { 14 test('doctype is cloneable', () {
15 var doc = parse('<!doctype HTML>'); 15 var doc = parse('<!doctype HTML>');
16 DocumentType doctype = doc.nodes[0]; 16 DocumentType doctype = doc.nodes[0];
17 expect(doctype.clone(false).toString(), '<!DOCTYPE html>'); 17 expect(doctype.clone(false).toString(), '<!DOCTYPE html>');
18 }); 18 });
19 19
20 test('line counter', () { 20 test('line counter', () {
21 // http://groups.google.com/group/html5lib-discuss/browse_frm/thread/f4f00e4 a2f26d5c0 21 // http://groups.google.com/group/html5lib-discuss/browse_frm/thread/f4f00e4 a2f26d5c0
22 var doc = parse("<pre>\nx\n&gt;\n</pre>"); 22 var doc = parse("<pre>\nx\n&gt;\n</pre>");
23 expect(doc.body.innerHtml, "<pre>x\n&gt;\n</pre>"); 23 expect(doc.body.innerHtml, "<pre>x\n&gt;\n</pre>");
24 }); 24 });
25 25
26 test('namespace html elements on', () { 26 test('namespace html elements on', () {
27 var doc = new HtmlParser('', tree: new TreeBuilder(true)).parse(); 27 var doc = new HtmlParser('', tree: new TreeBuilder(true)).parse();
28 expect(doc.nodes[0].namespaceUri, Namespaces.html); 28 expect((doc.nodes[0] as Element).namespaceUri, Namespaces.html);
29 }); 29 });
30 30
31 test('namespace html elements off', () { 31 test('namespace html elements off', () {
32 var doc = new HtmlParser('', tree: new TreeBuilder(false)).parse(); 32 var doc = new HtmlParser('', tree: new TreeBuilder(false)).parse();
33 expect(doc.nodes[0].namespaceUri, null); 33 expect((doc.nodes[0] as Element).namespaceUri, null);
34 }); 34 });
35 35
36 test('parse error spans - full', () { 36 test('parse error spans - full', () {
37 var parser = new HtmlParser(''' 37 var parser = new HtmlParser('''
38 <!DOCTYPE html> 38 <!DOCTYPE html>
39 <html> 39 <html>
40 <body> 40 <body>
41 <!DOCTYPE html> 41 <!DOCTYPE html>
42 </body> 42 </body>
43 </html> 43 </html>
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 var doc = parser.parse(); 244 var doc = parser.parse();
245 expect(doc.body.innerHtml, 'foo'); 245 expect(doc.body.innerHtml, 'foo');
246 expect(parser.errors.length, 1); 246 expect(parser.errors.length, 1);
247 expect(parser.errors[0].errorCode, 'expected-doctype-but-got-chars'); 247 expect(parser.errors[0].errorCode, 'expected-doctype-but-got-chars');
248 expect(parser.errors[0].message, 248 expect(parser.errors[0].message,
249 'Unexpected non-space characters. Expected DOCTYPE.'); 249 'Unexpected non-space characters. Expected DOCTYPE.');
250 expect(parser.errors[0].toString(), 250 expect(parser.errors[0].toString(),
251 'ParserError on line 1, column 4: Unexpected non-space characters. ' 251 'ParserError on line 1, column 4: Unexpected non-space characters. '
252 'Expected DOCTYPE.\n' 252 'Expected DOCTYPE.\n'
253 'foo\n' 253 'foo\n'
254 ' ^'); 254 ' ^');
255 }); 255 });
256 256
257 test('Element.text', () { 257 test('Element.text', () {
258 var doc = parseFragment('<div>foo<div>bar</div>baz</div>'); 258 var doc = parseFragment('<div>foo<div>bar</div>baz</div>');
259 var e = doc.firstChild; 259 var e = doc.firstChild;
260 var text = e.firstChild; 260 var text = e.firstChild;
261 expect((text as Text).data, 'foo'); 261 expect((text as Text).data, 'foo');
262 expect(e.text, 'foobarbaz'); 262 expect(e.text, 'foobarbaz');
263 263
264 e.text = 'FOO'; 264 e.text = 'FOO';
(...skipping 18 matching lines...) Expand all
283 283
284 test('Comment.text', () { 284 test('Comment.text', () {
285 var doc = parseFragment('<div><!--foo-->bar</div>'); 285 var doc = parseFragment('<div><!--foo-->bar</div>');
286 var e = doc.firstChild; 286 var e = doc.firstChild;
287 var c = e.firstChild; 287 var c = e.firstChild;
288 expect((c as Comment).data, 'foo'); 288 expect((c as Comment).data, 'foo');
289 expect(c.text, 'foo'); 289 expect(c.text, 'foo');
290 expect(e.text, 'bar'); 290 expect(e.text, 'bar');
291 291
292 c.text = 'qux'; 292 c.text = 'qux';
293 expect(c.data, 'qux'); 293 expect((c as Comment).data, 'qux');
294 expect(c.text, 'qux'); 294 expect(c.text, 'qux');
295 expect(e.text, 'bar'); 295 expect(e.text, 'bar');
296 }); 296 });
297 297
298 test('foreignObject end tag', () { 298 test('foreignObject end tag', () {
299 var p = new HtmlParser(''' 299 var p = new HtmlParser('''
300 <svg width="100%" height="100%" xmlns="http://www.w3.org/2000/svg" 300 <svg width="100%" height="100%" xmlns="http://www.w3.org/2000/svg"
301 version="1.1"> 301 version="1.1">
302 <foreignObject width="320px" height="200px"> 302 <foreignObject width="320px" height="200px">
303 <x-flow></x-flow> 303 <x-flow></x-flow>
304 </foreignObject> 304 </foreignObject>
305 </svg>'''); 305 </svg>''');
306 var doc = p.parseFragment(); 306 var doc = p.parseFragment();
307 expect(p.errors, isEmpty); 307 expect(p.errors, isEmpty);
308 var svg = doc.querySelector('svg'); 308 var svg = doc.querySelector('svg');
309 expect(svg.children[0].children[0].localName, 'x-flow'); 309 expect(svg.children[0].children[0].localName, 'x-flow');
310 }); 310 });
311 311
312 group('Encoding pre-parser', () { 312 group('Encoding pre-parser', () {
313 getEncoding(s) => new EncodingParser(s.codeUnits).getEncoding(); 313 getEncoding(String s) => new EncodingParser(s.codeUnits).getEncoding();
314 314
315 test('gets encoding from meta charset', () { 315 test('gets encoding from meta charset', () {
316 expect(getEncoding('<meta charset="utf-16">'), 'utf-16'); 316 expect(getEncoding('<meta charset="utf-16">'), 'utf-16');
317 }); 317 });
318 318
319 test('gets encoding from meta in head', () { 319 test('gets encoding from meta in head', () {
320 expect(getEncoding('<head><meta charset="utf-16">'), 'utf-16'); 320 expect(getEncoding('<head><meta charset="utf-16">'), 'utf-16');
321 }); 321 });
322 322
323 test('skips comments', () { 323 test('skips comments', () {
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 assertSpan(elem.sourceSpan, 8, 18, '<optgroup>'); 466 assertSpan(elem.sourceSpan, 8, 18, '<optgroup>');
467 assertSpan(elem.endSourceSpan, 38, 49, '</optgroup>'); 467 assertSpan(elem.endSourceSpan, 38, 49, '</optgroup>');
468 } 468 }
469 { 469 {
470 var elem = doc.querySelector('option'); 470 var elem = doc.querySelector('option');
471 assertSpan(elem.sourceSpan, 18, 26, '<option>'); 471 assertSpan(elem.sourceSpan, 18, 26, '<option>');
472 assertSpan(elem.endSourceSpan, 29, 38, '</option>'); 472 assertSpan(elem.endSourceSpan, 29, 38, '</option>');
473 } 473 }
474 }); 474 });
475 }); 475 });
476 } 476 }
OLDNEW
« no previous file with comments | « packages/html/test/dom_test.dart ('k') | packages/html/test/run_all.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698