<commit_before>import utest.Assert;
import doom.Node;
import doom.Node.*;
import doom.Patch;

class TestNode extends TestBase {
  public function testDiff() {
    Assert.same([], (Empty : Node).diff(Empty));
    Assert.same([], (Text("a") : Node).diff(Text("a")));
    Assert.same([ContentChanged("b")], (Text("a") : Node).diff(Text("b")));
    Assert.same([ReplaceWithText("b")], (Empty : Node).diff(Text("b")));
    Assert.same([ReplaceWithComment("b")], (Empty : Node).diff(Comment("b")));
    Assert.same([Remove], (Text("a") : Node).diff(Empty));
  }

  public function testAttributeDiff() {
    var empty = new Map();
    Assert.same([], Node.diffAttributes(empty, empty));
    Assert.same([RemoveAttribute("a")], Node.diffAttributes(["a" => "b"], empty));
    Assert.same([SetAttribute("a", "b")], Node.diffAttributes(empty, ["a" => "b"]));
    Assert.same([], Node.diffAttributes(["a" => "b"], ["a" => "b"]));
    Assert.same([SetAttribute("a", "c")], Node.diffAttributes(["a" => "b"], ["a" => "c"]));
  }

  public function testEventDiff() {
    var empty = new Map(),
        hb = function(_) {},
        hc = function(_) {};
    Assert.same([], Node.diffEvents(empty, empty));
    Assert.same([RemoveEvent("a")], Node.diffEvents(["a" => hb], empty));
    Assert.same([SetEvent("a", hb)], Node.diffEvents(empty, ["a" => hb]));
    Assert.same([], Node.diffEvents(["a" => hb], ["a" => hb]));
    Assert.same([SetEvent("a", hc)], Node.diffEvents(["a" => hb], ["a" => hc]));
  }

  public function testChildrenDiff() {
    Assert.same([], el2.diff(el2));
    Assert.same([ReplaceWithElement("div", emptys, emptye, [el1])], el1.diff(el2));
    Assert.same([PatchChild(1, [AddElement("a", emptys, emptye, [])])], el2.diff(el3));
    Assert.same([PatchChild(1, [Remove])], el3.diff(el2));
  }<commit_msg>added test for issue<commit_after>import utest.Assert;
import doom.Node;
import doom.Node.*;
using doom.Patch;

class TestNode extends TestBase {
  public function testDiff() {
    Assert.same([], (Empty : Node).diff(Empty));
    Assert.same([], (Text("a") : Node).diff(Text("a")));
    Assert.same([ContentChanged("b")], (Text("a") : Node).diff(Text("b")));
    Assert.same([ReplaceWithText("b")], (Empty : Node).diff(Text("b")));
    Assert.same([ReplaceWithComment("b")], (Empty : Node).diff(Comment("b")));
    Assert.same([Remove], (Text("a") : Node).diff(Empty));
  }

  public function testAttributeDiff() {
    var empty = new Map();
    Assert.same([], Node.diffAttributes(empty, empty));
    Assert.same([RemoveAttribute("a")], Node.diffAttributes(["a" => "b"], empty));
    Assert.same([SetAttribute("a", "b")], Node.diffAttributes(empty, ["a" => "b"]));
    Assert.same([], Node.diffAttributes(["a" => "b"], ["a" => "b"]));
    Assert.same([SetAttribute("a", "c")], Node.diffAttributes(["a" => "b"], ["a" => "c"]));
  }

  public function testEventDiff() {
    var empty = new Map(),
        hb = function(_) {},
        hc = function(_) {};
    Assert.same([], Node.diffEvents(empty, empty));
    Assert.same([RemoveEvent("a")], Node.diffEvents(["a" => hb], empty));
    Assert.same([SetEvent("a", hb)], Node.diffEvents(empty, ["a" => hb]));
    Assert.same([], Node.diffEvents(["a" => hb], ["a" => hb]));
    Assert.same([SetEvent("a", hc)], Node.diffEvents(["a" => hb], ["a" => hc]));
  }

  public function testChildrenDiff() {
    Assert.same([], el2.diff(el2));
    Assert.same([ReplaceWithElement("div", emptys, emptye, [el1])], el1.diff(el2));
    Assert.same([AddElement("a", emptys, emptye, [])], el2.diff(el3));
    Assert.same([PatchChild(1, [Remove])], el3.diff(el2));
  }

  public function testIssue20151105() {
    var comments = [
            { author : "<NAME>", text : "This is one comment" },
            { author : "<NAME>", text : "This is *another* comment" }
          ],
        o = el("div", ["class" => "loading"], "Loading ..."),
        n = el("div",
              ["class" => "commentList"],
              comments.map(function(comment) return el("div",
                ["class" => "comment"],
                [el("h2",
                  ["class" => "comment"],
                  comment.author
                )],
                comment.text
              ))
            );
    var patches = o.diff(n);
    trace(patches.toPrettyString());
    Assert.same(
      [
        SetAttribute("class", "commentList"),
        AddElement("div", ["class" => "comment"], new Map(), [
          el("h2",
            ["class" => "comment"],
            "<NAME>"
          ),
          text("This is *another* comment")
        ]),
        PatchChild(0, [ReplaceWithElement("div", ["class" => "comment"], new Map(),
          [
            el("h2",
              ["class" => "comment"],
              "<NAME>"
            ),
            text("This is one comment")
          ]
        )])
      ],
      patches
    );
  }
{'fraction_non_alphanumeric': 0.23554824110265377, 'fraction_numerical': 0.0067887265994651304, 'mean_word_length': 3.1133671742808797, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 39, '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': '4898340', 'n_tokens_mistral': 1603, 'n_tokens_neox': 1572, 'n_words': 305}