genx4r 0.04

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,93 @@
1
+ require 'test/unit'
2
+ require 'stringio'
3
+
4
+ $LOAD_PATH.unshift('ext/genx4r')
5
+
6
+ require 'genx4r'
7
+
8
+ # $Id: basics.rb 268 2004-07-10 00:33:11Z rooneg $
9
+
10
+ class BasicsTest < Test::Unit::TestCase
11
+ def init_writer
12
+ return GenX::Writer.new, StringIO.new
13
+ end
14
+
15
+ def test_element
16
+ w, io = init_writer
17
+
18
+ w.document(io) do
19
+ w.element("http://bar", "foo") do
20
+ end
21
+ end
22
+
23
+ assert io.string == "<g1:foo xmlns:g1=\"http://bar\"></g1:foo>"
24
+
25
+ w, io = init_writer
26
+
27
+ w.document(io) do
28
+ w.element("foo") do
29
+ end
30
+ end
31
+
32
+ assert io.string == "<foo></foo>"
33
+
34
+ w, io = init_writer
35
+
36
+ w.begin_document(io)
37
+ w.begin_element("foo")
38
+ w.text("bar")
39
+ w.end_element
40
+ w.end_document
41
+
42
+ assert io.string == "<foo>bar</foo>"
43
+ end
44
+
45
+ def test_nested_elements
46
+ w, io = init_writer
47
+
48
+ w.document(io) do
49
+ w.element("foo") do
50
+ w.element("bar") do
51
+ end
52
+ end
53
+ end
54
+
55
+ assert io.string == "<foo><bar></bar></foo>"
56
+ end
57
+
58
+ def test_text
59
+ w, io = init_writer
60
+
61
+ w.document(io) do
62
+ w.element("foo") do
63
+ w.text("bar")
64
+ end
65
+ end
66
+
67
+ assert io.string == "<foo>bar</foo>"
68
+ end
69
+
70
+ def test_comment
71
+ w, io = init_writer
72
+
73
+ w.document(io) do
74
+ w.element("foo") do
75
+ w.comment("blah")
76
+ end
77
+ end
78
+
79
+ assert io.string == "<foo><!--blah--></foo>"
80
+ end
81
+
82
+ def test_pi
83
+ w, io = init_writer
84
+
85
+ w.document(io) do
86
+ w.element("base") do
87
+ w.pi("foo", "bar")
88
+ end
89
+ end
90
+
91
+ assert io.string == "<base><?foo bar?></base>"
92
+ end
93
+ end
@@ -0,0 +1,59 @@
1
+ require 'test/unit'
2
+ require 'stringio'
3
+
4
+ $LOAD_PATH.unshift('ext/genx4r')
5
+
6
+ require 'genx4r'
7
+
8
+ # $Id: declare.rb 268 2004-07-10 00:33:11Z rooneg $
9
+
10
+ class DeclareTest < Test::Unit::TestCase
11
+ def init_writer
12
+ return GenX::Writer.new, StringIO.new
13
+ end
14
+
15
+ def test_element
16
+ w, io = init_writer
17
+
18
+ e = w.declare_element("bar")
19
+
20
+ w.document(io) do
21
+ w.element(e) do
22
+ end
23
+ end
24
+
25
+ assert io.string == "<bar></bar>"
26
+ end
27
+
28
+ def test_attribute
29
+ w, io = init_writer
30
+
31
+ a = w.declare_attribute("blah")
32
+
33
+ w.document(io) do
34
+ w.element("foo") do
35
+ w.attribute(a, "baz")
36
+ end
37
+ end
38
+
39
+ assert io.string == "<foo blah=\"baz\"></foo>"
40
+ end
41
+
42
+ def test_namespace
43
+ w, io = init_writer
44
+
45
+ n = w.declare_namespace("http://foo.com/bar", "bar")
46
+
47
+ e = w.declare_element(n, "blah")
48
+ a = w.declare_attribute(n, "zot")
49
+
50
+ w.document(io) do
51
+ w.element(e) do
52
+ w.attribute(a, "zang")
53
+ end
54
+ end
55
+
56
+ assert io.string == "<bar:blah xmlns:bar=\"http://foo.com/bar\"" +
57
+ " bar:zot=\"zang\"></bar:blah>"
58
+ end
59
+ end
@@ -0,0 +1,41 @@
1
+ require 'test/unit'
2
+ require 'stringio'
3
+
4
+ $LOAD_PATH.unshift('ext/genx4r')
5
+
6
+ require 'genx4r'
7
+
8
+ # $Id: basics.rb 202 2004-06-13 21:41:59Z rooneg $
9
+
10
+ # some class that doesn't respond to <<
11
+ class SomethingElse
12
+ end
13
+
14
+ # tests that we can use anything that replies to <<, not just an IO object
15
+ class NonIoTest < Test::Unit::TestCase
16
+ def test_non_io
17
+ w = GenX::Writer.new
18
+ s = String.new
19
+
20
+ w.document(s) do
21
+ w.element("http://bar", "foo") do
22
+ end
23
+ end
24
+
25
+ assert s == "<g1:foo xmlns:g1=\"http://bar\"></g1:foo>"
26
+
27
+ s = SomethingElse.new
28
+
29
+ begin
30
+ w.document(s) do
31
+ w.element("foo") do
32
+ end
33
+ end
34
+ rescue RuntimeError => re
35
+ assert re.to_s == "target must respond to '<<'"
36
+ return
37
+ end
38
+
39
+ fail "should have raised exception..."
40
+ end
41
+ end
metadata ADDED
@@ -0,0 +1,55 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.8.1
3
+ specification_version: 1
4
+ name: genx4r
5
+ version: !ruby/object:Gem::Version
6
+ version: "0.04"
7
+ date: 2004-10-01
8
+ summary: "GenX4r is a Ruby wrapper around the GenX library, which allows you to programatically generate correct, cannonical XML output."
9
+ require_paths:
10
+ - lib
11
+ author: Garrett Rooney
12
+ email: rooneg@electricjellyfish.net
13
+ homepage: http://genx4r.rubyforge.org
14
+ rubyforge_project: genx4r
15
+ description: "GenX4r is a Ruby wrapper around the GenX library, which allows you to programatically generate correct, cannonical XML output."
16
+ autorequire: genx4r
17
+ default_executable:
18
+ bindir: bin
19
+ has_rdoc: false
20
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
21
+ requirements:
22
+ -
23
+ - ">"
24
+ - !ruby/object:Gem::Version
25
+ version: 0.0.0
26
+ version:
27
+ platform: ruby
28
+ files:
29
+ - CHANGES
30
+ - ext
31
+ - genx4r.gemspec
32
+ - LICENSE
33
+ - README
34
+ - setup.rb
35
+ - test
36
+ - TODO
37
+ - ext/genx4r
38
+ - ext/genx4r/charProps.c
39
+ - ext/genx4r/extconf.rb
40
+ - ext/genx4r/genx.c
41
+ - ext/genx4r/genx.h
42
+ - ext/genx4r/genx4r.c
43
+ - ext/genx4r/MANIFEST
44
+ - test/basics.rb
45
+ - test/declare.rb
46
+ - test/non-io.rb
47
+ test_files:
48
+ - test/basics.rb
49
+ rdoc_options: []
50
+ extra_rdoc_files: []
51
+ executables: []
52
+ extensions:
53
+ - ext/genx4r/extconf.rb
54
+ requirements: []
55
+ dependencies: []