File: objectconsistency.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 (64 lines) | stat: -rw-r--r-- 1,566 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
suite 'Creating XML:', ->
  test 'Object builder consistency', ->
    obj =
        ele: "simple element"
        person:
            name: "John"
            '@age': 35
            '?pi': 'mypi'
            '#comment': 'Good guy'
            '#cdata': 'well formed!'
            unescaped:
              '#raw': '&<>&'
            address:
                city: "Istanbul"
                street: "End of long and winding road"
            contact:
                phone: [
                    "555-1234"
                    "555-1235"
                ]
            id: () -> return 42
            details:
              '#text': 'classified'
            nullval: null
    
    t1 = xml('root', { headless: true }).ele(obj)

    t2 = xml('root', { headless: true })
        .ele('ele', 'simple element')
          .up()
        .ele('person')
          .ele('name', 'John')
            .up()
        .att('age', 35)
        .ins('pi', 'mypi')
        .com('Good guy')
        .dat('well formed!')
        .ele('unescaped')
          .raw('&<>&')
            .up()
        .ele('address')
          .ele('city', 'Istanbul')
            .up()
          .ele('street', 'End of long and winding road')
            .up()
          .up()
        .ele('contact')
          .ele('phone', '555-1234')
            .up()
          .ele('phone', '555-1235')
            .up()
          .up()
        .ele('id', 42)
          .up()
        .ele('details')
          .text('classified')
          .up()
        .ele('nullval', null)

    eq(
      t1.end()
      t2.end()
    )