<commit_before>import "6to5/polyfill";

import test from "tape-catch";

import m from "mithril";
import n from "../source/n";


var flush = function flush (target) {
  var childNode;
  while ((childNode = target.lastChild)) {
    target.removeChild(childNode);
    }
  };


test("Doesn't break Mithril", function (is) {
  var noop = function () {};

  is.deepEqual
    ( m("div", {an: "attribute", onclick: noop})
    , n("div", {an: "attribute", onclick: noop})
    , "Does the same as Mithril with a vnode,"
    );

  is.deepEqual
    ( m("div", {an: "attribute", onclick: noop}, m("a"), [m(".b"), m("#c")])
    , n("div", {an: "attribute", onclick: noop}, m("a"), [m(".b"), m("#c")])
    , "even when the vnode has children."
    );

  var changed = false;
  m.render(document.body, n
    ( ".something"
    , {config: function () { changed = true; }}
    ));
  is.true
    ( changed
    , "Doesn't break an existing config attribute,"
    );

  var changedAgain = false;
  m.render(document.body, n
    ( ".somethingElse"
    , {config: function () { changedAgain = true; }}
    , document.createElement("div")
    ));
  is.true
    ( changedAgain
    , "even when rendering a node."
    );

  flush(document.body);
  is.end();
  });


test("Renders a real child node", function (is) {
  var grandpa, son, daughter;
  var pa = document.createElement("div");
  pa.setAttribute("some-attr", "and its value");
  pa.appendChild(son = document.createElement("span"));
  pa.appendChild(daughter = document.createTextNode("I'm the daughter"));

  m.render
    ( document.body
    , n
      ( "article"
      , {config: function (element) {
        grandpa = element;
        }}
      , pa
      )
    );

  is.equal
    ( pa.parentNode, grandpa
    , "Renders a child node"
    );

  is.equal
    ( pa.getAttribute("some-attr"), "and its value"
    , "keeping attributes"
    );

  is.true
    (  pa.firstChild == son
    && son.nextSibling == daughter
    , "and the node's subtree."
    );

  flush(document.body);
  is.end();
});


test.skip("Renders a bunch of real nodes", function (is) {
  is.pass("Renders a bunch of child nodes mixed with virtual nodes");
  is.pass("in the correct order");
  is.pass("without breaking references");
  is.pass("and persists them across redraws.");
  is.pass("Even when called more than once in a single view.");
  is.end();
  });


test.skip("Updates real nodes", function (is) {
  is.pass("Reacts to updates on the parent vnode,");
  is.pass("or on virtual children,");
  is.pass("still keeping node references.");
  is.end();
  });<commit_msg>More test cases<commit_after>import "6to5/polyfill";

import test from "tape-catch";

import m from "mithril";
import n from "../source/n";


// Prepare a DOM container for tests
var testContainer = document.createElement("div");
document.body.appendChild(testContainer);

function flush (target) {
  var childNode;
  while ((childNode = target.lastChild)) {
    target.removeChild(childNode);
    }
  }


test("Does the same as Mithril", (is) => {
  var noop = () => {};

  is.deepEqual
    ( m("div", {an: "attribute", onclick: noop})
    , n("div", {an: "attribute", onclick: noop})
    , "with a single vnode"
    );

  is.deepEqual
    ( m("div", {an: "attribute", onclick: noop}, m("a"), [m(".b"), m("#c")])
    , n("div", {an: "attribute", onclick: noop}, m("a"), [m(".b"), m("#c")])
    , "even when the vnode has children"
    );

  m.render(testContainer, n
    ( ".something"
    , {config: () => {
      is.pass("keeping an existing config attribute when tha vnode has no children");
      }}
    ));

  m.render(testContainer, n
    ( ".somethingElse"
    , {config: () => {
      is.pass("as well as when it does have vchildren and child nodes");
      }}
    , document.createElement("div")
    , m(".another-child")
    ));

  flush(testContainer);
  is.end();
  });


test("Renders a real child node", (is) => {
  var grandpa, daughter, pa, son;

  (pa = document.createElement("div"))
    .setAttribute("some-attr", "some value")
    ;
  pa.appendChild(
    (son = document.createElement("span"))
    );
  pa.appendChild(
    (daughter = document.createTextNode("me is the daughter"))
    );

  m.render
    ( testContainer
    , n("article"
      , {config: (element) => {
        grandpa = element;
        }}
      , pa
      )
    );

  is.equal
    ( pa && pa.parentNode
    , grandpa
    , "in the parent vnode"
    );

  is.equal
    ( pa.getAttribute("some-attr")
    , "some value"
    , "keeping attributes and their values"
    );

  is.ok
    (  pa.firstChild == son
    && son.nextSibling == daughter
    ,  "and the node's subtree"
    );

  flush(testContainer);
  is.end();
});


test("Renders a bunch of real nodes", (is) => {
  var aunt, grandpa;
  var [ma, pa, uncle] = Array(3).fill(null).map(
    () => document.createElement("div")
    );

  m.render(testContainer
    , n(".grandpa"
      , {config: (element) => {grandpa = element;}}
      , ma
      , m(".aunt", {config: (element) => {aunt = element;}})
      , uncle
      , pa
      )
    );

  is.equal
    ( grandpa && grandpa.parentNode
    , testContainer
    , "just where told to render"
    );

  is.ok
    ( [ma, pa, uncle].every((element) =>
      element && element.parentNode == grandpa
      )
    , "in the parent node"
    );

  is.equal
    ( aunt && aunt.parentNode
    , grandpa
    , "alongside virtual nodes"
    );

  is.true
    ( [ma, aunt, uncle, pa].every((element, index, elements) =>
      (  index === 0
      || element.previousSibling == elements[index - 1]
      ))
    , "in the correct order"
    );

  is.skip("without breaking references");
  is.skip("persistently across redraws");
  is.skip("even when changing the order");
  is.skip("and keeping references to keyed vnodes");
  is.skip("even when called more than once in a single view");

  flush(testContainer);
  is.end();
  });


test("Updates real nodes", (is) => {
  is.skip("Reacts to updates on the parent vnode,");
  is.skip("or on virtual children,");
  is.skip("still keeping node references.");
  is.end();
  });
{'fraction_non_alphanumeric': 0.17274220032840723, 'fraction_numerical': 0.0011494252873563218, 'mean_word_length': 2.7879353233830844, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1721491', 'n_tokens_mistral': 2040, 'n_tokens_neox': 1992, 'n_words': 532}