File: attributes.coffee

package info (click to toggle)
node-xml2js 0.4.23%2B~cs15.4.0%2Bdfsg-8
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,380 kB
  • sloc: xml: 117; javascript: 7; makefile: 2
file content (91 lines) | stat: -rw-r--r-- 2,628 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
suite 'Attributes:', ->
  test 'Add attribute (single with object argument)', ->
    eq(
      xml('test4', { headless: true })
        .ele('node', 'element', {"first":"1", "second":"2"})
          .att("third", "3")
        .end()
      '<test4><node first="1" second="2" third="3">element</node></test4>'
    )

  test 'Add attribute (multiple with object argument)', ->
    eq(
      xml('test4', { headless: true })
        .ele('node').att({"first":"1", "second":"2"})
        .end()
      '<test4><node first="1" second="2"/></test4>'
    )

  test 'Remove attribute', ->
    eq(
      xml('test4', { headless: true })
        .ele('node', 'element', {"first":"1", "second":"2", "third":"3"})
          .removeAttribute("second")
        .end()
      '<test4><node first="1" third="3">element</node></test4>'
    )

  test 'Remove multiple attributes', ->
    eq(
      xml('test4', { headless: true })
        .ele('node', 'element', {"first":"1", "second":"2", "third":"3"})
          .removeAttribute(["second", "third"])
        .end()
      '<test4><node first="1">element</node></test4>'
    )

  test 'Empty attribute', ->
    eq(
      xml('test', { headless: true })
        .ele('node', 'element', {"first":"", "second":"2", "third":""})
        .end()
      '<test><node first="" second="2" third="">element</node></test>'
    )

  test 'Skip if null attribute (ele)', ->
    eq(
      xml('test4', { headless: true })
        .ele('node', 'element', {"first": null, "second": '2'})
        .end()
      '<test4><node second="2">element</node></test4>'
    )

  test 'Skip if null attribute (att)', ->
    eq(
      xml('test4', { headless: true })
        .ele('node').att("first")
        .end()
      '<test4><node/></test4>'
    )

  test 'Skip if null attribute (JSON)', ->
    eq(
      xml('test4', { headless: true })
        .ele({'@first': null, '@second': '2'})
        .end()
      '<test4 second="2"/>'
    )

  test 'Keep null attribute (ele)', ->
    eq(
      xml('test4', { headless: true, keepNullAttributes: true })
        .ele('node', 'element', {"first": null, "second": '2'})
        .end()
      '<test4><node first="" second="2">element</node></test4>'
    )

  test 'Keep null attribute (att)', ->
    eq(
      xml('test4', { headless: true, keepNullAttributes: true })
        .ele('node').att("first")
        .end()
      '<test4><node first=""/></test4>'
    )

  test 'Keep null attribute (JSON)', ->
    eq(
      xml('test4', { headless: true, keepNullAttributes: true })
        .ele({'@first': null, '@second': '2'})
        .end()
      '<test4 first="" second="2"/>'
    )