<commit_before>package com.campudus.scycle.vdom

import com.campudus.scycle
import com.campudus.scycle.dom._
import com.campudus.scycle.vdom.VirtualDom.{Insertion, Path, Replacement}
import org.scalajs.dom
import org.scalatest.FunSpec

class VirtualDomTest extends FunSpec {

  describe("scalajs test setup") {
    it("can tell if two divs are the same") {
      val container = dom.document.createElement("div")
      val div = dom.document.createElement("div")
      container.appendChild(div)
      assert(container == container)
      assert(div == container.firstChild)
      assert(div == container.firstChild.asInstanceOf[dom.Element])
    }
  }

  describe("The virtual dom diffing algorithm") {

    describe("doing replacements") {
      it("detects the same element") {
        val myH1 = H1("hello")

        assert(VirtualDom.diff(myH1, myH1) === Nil)
      }

      it("replaces two different elements") {
        val myH1 = H1("hello")
        val mySpan = Span("bye")

        assert(VirtualDom.diff(myH1, mySpan) === List(Replacement(Path(), mySpan)))
      }

      it("replaces same element with different attributes") {
        val myH1a = H1("hello")
        val myH1b = H1("bye")

        assert(VirtualDom.diff(myH1a, myH1b) === List(Replacement(Path(), myH1b)))
      }

      it("only replaces a changed text if the tags above are the same") {<commit_msg>Add test for applying null value in VirtualDom<commit_after>package com.campudus.scycle.vdom

import com.campudus.scycle
import com.campudus.scycle.dom._
import com.campudus.scycle.vdom.VirtualDom.{Insertion, Path, Replacement}
import org.scalajs.dom
import org.scalatest.FunSpec

class VirtualDomTest extends FunSpec {

  describe("scalajs test setup") {
    it("can tell if two divs are the same") {
      val container = dom.document.createElement("div")
      val div = dom.document.createElement("div")
      container.appendChild(div)
      assert(container == container)
      assert(div == container.firstChild)
      assert(div == container.firstChild.asInstanceOf[dom.Element])
    }
  }

  describe("The virtual dom diffing algorithm") {

    it("can apply null values") {
      assert(VirtualDom(null) === null)
    }

    describe("doing replacements") {
      it("detects the same element") {
        val myH1 = H1("hello")

        assert(VirtualDom.diff(myH1, myH1) === Nil)
      }

      it("replaces two different elements") {
        val myH1 = H1("hello")
        val mySpan = Span("bye")

        assert(VirtualDom.diff(myH1, mySpan) === List(Replacement(Path(), mySpan)))
      }

      it("replaces same element with different attributes") {
        val myH1a = H1("hello")
        val myH1b = H1("bye")

        assert(VirtualDom.diff(myH1a, myH1b) === List(Replacement(Path(), myH1b)))
      }

      it("only replaces a changed text if the tags above are the same") {
{'fraction_non_alphanumeric': 0.12421711899791232, 'fraction_numerical': 0.009742519137091163, 'mean_word_length': 3.178779069767442, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3434185', 'n_tokens_mistral': 915, 'n_tokens_neox': 883, 'n_words': 215}