<commit_before>assert = chai.assert

$ = Rye

list_items = -> $('.list li')

makeElement = (tagName, html, attrs) ->
    el = document.createElement(tagName)
    el.innerHTML = html
    el[key] = value for key, value of attrs
    return el

suite 'Manipulation', ->

    test 'get html', ->
        assert.equal $('body').html(), document.getElementsByTagName('body')[0].innerHTML

    test 'set html', ->
        x = makeElement 'div'
        contents = '<p><b>X</b></p>'
        $(x).html(contents)
        assert.equal $(x).html(), contents

    test 'append', ->
        x = makeElement 'div', '<span>1</span>'
        contents = '<p>Hello</p>'
        $(x).append(contents)
        assert.lengthOf x.childNodes, 2
        assert.equal x.getElementsByTagName('p')[0].innerText, 'Hello'
        assert.equal x.getElementsByTagName('*')[1].tagName, 'P'

    test 'append element', ->
        el = makeElement 'p', 'test', { className: 'test-append-element' }
        $('#test').append(el)
        assert.lengthOf $('#test .test-append-element'), 1
        assert.equal $('#test .content').next().get(0), el
        assert.equal $('#test p').get(-1), el

    test 'prepend', ->
        x = makeElement 'div', '<span>2</span>'
        contents = '<p>Hello</p>'
        $(x).prepend(contents)
        assert.lengthOf x.childNodes, 2
        assert.equal x.getElementsByTagName('p')[0].innerText, 'Hello'
        assert.equal x.getElementsByTagName('*')[0].tagName, 'P'

    test 'prepend element', ->
        el = makeElement 'p', 'test', { className: 'test-prepend-element' }
        $('#test').prepend(el)
        assert.lengthOf $('#test .test-prepend-element'), 1
        assert.equal $('#test p').get(0), el

    test 'after', ->
        el = $('#hello')
        el.after('<div id="after"></div>')
        found = $('#after')
        assert.equal el.next().get(0), found.get(0)
        #found.remove() - not implemented

    test 'after with element', ->
        el = $('#hello')
        div = makeElement 'div', null, { id: 'after-element' }
        el.after(div)
        found = $('#after-element')
        assert.equal el.next().get(0), found.get(0)

    test 'before', -><commit_msg>Cover case where there is no next element<commit_after>assert = chai.assert

$ = Rye

list_items = -> $('.list li')

makeElement = (tagName, html, attrs) ->
    el = document.createElement(tagName)
    el.innerHTML = html
    el[key] = value for key, value of attrs
    return el

suite 'Manipulation', ->

    test 'get html', ->
        assert.equal $('body').html(), document.getElementsByTagName('body')[0].innerHTML

    test 'set html', ->
        x = makeElement 'div'
        contents = '<p><b>X</b></p>'
        $(x).html(contents)
        assert.equal $(x).html(), contents

    test 'append', ->
        x = makeElement 'div', '<span>1</span>'
        contents = '<p>Hello</p>'
        $(x).append(contents)
        assert.lengthOf x.childNodes, 2
        assert.equal x.getElementsByTagName('p')[0].innerText, 'Hello'
        assert.equal x.getElementsByTagName('*')[1].tagName, 'P'

    test 'append element', ->
        el = makeElement 'p', 'test', { className: 'test-append-element' }
        $('#test').append(el)
        assert.lengthOf $('#test .test-append-element'), 1
        assert.equal $('#test .content').next().get(0), el
        assert.equal $('#test p').get(-1), el

    test 'prepend', ->
        x = makeElement 'div', '<span>2</span>'
        contents = '<p>Hello</p>'
        $(x).prepend(contents)
        assert.lengthOf x.childNodes, 2
        assert.equal x.getElementsByTagName('p')[0].innerText, 'Hello'
        assert.equal x.getElementsByTagName('*')[0].tagName, 'P'

    test 'prepend element', ->
        el = makeElement 'p', 'test', { className: 'test-prepend-element' }
        $('#test').prepend(el)
        assert.lengthOf $('#test .test-prepend-element'), 1
        assert.equal $('#test p').get(0), el

    test 'after', ->
        el = $('#hello')
        el.after('<div id="after"></div>')
        found = $('#after')
        assert.equal el.next().get(0), found.get(0)
        #found.remove() - not implemented

    test 'after with element', ->
        el = $('#hello')
        div = makeElement 'div', null, { id: 'after-element' }
        el.after(div)
        found = $('#after-element')
        assert.equal el.next().get(0), found.get(0)

        el = $('.list .c')
        li = makeElement 'li', null, { id: 'after-element' }
        el.after(li)
        assert.equal el.next().get(0), li
        assert.equal $('.list li').last().get(0), li

    test 'before', ->
{'fraction_non_alphanumeric': 0.19414951245937162, 'fraction_numerical': 0.008234019501625136, 'mean_word_length': 2.4422073079791202, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 55, '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': '1856134', 'n_tokens_mistral': 1481, 'n_tokens_neox': 1454, 'n_words': 330}