File: xbuilder_test.rb

package info (click to toggle)
ruby-ox 2.14.22-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,500 kB
  • sloc: xml: 39,683; ansic: 9,615; ruby: 6,422; sh: 47; makefile: 2
file content (45 lines) | stat: -rwxr-xr-x 1,099 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
#!/usr/bin/env ruby
# Contributed by Notezen

$: << File.join(File.dirname(__FILE__), '../lib')
$: << File.join(File.dirname(__FILE__), '../ext')
$: << File.join(File.dirname(__FILE__), '.')

require 'test/unit'
require 'ox'
require 'xbuilder'

class XBuilderTest < Test::Unit::TestCase
  include Ox::XBuilder

  def test_build
    xml =
      '<parent>
  <child1 atr1="atr1_value" atr2="atr2_value">
    <subchild1>some text</subchild1>
    <subchild2 atr3="atr3_value">
      <sometag/>
    </subchild2>
  </child1>
  <child3/>
  <child4 atr4="atr4_value">another text</child4>
</parent>'

    children =
      [
        x_if(true, 'child3'),
        x('child4', 'another text', 'atr4' => 'atr4_value'),
        x_if(false, 'child5')
      ]

    n=x('parent',
        x('child1', { 'atr1'=>'atr1_value', :atr2 => 'atr2_value' },
          x('subchild1', 'some text'),
          x('subchild2', { 'atr3' => 'default_value' }, { 'atr3' => 'atr3_value' },
            x('sometag'),
            x_if(false, 'never'))),
        children)

    assert_equal(Ox.dump(n), Ox.dump(Ox.parse(xml)))
  end
end