File: clone.coffee

package info (click to toggle)
node-xml2js 0.4.23%2B~cs15.4.0%2Bdfsg-8
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 1,380 kB
  • sloc: xml: 117; javascript: 7; makefile: 2
file content (37 lines) | stat: -rw-r--r-- 1,093 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
xmloriginal = xml('test', { headless: true})
  .att('att', 'val')
  .ele('nodes')
    .ele('node', '1').up()
    .ele('node', '2')
      .att('att2', 'val2')
  .root()

xmlcloned = xmloriginal.root().clone()
xmlcloned.ele('added', '3')
newxml = xml('test2', { headless: true}).importDocument(xmlcloned)

suite 'Clone:', ->
  test 'Original should remain unchanged', ->
    eq(
      xmloriginal.end()
      '<test att="val"><nodes><node>1</node><node att2="val2">2</node></nodes></test>'
    )

  test 'Cloned should contain all nodes including added node', ->
    eq(
      newxml.end()
      '<test2><test att="val"><nodes><node>1</node><node att2="val2">2</node></nodes><added>3</added></test></test2>'
    )

  test 'Clone each node type', ->
    org = xml('test', { headless: true})
      .cdata('val1')
      .raw('val2')
      .ele('node')
        .ins('pi', 'target')
        .com('comment')
    eq(
      xml('test2', { headless: true}).importDocument(org.root().clone()).end()
      '<test2><test><![CDATA[val1]]>val2<node><?pi target?><!-- comment --></node></test></test2>'
    )