File: xml_test.liq

package info (click to toggle)
liquidsoap 2.4.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 12,844 kB
  • sloc: ml: 74,136; javascript: 27,320; ansic: 505; sh: 139; xml: 114; lisp: 96; makefile: 26
file content (132 lines) | stat: -rw-r--r-- 2,687 bytes parent folder | download
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
def f() =
  s =
    '<bla param="1" bla="true">
<foo opt="12.3">gni</foo>
<bar />
<bar option="aab">bla</bar>
<blo>1.23</blo>
<blu>false</blu>
<ble>123</ble>
</bla>'

  let xml.parse (x :
    {
      bla: {
        foo: string.{ xml_params: {opt: float} },
        bar: (string? * string?.{ xml_params: [(string * string)] }),
        blo: float,
        blu: bool,
        ble: int,
        xml_params: [(string * string)].{ bla: bool }
      }
    }
  ) = s

  test.equal(
    x,
    {
      bla=
        {
          xml_params=[("param", "1"), ("bla", "true")].{bla=true},
          ble=123,
          blu=false,
          blo=1.23,
          bar=(null, "bla".{xml_params=[("option", "aab")]}),
          foo="gni".{xml_params={opt=12.3}}
        }
    }
  )

  test.equal(
    xml.stringify(
      {
        bla=
          {
            xml_params=[("param", "1"), ("bla", "true")],
            bar="bla".{xml_params=[("option", "aab")]},
            foo=true.{xml_params={opt=12.3}}
          }
      }
    ),
    '<bla param="1" bla="true">
  <bar option="aab">bla</bar>
  <foo opt="12.3">true</foo>
</bla>'
  )

  let xml.parse (x :
    (
      string
      *
      {
        xml_params: [(string * string)],
        xml_children: [
          (
            string
            *
            {
              xml_params: [(string * string)],
              xml_children: [(string * {xml_text: string})]
            }
          )
        ]
      }
    )
  ) = s

  test.equal(
    x,
    (
      "bla",
      {
        xml_children=
          [
            (
              "foo",
              {
                xml_children=[("xml_text", {xml_text="gni"})],
                xml_params=[("opt", "12.3")]
              }
            ),
            ("bar", {xml_children=[], xml_params=[]}),
            (
              "bar",
              {
                xml_children=[("xml_text", {xml_text="bla"})],
                xml_params=[("option", "aab")]
              }
            ),
            (
              "blo",
              {xml_children=[("xml_text", {xml_text="1.23"})], xml_params=[]}
            ),
            (
              "blu",
              {xml_children=[("xml_text", {xml_text="false"})], xml_params=[]}
            ),
            (
              "ble",
              {xml_children=[("xml_text", {xml_text="123"})], xml_params=[]}
            )
          ],
        xml_params=[("param", "1"), ("bla", "true")]
      }
    )
  )

  test.equal(
    xml.stringify(x),
    '<bla param="1" bla="true">
  <foo opt="12.3">gni</foo>
  <bar/>
  <bar option="aab">bla</bar>
  <blo>1.23</blo>
  <blu>false</blu>
  <ble>123</ble>
</bla>'
  )

  test.pass()
end

test.check(f)