"use strict";

var jsdom = require("../..").jsdom;

// These tests are mostly random regression tests, not systematic parsing tests. They are compiled from the bug tracker.

exports["unclosed <td> (GH-605)"] = function (t) {
  var doc = jsdom("<table><tr><td>first td<td>second td</tr></table>");

  var tds = doc.getElementsByTagName("td");

  t.equal(tds.length, 2);
  t.equal(tds[0].innerHTML, 'first td');
  t.equal(tds[1].innerHTML, 'second td');

  t.done();
};

exports["multiline attributes (GH-585)"] = function (t) {
  var doc = jsdom("<a data-title='<strong>hello \nworld</strong>' href='example.org</strong>'>link</a>");

  var as = doc.getElementsByTagName("a");

  t.equal(as.length, 1);
  t.equal(as[0].innerHTML, "link");
  t.equal(as[0].getAttribute("data-title"), "<strong>hello \nworld</strong>");
  t.equal(as[0].getAttribute("href"), "example.org</strong>");

  t.done();
};

exports["innerHTML of <script type='text/html'> (GH-575)"] = function (t) {
  var doc = jsdom("<script type='text/html'>script innerHTML</script>");

  var scripts = doc.getElementsByTagName("script");

  t.equal(scripts.length, 1);
  t.equal(scripts[0].innerHTML, "script innerHTML");

  t.done();
};

exports["attributes containing '<' and '>' (GH-494)"] = function (t) {
  var doc = jsdom("<p title='<'>stuff</p><p title='>'>more</p><p>just testing</p>");

  var ps = doc.getElementsByTagName("p");

  t.equal(ps.length, 3);
  t.equal(ps[0].getAttribute("title"), "<");
  t.equal(ps[1].getAttribute("title"), ">");

  t.done();
};

@@ -1504,28 +1504,262 @@
 le%22), %22%3E%22);%0A%0A  t.done();%0A%7D;%0A
+%0Aexports%5B%22empty attributes (GH-488)%22%5D = function (t) %7B%0A  var doc = jsdom(%22%3Cdiv ng-app%3E%3C/div%3E%22);%0A%0A  var divs = doc.getElementsByTagName(%22div%22);%0A%0A  t.equal(divs.length, 1);%0A  t.equal(divs%5B0%5D.getAttribute(%22ng-app%22), %22%22);%0A%0A  t.done();%0A%7D;%0A

Add test for empty attributes. Fixes #488.