|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- import test from 'ava'
- import Window from 'window';
-
- import doctypeToString from '.'
-
- function makeStubDocument(doctype) {
- const window = new Window()
- const parser = new window.DOMParser()
- const doc = parser.parseFromString(
- `${doctype}<html></html>`,
- 'text/html'
- )
- return doc
- }
-
- test('should return empty string if absent', t => {
- const doctype = ''
- const doc = makeStubDocument()
- t.is(doctypeToString(doc.doctype), doctype)
- })
-
- test('should work for a HTML5-ish doctype', t => {
- const doctype = '<!DOCTYPE html>'
- const doc = makeStubDocument(doctype)
- t.is(doctypeToString(doc.doctype), doctype)
- })
-
- test('should work for a HTML4-ish doctype', t => {
- const doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">'
- const doc = makeStubDocument(doctype)
- t.is(doctypeToString(doc.doctype), doctype)
- })
-
- test('should work for a doctype without public id', t => {
- const doctype = '<!DOCTYPE html SYSTEM "http://www.w3.org/TR/html4/loose.dtd">'
- const doc = makeStubDocument(doctype)
- t.is(doctypeToString(doc.doctype), doctype)
- })
-
- // Cannot test, as modern parsers do not to support internal declarations.
- // test('should work for a doctype with internal declarations', t => {
- // const doctype = `<!DOCTYPE html SYSTEM "example.dtd" [
- // <!ENTITY foo "foo">
- // <!ENTITY bar "bar">
- // ]>`
- // const doc = makeStubDocument(doctype)
- // t.is(doctypeToString(doc.doctype), doctype)
- // })
|