rogdl 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,189 @@
1
+ require 'test/unit'
2
+ require 'lib/rogdl'
3
+
4
+ class TestParser < Test::Unit::TestCase
5
+ include Rogdl
6
+
7
+ def test_initialize
8
+ parser = Parser.new
9
+ assert_equal false, parser.nil?
10
+ assert_equal [[]], parser.lines
11
+ end
12
+
13
+ def xtest_parse
14
+ text = <<TEXT
15
+ # leading comments
16
+
17
+ parent
18
+ child
19
+ grandchild #trailing comments
20
+ # comments in the middle
21
+ sibling
22
+
23
+ TEXT
24
+
25
+ parent = Parser.parse(text)
26
+ assert_equal 'parent', parent.gname
27
+ assert_equal 2, parent.glength
28
+ assert_equal 'grandchild', parent.child.grandchild.gname
29
+ assert_equal '<parent><child>grandchild</child><sibling/></parent>', parent.to_xml
30
+ end
31
+
32
+
33
+
34
+
35
+ def tconvert(convert_me, expected)
36
+ parser = Parser.new
37
+ parser.lines = convert_me
38
+ converted = parser.convert
39
+ assert_equal true, (expected == converted)
40
+ end
41
+
42
+ def test_convert
43
+
44
+ tconvert([['a']], Node.new('a'))
45
+ tconvert([['ab']], Node.new('ab'))
46
+ tconvert([['a','b']], Node.new('a').add('b'))
47
+ tconvert([['a'], [nil, 'b']], Node.new('a').add('b'))
48
+
49
+ tconvert([[],['a']], Node.new('a'))
50
+ end
51
+
52
+
53
+ def expect(string, lines)
54
+ parser = Parser.new
55
+ parser.translate(string)
56
+
57
+ assert_equal lines, parser.lines
58
+ end
59
+
60
+ def expect_raise(string)
61
+ assert_raise RuntimeError do
62
+ Parser.new.translate(string)
63
+ end
64
+ end
65
+
66
+ def test_whitespace
67
+ expect(' ', [[]])
68
+ expect(' ', [[]])
69
+ expect(' ', [[]])
70
+ expect(' ', [[nil]])
71
+ expect(' ', [[nil]])
72
+ expect(' ', [[nil]])
73
+ expect(' ', [[nil]])
74
+ expect(' ', [[nil,nil]])
75
+
76
+ expect(' a', [[nil, 'a']])
77
+ expect(' a', [[nil, nil, 'a']])
78
+
79
+ expect(" a\n b", [[nil, 'a'], [nil, 'b']])
80
+ expect(" a\n b", [[nil, nil, 'a'], [nil, nil, 'b']])
81
+
82
+ expect(' #', [[]])
83
+ expect(" \n", [[],[]])
84
+ expect(" #\n", [[],[]])
85
+ expect " \na", [[],['a']]
86
+ end
87
+
88
+ def test_simple_strings
89
+ expect('a', [['a']])
90
+ expect('ab', [['ab']])
91
+ expect('a b', [['a','b']])
92
+ expect(' a', [[nil, 'a']])
93
+ expect(' a ', [[nil, 'a']])
94
+ expect(' a ', [[nil, 'a']])
95
+
96
+ expect('ab cd', [['ab','cd']])
97
+ expect(' ab cd', [[nil, 'ab','cd']])
98
+ expect(' ab cd ', [[nil, 'ab', 'cd']])
99
+ expect(' ab cd ', [[nil, 'ab', 'cd']])
100
+
101
+ expect("a\nb", [['a'],['b']])
102
+ expect("ab\ncd", [['ab'], ['cd']])
103
+ expect("a b\nc d", [['a','b'], ['c','d']])
104
+ expect(" a\n b", [[nil, 'a'], [nil, 'b']])
105
+ expect(" a \n b ", [[nil, 'a'], [nil, 'b']])
106
+ expect(" a \n b ", [[nil, 'a'], [nil, 'b']])
107
+
108
+ expect("ab cd\nef gh", [['ab','cd'], ['ef','gh']])
109
+ expect(" ab cd\n ef gh", [[nil, 'ab','cd'], [nil, 'ef','gh']])
110
+ expect(" ab cd \n ef gh ", [[nil, 'ab', 'cd'], [nil, 'ef', 'gh']])
111
+ expect(" ab cd \n ef gh ", [[nil, 'ab', 'cd'], [nil, 'ef', 'gh']])
112
+
113
+ end
114
+
115
+ def test_sq_strings
116
+ expect("'a'", [['a']])
117
+ expect("'ab'", [['ab']])
118
+ expect("'a b'", [['a b']])
119
+ expect("'a' 'b'", [['a','b']])
120
+ expect("'a b'", [['a b']])
121
+ expect(%s{'!@#$%^&*()<>?:"|_+,./;[]-='}.to_s, [[%s{!@#$%^&*()<>?:"|_+,./;[]-=}.to_s]])
122
+ expect("'\\''",[["'"]])
123
+
124
+ expect_raise("'\n")
125
+ expect_raise("'\n'")
126
+ end
127
+
128
+ def test_dq_strings
129
+ expect('"a"', [['a']])
130
+ expect('"ab"', [['ab']])
131
+ expect('"a b"', [['a b']])
132
+ expect('"a" "b"', [['a','b']])
133
+ expect('"a b"', [['a b']])
134
+ expect(%s{"!@#$%^&*()<>?:'|_+,./;[]-="}.to_s, [[%s{!@#$%^&*()<>?:'|_+,./;[]-=}.to_s]])
135
+ expect('"' + '\\' + '"' + '"',[['"']])
136
+
137
+ expect_raise('"' + "\n")
138
+ expect_raise('"' + "\n" + '"')
139
+ end
140
+
141
+ def test_comments
142
+ expect('#a', [[]])
143
+ expect(' #a', [[]])
144
+ expect(' #a', [[nil]])
145
+ expect('#####', [[]])
146
+ expect("#a\n#b", [[], []])
147
+
148
+ end
149
+
150
+ def test_phrases
151
+ expect('a (b)', [['a'], [nil, 'b']])
152
+ expect('a ( b)', [['a'], [nil, 'b']])
153
+ expect('a (b )', [['a'], [nil, 'b']])
154
+ expect('a ( b )', [['a'], [nil, 'b']])
155
+ expect('a (b c)', [['a'], [nil, 'b', 'c']])
156
+
157
+ expect('"a" ("b")', [['a'], [nil, 'b']])
158
+ expect('"a" ( "b")', [['a'], [nil, 'b']])
159
+ expect('"a" ("b" )', [['a'], [nil, 'b']])
160
+ expect('"a" ( "b" )', [['a'], [nil, 'b']])
161
+ expect('"a" ("b" "c")', [['a'], [nil, 'b', 'c']])
162
+ expect('"a" ("b c")', [['a'], [nil, 'b c']])
163
+
164
+ expect("'a' ('b')", [['a'], [nil, 'b']])
165
+ expect("'a' ( 'b')", [['a'], [nil, 'b']])
166
+ expect("'a' ('b' )", [['a'], [nil, 'b']])
167
+ expect("'a' ( 'b' )", [['a'], [nil, 'b']])
168
+ expect("'a' ('b' 'c')", [['a'], [nil, 'b', 'c']])
169
+ expect("'a' ('b c')", [['a'], [nil, 'b c']])
170
+
171
+
172
+ end
173
+
174
+
175
+ def test_clauses
176
+ expect('a (b, c)', [['a'], [nil, 'b'], [nil, 'c']])
177
+ expect('a (b, c, d)', [['a'], [nil, 'b'], [nil, 'c'], [nil, 'd']])
178
+ expect('"a" ("b", "c")', [['a'], [nil, 'b'], [nil, 'c']])
179
+ expect("'a' ('b', 'c')", [['a'], [nil, 'b'], [nil, 'c']])
180
+
181
+ expect("a (b c)", [['a'], [nil, 'b', 'c']])
182
+ expect("a (b c)\n", [['a'], [nil, 'b', 'c'], []])
183
+ expect("a\n b (c d)", [['a'], [nil, 'b'], [nil, nil, 'c', 'd']])
184
+ expect("a\n b (c)\n d (e)", [['a'], [nil, 'b'], [nil, nil, 'c'], [nil, 'd'], [nil, nil, 'e']])
185
+ end
186
+
187
+
188
+
189
+ end
@@ -0,0 +1,11 @@
1
+ require 'test/unit'
2
+ require 'lib/rogdl'
3
+
4
+ class TestRogdl < Test::Unit::TestCase
5
+ include Rogdl
6
+
7
+ def test_empty
8
+ # this is included for Gem publication
9
+ end
10
+
11
+ end
@@ -0,0 +1,66 @@
1
+ require 'test/unit'
2
+ require 'lib/rogdl'
3
+
4
+
5
+ class TestSchema < Test::Unit::TestCase
6
+ include Rogdl
7
+
8
+ def test_initialize
9
+ schema = Schema.new(Node.new('a'))
10
+ end
11
+
12
+ def test_validate1
13
+ schema = Schema.new(Parser.parse_file("./rspec/clouds_schema.ogdl"))
14
+ messages = schema.validate(Node.new('blah'))
15
+ assert_equal "Expecting 'families', but found 'blah'", messages.first
16
+ end
17
+
18
+ def test_validate2
19
+ schema = Schema.new(Parser.parse_file("./rspec/clouds_schema.ogdl"))
20
+ messages = schema.validate(Node.new('families'))
21
+ assert_equal "Found node named 'families' that should have one or more children named: 'family'", messages.first
22
+ end
23
+
24
+ def test_validate3
25
+ cloud_string = <<CLOUDS
26
+ families
27
+ family
28
+ name
29
+ description
30
+ CLOUDS
31
+ schema = Schema.new(Parser.parse_file("./rspec/clouds_schema.ogdl"))
32
+ messages = schema.validate(Parser.parse(cloud_string))
33
+ assert_equal "Found node named 'family' that should have one or more children named: 'cloud'", messages.first
34
+ end
35
+
36
+ def test_validate4
37
+ cloud_string = <<CLOUDS
38
+ families
39
+ family
40
+ #name missing!!
41
+ description
42
+ cloud
43
+ name
44
+ CLOUDS
45
+ schema = Schema.new(Parser.parse_file("./rspec/clouds_schema.ogdl"))
46
+ messages = schema.validate(Parser.parse(cloud_string))
47
+ assert_equal "Found node named 'family' that should have exactly one child named: 'name'", messages.first
48
+ end
49
+
50
+ def test_validate5
51
+ cloud_string = <<CLOUDS
52
+ families
53
+ family
54
+ name
55
+ description
56
+ cloud
57
+ name
58
+ genus
59
+ genus
60
+ CLOUDS
61
+ schema = Schema.new(Parser.parse_file("./rspec/clouds_schema.ogdl"))
62
+ messages = schema.validate(Parser.parse(cloud_string))
63
+ assert_equal "Found node named 'cloud' that should have zero or one child named: 'genus'", messages.first
64
+ end
65
+
66
+ end
@@ -0,0 +1,32 @@
1
+ require 'lib/rogdl'
2
+ require 'test/unit'
3
+
4
+ class TestString < Test::Unit::TestCase
5
+ include Rogdl
6
+
7
+ def test_camel_case
8
+ assert_equal 'someText', 'some text'.camel_case
9
+ assert_equal 'someText', 'some_text'.camel_case
10
+ end
11
+
12
+ def test_upper_camel_case
13
+ assert_equal 'SomeText', 'some text'.upper_camel_case
14
+ assert_equal 'SomeText', 'some_text'.upper_camel_case
15
+ end
16
+
17
+ def test_pluralize
18
+ assert_equal 'dogs', 'dog'.pluralize
19
+ assert_equal 'buses', 'bus'.pluralize
20
+ end
21
+
22
+ def test_to_b
23
+ assert_equal true, 'true'.to_b
24
+ assert_equal false, 'false'.to_b
25
+ assert_equal false, 'blah'.to_b
26
+ end
27
+
28
+ def test_to_n
29
+ assert_equal 'a', 'a'.to_n.gname
30
+ end
31
+
32
+ end
@@ -0,0 +1,13 @@
1
+ require 'test/unit'
2
+ require 'lib/rogdl'
3
+
4
+ class TestSymbol < Test::Unit::TestCase
5
+ include Rogdl
6
+
7
+ def test_a
8
+ assert_equal ':a', :a.to_n.gname
9
+ end
10
+
11
+
12
+
13
+ end
@@ -0,0 +1,71 @@
1
+ require 'test/unit'
2
+ require 'lib/node'
3
+ require 'lib/writer'
4
+ require 'lib/parser'
5
+
6
+ class TestWriter < Test::Unit::TestCase
7
+ include Rogdl
8
+
9
+ def test_initialize
10
+ writer = Writer.new
11
+ assert_equal({}, writer.templates)
12
+ end
13
+
14
+ def test_hi
15
+ parent = Node.new("parent")
16
+ writer = Writer.new
17
+ writer.templates["parent"] = "hi"
18
+ array = writer.write(parent)
19
+ assert_equal ["hi"], array
20
+ end
21
+
22
+ def test_simple
23
+ parent = Node.new("parent")
24
+ writer = Writer.new
25
+ writer.templates["parent"] = "<%= self.gname %>"
26
+ array = writer.write(parent)
27
+ assert_equal ["parent"], array
28
+ end
29
+
30
+ def test_simple2
31
+ parent = Node.new("parent")
32
+ parent.add Node.new("child")
33
+ writer = Writer.new
34
+ writer.templates["parent"] = "<%= self.gvalue %>"
35
+ array = writer.write(parent)
36
+ assert_equal ["child"], array
37
+ end
38
+
39
+ def test_simple3
40
+ parent = Node.new("parent")
41
+ parent.add Node.new("child")
42
+ writer = Writer.new
43
+ writer.templates["parent"] = "<hi><%= self.gvalue %></hi>"
44
+ array = writer.write(parent)
45
+ assert_equal ["<hi>child</hi>"], array
46
+ end
47
+
48
+ def test_nested
49
+ parent = Node.new("parent")
50
+ parent.add Node.new("child")
51
+ writer = Writer.new
52
+ writer.templates["parent"] = %q{<hi><%= self.gfirst.render %></hi>}
53
+ writer.templates["child"] = %q{<bye><%= self.gname %></bye>}
54
+ array = writer.write(parent)
55
+ assert_equal ["<hi><bye>child</bye></hi>"], array
56
+ end
57
+
58
+ def test_override_template_name
59
+ parent = Node.new("parent")
60
+ parent.add Node.new("child")
61
+ writer = Writer.new
62
+ writer.templates["parent"] = %q{<hi><%= self.gfirst.render('alternate') %></hi>}
63
+ writer.templates["child"] = %q{<bye><%= self.gname %></bye>}
64
+ writer.templates["alternate"] = %q{<goodbye><%= self.gname %></goodbye>}
65
+ array = writer.write(parent)
66
+ assert_equal ["<hi><goodbye>child</goodbye></hi>"], array
67
+ end
68
+
69
+
70
+
71
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.2
3
+ specification_version: 1
4
+ name: rogdl
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.1.0
7
+ date: 2007-08-20 00:00:00 -05:00
8
+ summary: A package for parsing OGDL files
9
+ require_paths:
10
+ - lib/rogdl
11
+ email: ben.hidalgo@gmail.com
12
+ homepage:
13
+ rubyforge_project:
14
+ description:
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: false
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - Ben Hidalgo
31
+ files:
32
+ - lib/array.rb
33
+ - lib/fixnum.rb
34
+ - lib/hash.rb
35
+ - lib/nil.rb
36
+ - lib/node.rb
37
+ - lib/parser.rb
38
+ - lib/rogdl.rb
39
+ - lib/schema.rb
40
+ - lib/string.rb
41
+ - lib/symbol.rb
42
+ - lib/writer.rb
43
+ - test/test_array.rb
44
+ - test/test_fixnum.rb
45
+ - test/test_hash.rb
46
+ - test/test_nil.rb
47
+ - test/test_node.rb
48
+ - test/test_parser.rb
49
+ - test/test_rogdl.rb
50
+ - test/test_schema.rb
51
+ - test/test_string.rb
52
+ - test/test_symbol.rb
53
+ - test/test_writer.rb
54
+ - README.txt
55
+ - History.txt
56
+ test_files: []
57
+
58
+ rdoc_options: []
59
+
60
+ extra_rdoc_files:
61
+ - README.txt
62
+ - History.txt
63
+ executables: []
64
+
65
+ extensions: []
66
+
67
+ requirements: []
68
+
69
+ dependencies: []
70
+