/*jslint node: true */
"use strict";
var assert = require('assert')
, _ = require('underscore')
, xml = require('../index.js')
, testParents = require('./testParents')
;

describe('setNode', function () {
    
    it('should add a new element to a childless parent', function () {
        var parent = xml.elt('mama');
        var child = xml.elt('baby');
        xml.setNode(parent, child);
        assert.equal(parent.children.length, 1);
        assert.equal(parent.children[0].name, 'baby');
        assert.equal(parent.hash.baby.length, 1);
        testParents(parent);
    });

    it('should replace an existing node', function () {
        var parent = xml.elt('mama');
        var alice = xml.elt('baby', [xml.text('alice')]);
        xml.setNode(parent, alice);
        var betty = xml.elt('baby', [xml.text('betty')]);
        xml.setNode(parent, betty);
        assert.equal(parent.hash.baby.length, 1);
        assert.equal(xml.value(parent.hash.baby[0]), 'betty');
        testParents(parent);
    });

    it('should parse a string second argument', function () {
        var parent = xml.elt('mama');
        xml.setNode(parent, '<baby>betty</baby>');
        assert(parent.hash.baby);
        assert.equal(parent.hash.baby.length, 1);
        assert.equal(xml.value(parent.hash.baby[0]), 'betty');
        testParents(parent);
    });


});

@@ -202,13 +202,9 @@
 ) %7B%0A
-    
 %0A
+
     
@@ -1342,13 +1342,1196 @@
    %7D);%0A%0A
+%7D);%0A%0A%0Adescribe('nodeSet', function () %7B%0A%0A    it('should add a new element to a childless parent', function () %7B%0A        var parent = xml.elt('mama');%0A        var child = xml.elt('baby');%0A        xml.nodeSet(parent, child);%0A        assert.equal(parent.children.length, 1);%0A        assert.equal(parent.children%5B0%5D.name, 'baby');%0A        assert.equal(parent.hash.baby.length, 1);%0A        testParents(parent);%0A    %7D);%0A%0A    it('should replace an existing node', function () %7B%0A        var parent = xml.elt('mama');%0A        var alice = xml.elt('baby', %5Bxml.text('alice')%5D);%0A        xml.nodeSet(parent, alice);%0A        var betty = xml.elt('baby', %5Bxml.text('betty')%5D);%0A        xml.nodeSet(parent, betty);%0A        assert.equal(parent.hash.baby.length, 1);%0A        assert.equal(xml.value(parent.hash.baby%5B0%5D), 'betty');%0A        testParents(parent);%0A    %7D);%0A%0A    it('should parse a string second argument', function () %7B%0A        var parent = xml.elt('mama');%0A        xml.nodeSet(parent, '%3Cbaby%3Ebetty%3C/baby%3E');%0A        assert(parent.hash.baby);%0A        assert.equal(parent.hash.baby.length, 1);%0A        assert.equal(xml.value(parent.hash.baby%5B0%5D), 'betty');%0A        testParents(parent);%0A    %7D);%0A
 %0A%7D);%0A

Add test to allow setNode or nodeSet.