<commit_before>require('../global-shim');

var test = require('tap').test;

//remove white space so it's easier to test
function clean(e) {
  return e.replace(/\n/g, '')
          .replace(/\s+/, ' ')
}

test('Element attributes', function(t){
  var div = document.createElement('div')
  t.equal(div.nodeName, 'div')
  t.equal(div.tagName, 'div')

  t.end()
})

test('assign textContent to an Element', function(t){
  var div = document.createElement('div')
  t.equal(clean(div.textContent), '')

  div.textContent = 'text 1'
  t.equal(clean(div.textContent), 'text 1')

  div.textContent = 'text 2'
  t.equal(clean(div.textContent), 'text 2')

  t.end()
})

test('create a Text node', function(t){
  var h1 = document.createElement('h1')
  t.equal(clean(h1.outerHTML), "<h1></h1>")
  t.equal(clean(h1.textContent), "")
  t.equal(clean(h1.innerHTML), "")

  h1.setAttribute('class', 'myclass');
  t.type(h1.toString(), "string", "type of h1 should be string")

  t.equal(clean(h1.outerHTML), '<h1 class="myclass"></h1>')
  t.equal(clean(h1.textContent), "")

  h1.appendChild(document.createTextNode('hello'))
<commit_msg>test for child-replacement behavior of textContent setter<commit_after>require('../global-shim');

var test = require('tap').test;

//remove white space so it's easier to test
function clean(e) {
  return e.replace(/\n/g, '')
          .replace(/\s+/, ' ')
}

test('Element attributes', function(t){
  var div = document.createElement('div')
  t.equal(div.nodeName, 'div')
  t.equal(div.tagName, 'div')

  t.end()
})

test('assign textContent to an Element', function(t){
  var div = document.createElement('div')
  t.equal(clean(div.textContent), '')

  // adds and replaces text
  div.textContent = 'text 1'
  t.equal(clean(div.textContent), 'text 1')
  div.textContent = 'text 2'
  t.equal(clean(div.textContent), 'text 2')

  // replaces existing children
  div = document.createElement('div')
  var p1 = document.createElement('p')
  var p2 = document.createElement('p')
  div.appendChild(p1)
  div.appendChild(p2)
  t.same(div.childNodes[0], p1)
  t.same(div.childNodes[1], p2)
  t.equal(clean(div.textContent), '')
  div.textContent = 'replacement'
  t.equal(clean(div.textContent), 'replacement')
  t.equal(div.childNodes.length, 1)
  t.notSame(div.childNodes[0], p1)

  t.end()
})

test('create a Text node', function(t){
  var h1 = document.createElement('h1')
  t.equal(clean(h1.outerHTML), "<h1></h1>")
  t.equal(clean(h1.textContent), "")
  t.equal(clean(h1.innerHTML), "")

  h1.setAttribute('class', 'myclass');
  t.type(h1.toString(), "string", "type of h1 should be string")

  t.equal(clean(h1.outerHTML), '<h1 class="myclass"></h1>')
  t.equal(clean(h1.textContent), "")

  h1.appendChild(document.createTextNode('hello'))

{'fraction_non_alphanumeric': 0.19464544138929088, 'fraction_numerical': 0.01772793053545586, 'mean_word_length': 4.400390625, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '4350713', 'n_tokens_mistral': 1018, 'n_tokens_neox': 992, 'n_words': 192}