sdl4r 0.9.9 → 0.9.11
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +70 -1
- data/LICENSE +499 -497
- data/Rakefile +38 -28
- data/TODO +194 -45
- data/doc/classes/SDL4R/AbbreviationTimezoneProxy.html +151 -0
- data/doc/classes/SDL4R/ConstantTimezone.html +129 -0
- data/doc/classes/SDL4R/Element.html +148 -0
- data/doc/classes/SDL4R/Reader.html +683 -0
- data/doc/classes/SDL4R/RelativeTimezone.html +187 -0
- data/doc/classes/SDL4R/SdlBinary.html +188 -0
- data/doc/classes/SDL4R/SdlParseError.html +110 -0
- data/doc/classes/SDL4R/SdlTimeSpan.html +651 -0
- data/doc/classes/SDL4R/Serializer.html +557 -0
- data/doc/classes/SDL4R/Serializer/Ref.html +138 -0
- data/doc/classes/SDL4R/TZAbbreviationDB/Record.html +117 -0
- data/doc/classes/SDL4R/Tag.html +1274 -0
- data/doc/classes/SDL4R/Token.html +131 -0
- data/doc/created.rid +1 -0
- data/doc/files/CHANGELOG.html +290 -0
- data/doc/files/LICENSE.html +53 -0
- data/doc/files/README.html +405 -0
- data/doc/files/lib/sdl4r/abbreviation_timezone_proxy_rb.html +63 -0
- data/doc/files/lib/sdl4r/constant_timezone_rb.html +54 -0
- data/doc/files/lib/sdl4r/element_rb.html +54 -0
- data/doc/files/lib/sdl4r/reader_rb.html +68 -0
- data/doc/files/lib/sdl4r/relative_timezone_rb.html +62 -0
- data/doc/files/lib/sdl4r/sdl4r_rb.html +66 -0
- data/doc/files/lib/sdl4r/sdl4r_tzinfo_rb.html +64 -0
- data/doc/files/lib/sdl4r/sdl4r_version_rb.html +54 -0
- data/doc/files/lib/sdl4r/sdl_binary_rb.html +54 -0
- data/doc/files/lib/sdl4r/sdl_parse_error_rb.html +54 -0
- data/doc/files/lib/sdl4r/sdl_time_span_rb.html +54 -0
- data/doc/files/lib/sdl4r/serializer_rb.html +62 -0
- data/doc/files/lib/sdl4r/tag_rb.html +66 -0
- data/doc/files/lib/sdl4r/token_rb.html +54 -0
- data/doc/files/lib/sdl4r/tokenizer_rb.html +64 -0
- data/doc/files/lib/sdl4r/tz_abbreviation_db_rb.html +67 -0
- data/doc/files/lib/sdl4r_rb.html +54 -0
- data/doc/files/lib/sdl4r_tzinfo_rb.html +54 -0
- data/doc/fr_class_index.html +23 -0
- data/doc/fr_file_index.html +40 -0
- data/doc/fr_method_index.html +4711 -0
- data/doc/index.html +15 -0
- data/doc/rdoc-style.css +328 -0
- data/lib/sdl4r.rb +3 -1
- data/lib/sdl4r/abbreviation_timezone_proxy.rb +38 -0
- data/lib/sdl4r/constant_timezone.rb +58 -0
- data/{test/sdl4r/sdl_test.rb → lib/sdl4r/element.rb} +19 -14
- data/lib/sdl4r/reader.rb +772 -0
- data/lib/sdl4r/relative_timezone.rb +156 -0
- data/lib/sdl4r/sdl4r.rb +187 -45
- data/lib/sdl4r/sdl4r_tzinfo.rb +75 -0
- data/lib/sdl4r/sdl4r_version.rb +24 -0
- data/lib/sdl4r/sdl_parse_error.rb +1 -1
- data/lib/sdl4r/sdl_time_span.rb +5 -1
- data/lib/sdl4r/serializer.rb +473 -60
- data/lib/sdl4r/tag.rb +126 -51
- data/lib/sdl4r/token.rb +49 -0
- data/lib/sdl4r/tokenizer.rb +431 -0
- data/lib/sdl4r/tz_abbreviation_db.rb +266 -0
- data/read_jprof.html +16934 -0
- data/read_jprof_pull.html +14451 -0
- data/read_prof.html +4983 -0
- data/read_prof_pull.html +4896 -0
- data/test/sdl4r/parser_test.rb +577 -503
- data/test/sdl4r/read_jprof.rb +58 -0
- data/test/sdl4r/read_prof.rb +70 -0
- data/test/sdl4r/reader_test.rb +173 -0
- data/test/sdl4r/relative_timezone_test.rb +102 -0
- data/test/sdl4r/sdl4r_test.rb +611 -528
- data/test/sdl4r/sdl4r_tzinfo_test.rb +108 -0
- data/test/sdl4r/sdl_test_case.rb +60 -0
- data/test/sdl4r/serializer_test.rb +448 -11
- data/test/sdl4r/tag_test.rb +84 -5
- data/test/sdl4r/tokenizer_test.rb +128 -0
- metadata +69 -11
- data/lib/sdl4r/parser.rb +0 -648
- data/lib/sdl4r/parser/reader.rb +0 -184
- data/lib/sdl4r/parser/time_span_with_zone.rb +0 -57
- data/lib/sdl4r/parser/token.rb +0 -138
- data/lib/sdl4r/parser/tokenizer.rb +0 -507
@@ -0,0 +1,58 @@
|
|
1
|
+
#!/usr/bin/env ruby -w
|
2
|
+
# encoding: UTF-8
|
3
|
+
|
4
|
+
#--
|
5
|
+
#
|
6
|
+
# Simple Declarative Language (SDL) for Ruby
|
7
|
+
# Copyright 2005 Ikayzo, inc.
|
8
|
+
#
|
9
|
+
# This program is free software. You can distribute or modify it under the
|
10
|
+
# terms of the GNU Lesser General Public License version 2.1 as published by
|
11
|
+
# the Free Software Foundation.
|
12
|
+
#
|
13
|
+
# This program is distributed AS IS and WITHOUT WARRANTY. OF ANY KIND,
|
14
|
+
# INCLUDING MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
|
15
|
+
# See the GNU Lesser General Public License for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU Lesser General Public License
|
18
|
+
# along with this program; if not, contact the Free Software Foundation, Inc.,
|
19
|
+
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
20
|
+
#++
|
21
|
+
|
22
|
+
# Work-around a bug in NetBeans (http://netbeans.org/bugzilla/show_bug.cgi?id=188653)
|
23
|
+
if ENV["NB_EXEC_EXTEXECUTION_PROCESS_UUID"]
|
24
|
+
$:[0] = File.join(File.dirname(__FILE__),'../../lib')
|
25
|
+
$:.unshift(File.join(File.dirname(__FILE__),'../../test'))
|
26
|
+
end
|
27
|
+
|
28
|
+
require 'rubygems'
|
29
|
+
require 'jruby-prof'
|
30
|
+
|
31
|
+
if RUBY_VERSION < '1.9.0'
|
32
|
+
$KCODE = 'u'
|
33
|
+
require 'jcode'
|
34
|
+
end
|
35
|
+
|
36
|
+
module SDL4R
|
37
|
+
|
38
|
+
require 'sdl4r'
|
39
|
+
|
40
|
+
# SDL4R::use_datetime = false
|
41
|
+
|
42
|
+
file1 = Pathname.new(File.dirname(__FILE__) + '/test_basic_types.sdl').read
|
43
|
+
file2 = Pathname.new(File.dirname(__FILE__) + '/test_structures.sdl').read
|
44
|
+
|
45
|
+
# Do all the loading once
|
46
|
+
SDL4R::read(file1)
|
47
|
+
SDL4R::read(file2)
|
48
|
+
|
49
|
+
result = JRubyProf.profile {
|
50
|
+
100.times {
|
51
|
+
SDL4R::read(file1)
|
52
|
+
SDL4R::read(file2)
|
53
|
+
}
|
54
|
+
}
|
55
|
+
|
56
|
+
JRubyProf.print_graph_html(result, "read_jprof_pull.html")
|
57
|
+
|
58
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
#!/usr/bin/env ruby -w
|
2
|
+
# encoding: UTF-8
|
3
|
+
|
4
|
+
#--
|
5
|
+
#
|
6
|
+
# Simple Declarative Language (SDL) for Ruby
|
7
|
+
# Copyright 2005 Ikayzo, inc.
|
8
|
+
#
|
9
|
+
# This program is free software. You can distribute or modify it under the
|
10
|
+
# terms of the GNU Lesser General Public License version 2.1 as published by
|
11
|
+
# the Free Software Foundation.
|
12
|
+
#
|
13
|
+
# This program is distributed AS IS and WITHOUT WARRANTY. OF ANY KIND,
|
14
|
+
# INCLUDING MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
|
15
|
+
# See the GNU Lesser General Public License for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU Lesser General Public License
|
18
|
+
# along with this program; if not, contact the Free Software Foundation, Inc.,
|
19
|
+
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
20
|
+
#++
|
21
|
+
|
22
|
+
# Work-around a bug in NetBeans (http://netbeans.org/bugzilla/show_bug.cgi?id=188653)
|
23
|
+
if ENV["NB_EXEC_EXTEXECUTION_PROCESS_UUID"]
|
24
|
+
$:[0] = File.join(File.dirname(__FILE__),'../../lib')
|
25
|
+
$:.unshift(File.join(File.dirname(__FILE__),'../../test'))
|
26
|
+
end
|
27
|
+
|
28
|
+
require 'rubygems'
|
29
|
+
require 'ruby-prof'
|
30
|
+
|
31
|
+
if RubyProf.running?
|
32
|
+
RubyProf.stop
|
33
|
+
end
|
34
|
+
RubyProf.start
|
35
|
+
RubyProf.pause
|
36
|
+
|
37
|
+
if RUBY_VERSION < '1.9.0'
|
38
|
+
$KCODE = 'u'
|
39
|
+
require 'jcode'
|
40
|
+
end
|
41
|
+
|
42
|
+
module SDL4R
|
43
|
+
|
44
|
+
require 'sdl4r'
|
45
|
+
|
46
|
+
file1 = Pathname.new(File.dirname(__FILE__) + '/test_basic_types.sdl').read
|
47
|
+
file2 = Pathname.new(File.dirname(__FILE__) + '/test_structures.sdl').read
|
48
|
+
|
49
|
+
# Do all the loading once
|
50
|
+
SDL4R::read(file1)
|
51
|
+
SDL4R::read(file2)
|
52
|
+
|
53
|
+
puts "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
|
54
|
+
puts ""
|
55
|
+
|
56
|
+
RubyProf.resume {
|
57
|
+
100.times {
|
58
|
+
SDL4R::read(file1)
|
59
|
+
SDL4R::read(file2)
|
60
|
+
}
|
61
|
+
}
|
62
|
+
|
63
|
+
result = RubyProf.stop
|
64
|
+
|
65
|
+
open("read_prof_pull.html", "w") do |io|
|
66
|
+
printer = RubyProf::GraphHtmlPrinter.new(result)
|
67
|
+
printer.print(io, :min_percent => 1)
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
@@ -0,0 +1,173 @@
|
|
1
|
+
#!/usr/bin/env ruby -w
|
2
|
+
# encoding: UTF-8
|
3
|
+
|
4
|
+
#--
|
5
|
+
# Simple Declarative Language (SDL) for Ruby
|
6
|
+
# Copyright 2005 Ikayzo, inc.
|
7
|
+
#
|
8
|
+
# This program is free software. You can distribute or modify it under the
|
9
|
+
# terms of the GNU Lesser General Public License version 2.1 as published by
|
10
|
+
# the Free Software Foundation.
|
11
|
+
#
|
12
|
+
# This program is distributed AS IS and WITHOUT WARRANTY. OF ANY KIND,
|
13
|
+
# INCLUDING MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
|
14
|
+
# See the GNU Lesser General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU Lesser General Public License
|
17
|
+
# along with this program; if not, contact the Free Software Foundation, Inc.,
|
18
|
+
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
19
|
+
#++
|
20
|
+
|
21
|
+
# Work-around a bug in NetBeans (http://netbeans.org/bugzilla/show_bug.cgi?id=188653)
|
22
|
+
if ENV["NB_EXEC_EXTEXECUTION_PROCESS_UUID"]
|
23
|
+
$:[0] = File.join(File.dirname(__FILE__),'../../../lib')
|
24
|
+
$:.unshift(File.join(File.dirname(__FILE__),'../../../test'))
|
25
|
+
end
|
26
|
+
|
27
|
+
if RUBY_VERSION < '1.9.0'
|
28
|
+
$KCODE = 'u'
|
29
|
+
require 'jcode'
|
30
|
+
end
|
31
|
+
|
32
|
+
module SDL4R
|
33
|
+
module Parser
|
34
|
+
|
35
|
+
require 'stringio'
|
36
|
+
require 'test/unit'
|
37
|
+
|
38
|
+
require 'sdl4r/sdl4r'
|
39
|
+
require 'sdl4r/reader'
|
40
|
+
|
41
|
+
require 'sdl4r/sdl_test_case'
|
42
|
+
|
43
|
+
class ReaderTest < Test::Unit::TestCase
|
44
|
+
include SdlTestCase
|
45
|
+
|
46
|
+
def read(sdl)
|
47
|
+
node_types = []
|
48
|
+
node_values = []
|
49
|
+
Reader.from_memory(sdl).each { |node|
|
50
|
+
node_types << node.node_type
|
51
|
+
node_values << node.value if node.node_type == Reader::TYPE_ELEMENT
|
52
|
+
}
|
53
|
+
return node_types, node_values
|
54
|
+
end
|
55
|
+
private :read
|
56
|
+
|
57
|
+
def test_read_empty
|
58
|
+
reader = Reader.from_memory("")
|
59
|
+
assert_nil reader.read
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_read_values
|
63
|
+
types, values = read("tag1 `toto`")
|
64
|
+
assert_equal [Reader::TYPE_ELEMENT], types
|
65
|
+
assert_equal [["toto"]], values
|
66
|
+
|
67
|
+
types, values = read("tag1 \"toto\"")
|
68
|
+
assert_equal [Reader::TYPE_ELEMENT], types
|
69
|
+
assert_equal [["toto"]], values
|
70
|
+
|
71
|
+
types, values = read("tag1 \"toto\\t123\"")
|
72
|
+
assert_equal [Reader::TYPE_ELEMENT], types
|
73
|
+
assert_equal [["toto\t123"]], values
|
74
|
+
|
75
|
+
types, values = read(<<-EOS)
|
76
|
+
tag1 {
|
77
|
+
"text"
|
78
|
+
tag2 123
|
79
|
+
}
|
80
|
+
EOS
|
81
|
+
assert_equal(
|
82
|
+
[Reader::TYPE_ELEMENT, Reader::TYPE_ELEMENT, Reader::TYPE_ELEMENT, Reader::TYPE_END_ELEMENT],
|
83
|
+
types)
|
84
|
+
assert_equal [nil, ["text"], [123]], values
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_accessors
|
88
|
+
reader = Reader.from_memory(<<-EOS)
|
89
|
+
tag1 "I've seen this before."
|
90
|
+
tag2 party="today" ever:work=false {
|
91
|
+
ns:tag3 "time is of the essence" attr1=-145.99
|
92
|
+
"Taratatata"
|
93
|
+
tag4
|
94
|
+
}
|
95
|
+
EOS
|
96
|
+
|
97
|
+
node = reader.read
|
98
|
+
assert_equal Reader::TYPE_ELEMENT, node.node_type
|
99
|
+
assert_equal "", node.prefix
|
100
|
+
assert_equal "tag1", node.name
|
101
|
+
assert_equal true, node.self_closing?
|
102
|
+
assert_equal ["I've seen this before."], node.value
|
103
|
+
assert_equal ["I've seen this before."], node.values
|
104
|
+
assert_equal true, node.value?
|
105
|
+
assert_equal true, node.values?
|
106
|
+
assert_equal false, node.attributes?
|
107
|
+
assert_equal 0, node.attribute_count
|
108
|
+
assert_equal [], node.attributes
|
109
|
+
assert_equal nil, node.attribute("something")
|
110
|
+
|
111
|
+
node = reader.read
|
112
|
+
assert_equal Reader::TYPE_ELEMENT, node.node_type
|
113
|
+
assert_equal "", node.prefix
|
114
|
+
assert_equal "tag2", node.name
|
115
|
+
assert_equal false, node.self_closing?
|
116
|
+
assert_equal nil, node.values
|
117
|
+
assert_equal false, node.values?
|
118
|
+
assert_equal true, node.attributes?
|
119
|
+
assert_equal 2, node.attribute_count
|
120
|
+
assert_equal [[["", "party"], "today"], [["ever", "work"], false]], node.attributes
|
121
|
+
assert_equal [["", "party"], "today"], node.attribute_at(0)
|
122
|
+
assert_equal [["ever", "work"], false], node.attribute_at(1)
|
123
|
+
assert_equal "today", node.attribute("party")
|
124
|
+
assert_equal false, node.attribute("ever", "work")
|
125
|
+
assert_equal nil, node.attribute("work")
|
126
|
+
|
127
|
+
node = reader.read
|
128
|
+
assert_equal Reader::TYPE_ELEMENT, node.node_type
|
129
|
+
assert_equal "ns", node.prefix
|
130
|
+
assert_equal "tag3", node.name
|
131
|
+
assert_equal true, node.self_closing?
|
132
|
+
assert_equal ["time is of the essence"], node.values
|
133
|
+
assert_equal true, node.values?
|
134
|
+
assert_equal true, node.attributes?
|
135
|
+
assert_equal 1, node.attribute_count
|
136
|
+
assert_equal [[["", "attr1"], -145.99]], node.attributes
|
137
|
+
assert_equal [["", "attr1"], -145.99], node.attribute_at(0)
|
138
|
+
assert_equal(-145.99, node.attribute("attr1"))
|
139
|
+
assert_equal(-145.99, node.attribute("", "attr1"))
|
140
|
+
assert_equal nil, node.attribute("kraken", "attr1")
|
141
|
+
|
142
|
+
node = reader.read
|
143
|
+
assert_equal Reader::TYPE_ELEMENT, node.node_type
|
144
|
+
assert_equal "", node.prefix
|
145
|
+
assert_equal SDL4R::ANONYMOUS_TAG_NAME, node.name
|
146
|
+
assert_equal true, node.self_closing?
|
147
|
+
assert_equal ["Taratatata"], node.value
|
148
|
+
assert_equal true, node.value?
|
149
|
+
assert_equal false, node.attributes?
|
150
|
+
assert_equal 0, node.attribute_count
|
151
|
+
assert_equal [], node.attributes
|
152
|
+
|
153
|
+
node = reader.read
|
154
|
+
assert_equal Reader::TYPE_ELEMENT, node.node_type
|
155
|
+
assert_equal "", node.prefix
|
156
|
+
assert_equal "tag4", node.name
|
157
|
+
assert_equal true, node.self_closing?
|
158
|
+
assert_equal nil, node.value
|
159
|
+
assert_equal false, node.value?
|
160
|
+
assert_equal false, node.attributes?
|
161
|
+
assert_equal 0, node.attribute_count
|
162
|
+
assert_equal [], node.attributes
|
163
|
+
|
164
|
+
node = reader.read
|
165
|
+
assert_equal Reader::TYPE_END_ELEMENT, node.node_type
|
166
|
+
|
167
|
+
assert_nil reader.read
|
168
|
+
assert_nil reader.read
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
end
|
173
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
#!/usr/bin/env ruby -w
|
2
|
+
# encoding: UTF-8
|
3
|
+
|
4
|
+
#--
|
5
|
+
#
|
6
|
+
# Simple Declarative Language (SDL) for Ruby
|
7
|
+
# Copyright 2005 Ikayzo, inc.
|
8
|
+
#
|
9
|
+
# This program is free software. You can distribute or modify it under the
|
10
|
+
# terms of the GNU Lesser General Public License version 2.1 as published by
|
11
|
+
# the Free Software Foundation.
|
12
|
+
#
|
13
|
+
# This program is distributed AS IS and WITHOUT WARRANTY. OF ANY KIND,
|
14
|
+
# INCLUDING MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
|
15
|
+
# See the GNU Lesser General Public License for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU Lesser General Public License
|
18
|
+
# along with this program; if not, contact the Free Software Foundation, Inc.,
|
19
|
+
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
20
|
+
#++
|
21
|
+
|
22
|
+
module SDL4R
|
23
|
+
|
24
|
+
require 'tzinfo'
|
25
|
+
require 'test/unit'
|
26
|
+
|
27
|
+
require 'sdl4r/relative_timezone'
|
28
|
+
|
29
|
+
require "sdl4r/sdl_test_case"
|
30
|
+
|
31
|
+
class RelativeTimezoneTest < Test::Unit::TestCase
|
32
|
+
include SdlTestCase
|
33
|
+
|
34
|
+
def test_get
|
35
|
+
TZInfo::Timezone.get("GMT")
|
36
|
+
tz = SDL4R::RelativeTimezone.get("GMT")
|
37
|
+
|
38
|
+
assert_equal "GMT", tz.identifier
|
39
|
+
assert !tz.is_a?(SDL4R::RelativeTimezone)
|
40
|
+
|
41
|
+
tz = SDL4R::RelativeTimezone.get("GMT+01:30")
|
42
|
+
assert_equal "GMT+01:30", tz.identifier
|
43
|
+
assert_kind_of SDL4R::RelativeTimezone, tz
|
44
|
+
assert_equal 5400, tz.relative_offset
|
45
|
+
|
46
|
+
tz_period = tz.period_for_utc(Time.utc(2001, 1, 25, 21, 45, 50, 123))
|
47
|
+
assert_equal 5400, tz_period.utc_offset
|
48
|
+
assert_equal 0, tz_period.std_offset
|
49
|
+
assert_equal :"GMT+01:30", tz_period.abbreviation
|
50
|
+
|
51
|
+
tz = SDL4R::RelativeTimezone.get("CET-02:00")
|
52
|
+
assert_equal "CET-2", tz.identifier
|
53
|
+
assert_kind_of SDL4R::RelativeTimezone, tz
|
54
|
+
assert_equal(-7200, tz.relative_offset)
|
55
|
+
|
56
|
+
tz_period = tz.period_for_utc(Time.utc(2001, 1, 25, 21, 45, 50, 123))
|
57
|
+
assert_equal 3600 - 7200, tz_period.utc_offset
|
58
|
+
assert_equal 0, tz_period.std_offset
|
59
|
+
assert_equal :"CET-2", tz_period.abbreviation
|
60
|
+
|
61
|
+
tz = SDL4R::RelativeTimezone.get("Europe/Paris+01:40")
|
62
|
+
assert_equal "Europe/Paris+01:40", tz.identifier
|
63
|
+
assert_kind_of SDL4R::RelativeTimezone, tz
|
64
|
+
assert_equal 6000, tz.relative_offset
|
65
|
+
|
66
|
+
tz_period = tz.period_for_local(Time.utc(2001, 1, 1, 21, 45, 50, 123))
|
67
|
+
assert_equal 3600 + 6000, tz_period.utc_offset
|
68
|
+
assert_equal 3600 + 6000, tz_period.utc_total_offset
|
69
|
+
assert_equal 0, tz_period.std_offset
|
70
|
+
assert_equal :"CET+01:40", tz_period.abbreviation
|
71
|
+
|
72
|
+
tz_period = tz.period_for_local(Time.utc(2001, 7, 1, 21, 45, 50, 123))
|
73
|
+
assert_equal 3600 + 6000, tz_period.utc_offset
|
74
|
+
assert_equal 7200 + 6000, tz_period.utc_total_offset
|
75
|
+
assert_equal 3600, tz_period.std_offset
|
76
|
+
assert_equal :"CEST+01:40", tz_period.abbreviation
|
77
|
+
|
78
|
+
tz = SDL4R::RelativeTimezone.get("GMT+7")
|
79
|
+
assert_equal "GMT+7", tz.identifier
|
80
|
+
|
81
|
+
tz = SDL4R::RelativeTimezone.get("GMT-07")
|
82
|
+
assert_equal "GMT-7", tz.identifier
|
83
|
+
|
84
|
+
tz = SDL4R::RelativeTimezone.get("GMT+7:32")
|
85
|
+
assert_equal "GMT+07:32", tz.identifier
|
86
|
+
|
87
|
+
tz = SDL4R::RelativeTimezone.get("GMT-7:32")
|
88
|
+
assert_equal "GMT-07:32", tz.identifier
|
89
|
+
|
90
|
+
# Test abbreviations
|
91
|
+
tz = SDL4R::RelativeTimezone.get("JST")
|
92
|
+
assert_equal "JST", tz.identifier
|
93
|
+
|
94
|
+
tz = SDL4R::RelativeTimezone.get("JST+8")
|
95
|
+
assert_equal "JST+8", tz.identifier
|
96
|
+
|
97
|
+
assert_raise TZInfo::InvalidTimezoneIdentifier do
|
98
|
+
SDL4R::RelativeTimezone.get("LMT")
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
data/test/sdl4r/sdl4r_test.rb
CHANGED
@@ -1,529 +1,612 @@
|
|
1
|
-
#!/usr/bin/env ruby -w
|
2
|
-
# encoding: UTF-8
|
3
|
-
|
4
|
-
#--
|
5
|
-
#
|
6
|
-
# Simple Declarative Language (SDL) for Ruby
|
7
|
-
# Copyright 2005 Ikayzo, inc.
|
8
|
-
#
|
9
|
-
# This program is free software. You can distribute or modify it under the
|
10
|
-
# terms of the GNU Lesser General Public License version 2.1 as published by
|
11
|
-
# the Free Software Foundation.
|
12
|
-
#
|
13
|
-
# This program is distributed AS IS and WITHOUT WARRANTY. OF ANY KIND,
|
14
|
-
# INCLUDING MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
|
15
|
-
# See the GNU Lesser General Public License for more details.
|
16
|
-
#
|
17
|
-
# You should have received a copy of the GNU Lesser General Public License
|
18
|
-
# along with this program; if not, contact the Free Software Foundation, Inc.,
|
19
|
-
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
20
|
-
#++
|
21
|
-
|
22
|
-
|
23
|
-
if
|
24
|
-
|
25
|
-
|
26
|
-
end
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
require '
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
require '
|
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
|
-
t2.
|
114
|
-
assert_not_equal(t1, t2, TAG)
|
115
|
-
|
116
|
-
|
117
|
-
t2.set_attribute("
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
end
|
131
|
-
|
132
|
-
def
|
133
|
-
check_tag_write_parse @@
|
134
|
-
end
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
#
|
141
|
-
#
|
142
|
-
#
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
#
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
assert_equal(root.child("
|
166
|
-
assert_equal(root.child("
|
167
|
-
assert_equal(root.child("
|
168
|
-
assert_equal(root.child("
|
169
|
-
assert_equal(
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
assert_equal(
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
assert_equal(root.child("
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
assert_equal(root.child("
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
root
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
assert_equal(root.child("
|
193
|
-
assert_equal(root.child("
|
194
|
-
assert_equal(root.child("
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
root
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
root
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
assert_equal(root.child("
|
216
|
-
assert_equal(root.child("
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
assert_equal(root.child("
|
222
|
-
assert_equal(root.child("
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
assert_equal(root.child("
|
227
|
-
assert_equal(root.child("
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
assert_equal(
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
assert_equal(
|
236
|
-
root.child("
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
root
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
root
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
root
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
assert_equal(
|
271
|
-
root.child("
|
272
|
-
assert_equal(
|
273
|
-
root.child("
|
274
|
-
assert_equal(
|
275
|
-
root.child("
|
276
|
-
assert_equal(
|
277
|
-
root.child("
|
278
|
-
assert_equal(
|
279
|
-
root.child("
|
280
|
-
assert_equal(
|
281
|
-
root.child("
|
282
|
-
assert_equal(
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
assert_equal(
|
287
|
-
root.child("
|
288
|
-
|
289
|
-
|
290
|
-
assert_equal(
|
291
|
-
root.child("
|
292
|
-
|
293
|
-
|
294
|
-
assert_equal(
|
295
|
-
root.child("
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
assert_equal(root.child("
|
309
|
-
DateTime.civil(2005,12,31,
|
310
|
-
assert_equal(root.child("
|
311
|
-
DateTime.civil(1882,5,2,
|
312
|
-
assert_equal(root.child("
|
313
|
-
DateTime.civil(2005,12,31,
|
314
|
-
assert_equal(root.child("
|
315
|
-
DateTime.civil(1882,5,2,
|
316
|
-
|
317
|
-
|
318
|
-
assert_equal(root.child("
|
319
|
-
DateTime.civil(1882,5,2,12,30,23123.to_r/1000,
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
"
|
337
|
-
"
|
338
|
-
"
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
root
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
assert_equal(root.child("
|
362
|
-
assert_equal(root.child("
|
363
|
-
assert_equal(
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
assert_equal(
|
368
|
-
root.child("
|
369
|
-
[nil,
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
assert_equal(root.child("
|
392
|
-
assert_equal(root.child("
|
393
|
-
assert_equal(root.child("
|
394
|
-
assert_equal(root.child("
|
395
|
-
assert_equal(root.child("
|
396
|
-
assert_equal(root.child("
|
397
|
-
assert_equal(root.child("
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
root
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
assert_equal(
|
416
|
-
|
417
|
-
|
418
|
-
{"name"=>"joe","
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
assert_equal(root.child("
|
433
|
-
assert_equal(
|
434
|
-
|
435
|
-
|
436
|
-
assert_equal(root.child("
|
437
|
-
|
438
|
-
|
439
|
-
assert_equal(
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
VALUES_AND_ATTRIBUTES)
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
VALUES_AND_ATTRIBUTES)
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
VALUES_AND_ATTRIBUTES)
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
VALUES_AND_ATTRIBUTES)
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
VALUES_AND_ATTRIBUTES)
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
assert_equal(
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
assert_equal(
|
498
|
-
assert_equal(
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
1
|
+
#!/usr/bin/env ruby -w
|
2
|
+
# encoding: UTF-8
|
3
|
+
|
4
|
+
#--
|
5
|
+
#
|
6
|
+
# Simple Declarative Language (SDL) for Ruby
|
7
|
+
# Copyright 2005 Ikayzo, inc.
|
8
|
+
#
|
9
|
+
# This program is free software. You can distribute or modify it under the
|
10
|
+
# terms of the GNU Lesser General Public License version 2.1 as published by
|
11
|
+
# the Free Software Foundation.
|
12
|
+
#
|
13
|
+
# This program is distributed AS IS and WITHOUT WARRANTY. OF ANY KIND,
|
14
|
+
# INCLUDING MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
|
15
|
+
# See the GNU Lesser General Public License for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU Lesser General Public License
|
18
|
+
# along with this program; if not, contact the Free Software Foundation, Inc.,
|
19
|
+
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
20
|
+
#++
|
21
|
+
|
22
|
+
# Work-around a bug in NetBeans (http://netbeans.org/bugzilla/show_bug.cgi?id=188653)
|
23
|
+
if ENV["NB_EXEC_EXTEXECUTION_PROCESS_UUID"]
|
24
|
+
$:[0] = File.join(File.dirname(__FILE__),'../../lib')
|
25
|
+
$:.unshift(File.join(File.dirname(__FILE__),'../../test'))
|
26
|
+
end
|
27
|
+
|
28
|
+
if RUBY_VERSION < '1.9.0'
|
29
|
+
$KCODE = 'u'
|
30
|
+
require 'jcode'
|
31
|
+
end
|
32
|
+
|
33
|
+
module SDL4R
|
34
|
+
|
35
|
+
require 'fileutils'
|
36
|
+
require 'pathname'
|
37
|
+
require 'date'
|
38
|
+
require 'test/unit'
|
39
|
+
|
40
|
+
require 'sdl4r'
|
41
|
+
|
42
|
+
require 'sdl4r/sdl_test_case'
|
43
|
+
|
44
|
+
class SDL4RTest < Test::Unit::TestCase
|
45
|
+
include SdlTestCase
|
46
|
+
|
47
|
+
# Tag datastructure tests
|
48
|
+
TAG = "Tag"
|
49
|
+
TAG_WRITE_PARSE = "Tag Write Parse"
|
50
|
+
|
51
|
+
# Basic Types Tests
|
52
|
+
STRING_DECLARATIONS = "String Declarations"
|
53
|
+
CHARACTER_DECLARATIONS = "Character Declarations"
|
54
|
+
NUMBER_DECLARATIONS = "Number Declarations"
|
55
|
+
BOOLEAN_DECLARATIONS = "Boolean Declarations"
|
56
|
+
NULL_DECLARATION = "Null Declaration"
|
57
|
+
DATE_DECLARATIONS = "Date Declarations"
|
58
|
+
TIME_SPAN_DECLARATIONS = "Time Span Declarations"
|
59
|
+
DATE_TIME_DECLARATIONS = "Date Time Declarations"
|
60
|
+
BINARY_DECLARATIONS = "Binary Declarations"
|
61
|
+
|
62
|
+
# Structure Tests
|
63
|
+
EMPTY_TAG = "Empty Tag"
|
64
|
+
VALUES = "Values"
|
65
|
+
ATTRIBUTES = "Attributes"
|
66
|
+
VALUES_AND_ATTRIBUTES = "Values and Attributes"
|
67
|
+
CHILDREN = "Children"
|
68
|
+
NAMESPACES = "Namespaces"
|
69
|
+
|
70
|
+
|
71
|
+
def assert_tags_equal(expected, actual, message)
|
72
|
+
if expected != actual
|
73
|
+
assert_equal(expected.to_s, actual.to_s, message)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
# Returns a Pathname giving the location of the specified relative +filename+.
|
78
|
+
#
|
79
|
+
# +filename+:: path to a file relatively to this source file
|
80
|
+
#
|
81
|
+
def get_test_sdl_file_path(filename)
|
82
|
+
dir = File.dirname(__FILE__)
|
83
|
+
return Pathname.new(dir + '/' + filename)
|
84
|
+
end
|
85
|
+
|
86
|
+
@@root_basic_types = nil
|
87
|
+
@@root_structures = nil
|
88
|
+
|
89
|
+
def setup
|
90
|
+
super
|
91
|
+
|
92
|
+
@@root_basic_types ||= SDL4R::read(get_test_sdl_file_path("test_basic_types.sdl"))
|
93
|
+
@@root_structures ||= SDL4R::read(get_test_sdl_file_path("test_structures.sdl"))
|
94
|
+
end
|
95
|
+
|
96
|
+
######################################
|
97
|
+
# Tag Tests
|
98
|
+
######################################
|
99
|
+
def test_tag
|
100
|
+
# Test to make sure Tag ignores the order in which attributes are
|
101
|
+
# added.
|
102
|
+
t1 = Tag.new("test")
|
103
|
+
t1.set_attribute("foo", "bar")
|
104
|
+
t1.set_attribute("john", "doe")
|
105
|
+
|
106
|
+
t2 = Tag.new("test")
|
107
|
+
t2.set_attribute("john", "doe")
|
108
|
+
t2.set_attribute("foo", "bar")
|
109
|
+
|
110
|
+
assert_tags_equal(t1, t2, TAG)
|
111
|
+
|
112
|
+
# Making sure tags with different structures return false from .equals
|
113
|
+
t2.value = "item"
|
114
|
+
assert_not_equal(t1, t2, TAG)
|
115
|
+
|
116
|
+
t2.remove_value("item")
|
117
|
+
t2.set_attribute("another", "attribute")
|
118
|
+
assert_not_equal(t1, t2, TAG)
|
119
|
+
|
120
|
+
# Checking attributes namespaces
|
121
|
+
t2.set_attribute("name", "bill")
|
122
|
+
t2.set_attribute("private", "smoker", true)
|
123
|
+
t2.set_attribute("public", "hobby", "hiking")
|
124
|
+
t2.set_attribute("private", "nickname", "tubby")
|
125
|
+
|
126
|
+
assert_equal(
|
127
|
+
t2.attributes("private"),
|
128
|
+
{ "smoker" => true, "nickname" => "tubby" },
|
129
|
+
"attributes()")
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_tag_write_parse_basic_types
|
133
|
+
check_tag_write_parse @@root_basic_types
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_tag_write_parse_structures
|
137
|
+
check_tag_write_parse @@root_structures
|
138
|
+
end
|
139
|
+
|
140
|
+
#
|
141
|
+
# Does a to_s/parse test on the specified Tag (+root+)
|
142
|
+
#
|
143
|
+
def check_tag_write_parse(root)
|
144
|
+
# puts '========================================'
|
145
|
+
# puts root.to_s
|
146
|
+
# puts '========================================'
|
147
|
+
|
148
|
+
write_parse_root = Tag.new("test").read(root.to_s).child("root")
|
149
|
+
|
150
|
+
# File.open("d:\\dev\\tmp\\root.sdl", "w") { |io| io.write(root.to_string) }
|
151
|
+
# File.open("d:\\dev\\tmp\\root_reparsed.sdl", "w") { |io| io.write(write_parse_root.to_string) }
|
152
|
+
|
153
|
+
assert_tags_equal(root, write_parse_root, "write/parse")
|
154
|
+
end
|
155
|
+
|
156
|
+
######################################
|
157
|
+
# Basic Types Tests
|
158
|
+
######################################
|
159
|
+
|
160
|
+
def test_strings
|
161
|
+
root = @@root_basic_types
|
162
|
+
|
163
|
+
# Doing String tests...
|
164
|
+
# Doing basic tests including new line handling...
|
165
|
+
assert_equal(root.child("string1").value, "hello", STRING_DECLARATIONS)
|
166
|
+
assert_equal(root.child("string2").value, "hi", STRING_DECLARATIONS)
|
167
|
+
assert_equal(root.child("string3").value, "aloha", STRING_DECLARATIONS)
|
168
|
+
assert_equal(root.child("string4").value, "hi there", STRING_DECLARATIONS)
|
169
|
+
assert_equal(root.child("string5").value, "hi there joe", STRING_DECLARATIONS)
|
170
|
+
assert_equal(root.child("string6").value, "line1\nline2", STRING_DECLARATIONS)
|
171
|
+
assert_equal(root.child("string7").value, "line1\nline2", STRING_DECLARATIONS)
|
172
|
+
assert_equal(root.child("string8").value, "line1\nline2\nline3", STRING_DECLARATIONS)
|
173
|
+
assert_equal(
|
174
|
+
root.child("string9").value,
|
175
|
+
"Anything should go in this line without escapes \\ \\\\ \\n " +
|
176
|
+
"\\t \" \"\" ' ''", STRING_DECLARATIONS)
|
177
|
+
assert_equal(root.child("string10").value, "escapes \"\\\n\t", STRING_DECLARATIONS)
|
178
|
+
|
179
|
+
# Checking unicode strings...
|
180
|
+
assert_equal(root.child("japanese.hello").value, "日本語", STRING_DECLARATIONS)
|
181
|
+
assert_equal(root.child("korean.hello").value, "여보세요", STRING_DECLARATIONS)
|
182
|
+
assert_equal(root.child("russian.hello").value, "здравствулте", STRING_DECLARATIONS)
|
183
|
+
|
184
|
+
# More new line tests...
|
185
|
+
assert(root.child("xml").value.index("<text>Hi there!</text>") >= 0, STRING_DECLARATIONS)
|
186
|
+
assert_equal(root.child("line_test").value, "\nnew line above and below\n", STRING_DECLARATIONS)
|
187
|
+
end
|
188
|
+
|
189
|
+
def test_characters
|
190
|
+
root = @@root_basic_types
|
191
|
+
|
192
|
+
assert_equal(root.child("char1").value, 'a', CHARACTER_DECLARATIONS)
|
193
|
+
assert_equal(root.child("char2").value, 'A', CHARACTER_DECLARATIONS)
|
194
|
+
assert_equal(root.child("char3").value, '\\', CHARACTER_DECLARATIONS)
|
195
|
+
assert_equal(root.child("char4").value, "\n", CHARACTER_DECLARATIONS)
|
196
|
+
assert_equal(root.child("char5").value, "\t", CHARACTER_DECLARATIONS)
|
197
|
+
assert_equal(root.child("char6").value, '\'', CHARACTER_DECLARATIONS)
|
198
|
+
assert_equal(root.child("char7").value, '"', CHARACTER_DECLARATIONS)
|
199
|
+
end
|
200
|
+
|
201
|
+
def test_characters_unicode
|
202
|
+
root = @@root_basic_types
|
203
|
+
|
204
|
+
assert_equal(root.child("char8").value, "日", CHARACTER_DECLARATIONS) # \u65e5
|
205
|
+
assert_equal(root.child("char9").value, "여", CHARACTER_DECLARATIONS) # \uc5ec
|
206
|
+
assert_equal(root.child("char10").value, "з", CHARACTER_DECLARATIONS) # \u0437
|
207
|
+
end
|
208
|
+
|
209
|
+
def test_numbers
|
210
|
+
root = @@root_basic_types
|
211
|
+
|
212
|
+
# Testing ints...
|
213
|
+
assert_equal(root.child("int1").value, 0, NUMBER_DECLARATIONS)
|
214
|
+
assert_equal(root.child("int2").value, 5, NUMBER_DECLARATIONS)
|
215
|
+
assert_equal(root.child("int3").value, -100, NUMBER_DECLARATIONS)
|
216
|
+
assert_equal(root.child("int4").value, 234253532, NUMBER_DECLARATIONS)
|
217
|
+
|
218
|
+
# Testing longs...
|
219
|
+
assert_equal(root.child("long1").value, 0, NUMBER_DECLARATIONS)
|
220
|
+
assert_equal(root.child("long2").value, 5, NUMBER_DECLARATIONS)
|
221
|
+
assert_equal(root.child("long3").value, 5, NUMBER_DECLARATIONS)
|
222
|
+
assert_equal(root.child("long4").value, 3904857398753453453, NUMBER_DECLARATIONS)
|
223
|
+
|
224
|
+
# Testing floats...
|
225
|
+
assert_equal(root.child("float1").value, 1, NUMBER_DECLARATIONS)
|
226
|
+
assert_equal(root.child("float2").value, 0.23, NUMBER_DECLARATIONS)
|
227
|
+
assert_equal(root.child("float3").value, -0.34, NUMBER_DECLARATIONS)
|
228
|
+
|
229
|
+
# Testing doubles..."
|
230
|
+
assert_equal(root.child("double1").value, 2, NUMBER_DECLARATIONS)
|
231
|
+
assert_equal(root.child("double2").value, -0.234, NUMBER_DECLARATIONS)
|
232
|
+
assert_equal(root.child("double3").value, 2.34, NUMBER_DECLARATIONS)
|
233
|
+
|
234
|
+
# Testing decimals (BigDouble in Java)...
|
235
|
+
assert_equal(
|
236
|
+
root.child("decimal1").value, 0, NUMBER_DECLARATIONS)
|
237
|
+
assert_equal(
|
238
|
+
root.child("decimal2").value, 11.111111, NUMBER_DECLARATIONS)
|
239
|
+
assert_equal(
|
240
|
+
root.child("decimal3").value, 234535.3453453453454345345341242343, NUMBER_DECLARATIONS)
|
241
|
+
end
|
242
|
+
|
243
|
+
def test_booleans
|
244
|
+
root = @@root_basic_types
|
245
|
+
|
246
|
+
assert_equal(root.child("light-on").value, true, BOOLEAN_DECLARATIONS)
|
247
|
+
assert_equal(root.child("light-off").value, false, BOOLEAN_DECLARATIONS)
|
248
|
+
assert_equal(root.child("light1").value, true, BOOLEAN_DECLARATIONS)
|
249
|
+
assert_equal(root.child("light2").value, false, BOOLEAN_DECLARATIONS)
|
250
|
+
end
|
251
|
+
|
252
|
+
def test_null
|
253
|
+
root = @@root_basic_types
|
254
|
+
|
255
|
+
assert_equal(root.child("nothing").value, nil, NULL_DECLARATION)
|
256
|
+
end
|
257
|
+
|
258
|
+
def test_dates
|
259
|
+
root = @@root_basic_types
|
260
|
+
|
261
|
+
assert_equal(root.child("date1").value, Date.civil(2005, 12, 31), DATE_DECLARATIONS)
|
262
|
+
assert_equal(root.child("date2").value, Date.civil(1882, 5, 2), DATE_DECLARATIONS)
|
263
|
+
assert_equal(root.child("date3").value, Date.civil(1882, 5, 2), DATE_DECLARATIONS)
|
264
|
+
assert_equal(root.child("_way_back").value, Date.civil(582, 9, 16), DATE_DECLARATIONS)
|
265
|
+
end
|
266
|
+
|
267
|
+
def test_time_spans
|
268
|
+
root = @@root_basic_types
|
269
|
+
|
270
|
+
assert_equal(
|
271
|
+
root.child("time1").value, SdlTimeSpan.new(0,12,30,0,0), TIME_SPAN_DECLARATIONS)
|
272
|
+
assert_equal(
|
273
|
+
root.child("time2").value, SdlTimeSpan.new(0,24,0,0,0), TIME_SPAN_DECLARATIONS)
|
274
|
+
assert_equal(
|
275
|
+
root.child("time3").value, SdlTimeSpan.new(0,1,0,0,0), TIME_SPAN_DECLARATIONS)
|
276
|
+
assert_equal(
|
277
|
+
root.child("time4").value, SdlTimeSpan.new(0,1,0,0,0), TIME_SPAN_DECLARATIONS)
|
278
|
+
assert_equal(
|
279
|
+
root.child("time5").value, SdlTimeSpan.new(0,12,30,2,0), TIME_SPAN_DECLARATIONS)
|
280
|
+
assert_equal(
|
281
|
+
root.child("time6").value, SdlTimeSpan.new(0,12,30,23,0), TIME_SPAN_DECLARATIONS)
|
282
|
+
assert_equal(
|
283
|
+
SdlTimeSpan.new(0,12,30,23,100), root.child("time7").value, TIME_SPAN_DECLARATIONS)
|
284
|
+
assert_equal(
|
285
|
+
root.child("time8").value, SdlTimeSpan.new(0,12,30,23,120), TIME_SPAN_DECLARATIONS)
|
286
|
+
assert_equal(
|
287
|
+
root.child("time9").value, SdlTimeSpan.new(0,12,30,23,123), TIME_SPAN_DECLARATIONS)
|
288
|
+
|
289
|
+
# Checking time spans with days...
|
290
|
+
assert_equal(
|
291
|
+
root.child("time10").value, SdlTimeSpan.new(34,12,30,23,100), TIME_SPAN_DECLARATIONS)
|
292
|
+
assert_equal(
|
293
|
+
root.child("time11").value, SdlTimeSpan.new(1,12,30,0,0), TIME_SPAN_DECLARATIONS)
|
294
|
+
assert_equal(
|
295
|
+
root.child("time12").value, SdlTimeSpan.new(5,12,30,23,123), TIME_SPAN_DECLARATIONS)
|
296
|
+
|
297
|
+
# Checking negative time spans...
|
298
|
+
assert_equal(
|
299
|
+
root.child("time13").value, SdlTimeSpan.new(0,-12,-30,-23,-123), TIME_SPAN_DECLARATIONS)
|
300
|
+
assert_equal(
|
301
|
+
root.child("time14").value, SdlTimeSpan.new(-5,-12,-30,-23,-123), TIME_SPAN_DECLARATIONS)
|
302
|
+
end
|
303
|
+
|
304
|
+
def test_date_times
|
305
|
+
root = @@root_basic_types
|
306
|
+
local_offset = DateTime.now.offset
|
307
|
+
|
308
|
+
assert_equal(root.child("date_time1").value,
|
309
|
+
DateTime.civil(2005,12,31,12,30,0, local_offset), DATE_TIME_DECLARATIONS)
|
310
|
+
assert_equal(root.child("date_time2").value,
|
311
|
+
DateTime.civil(1882,5,2,12,30,0, local_offset), DATE_TIME_DECLARATIONS)
|
312
|
+
assert_equal(root.child("date_time3").value,
|
313
|
+
DateTime.civil(2005,12,31,1,0,0, local_offset), DATE_TIME_DECLARATIONS)
|
314
|
+
assert_equal(root.child("date_time4").value,
|
315
|
+
DateTime.civil(1882,5,2,1,0,0, local_offset), DATE_TIME_DECLARATIONS)
|
316
|
+
assert_equal(root.child("date_time5").value,
|
317
|
+
DateTime.civil(2005,12,31,12,30,2312.to_r/100, local_offset), DATE_TIME_DECLARATIONS)
|
318
|
+
assert_equal(root.child("date_time6").value,
|
319
|
+
DateTime.civil(1882,5,2,12,30,23123.to_r/1000, local_offset), DATE_TIME_DECLARATIONS)
|
320
|
+
|
321
|
+
# Checking timezones...
|
322
|
+
assert_equal(root.child("date_time7").value,
|
323
|
+
DateTime.civil(1882,5,2,12,30,23123.to_r/1000,"JST"), DATE_TIME_DECLARATIONS)
|
324
|
+
assert_equal(root.child("date_time8").value,
|
325
|
+
DateTime.civil(985,04,11,12,30,23123.to_r/1000,"PST"), DATE_TIME_DECLARATIONS)
|
326
|
+
end
|
327
|
+
|
328
|
+
def test_binaries
|
329
|
+
root = @@root_basic_types
|
330
|
+
|
331
|
+
assert_equal(SDL4R::SdlBinary("hi"), root.child("hi").value, BINARY_DECLARATIONS)
|
332
|
+
assert_equal(
|
333
|
+
SDL4R::SdlBinary("hi"), root.child("hi").value, BINARY_DECLARATIONS)
|
334
|
+
assert_equal(
|
335
|
+
SdlBinary.decode64(
|
336
|
+
"iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAKnRFWHRDcmVhdGlvbiBUaW1l" +
|
337
|
+
"AERpIDQgTXJ6IDIwMDMgMDA6MjQ6MDQgKzAxMDDdSQ6OAAAAB3RJTUUH0wMEAAcllPlrJgAA" +
|
338
|
+
"AAlwSFlzAAAK8AAACvABQqw0mAAAAARnQU1BAACxjwv8YQUAAADQSURBVHjaY2CgEDCCyZn/" +
|
339
|
+
"3YHkDhL1ejCkM+5kgXJ2zDQmXueShwwMh9+ALWSEGcCQfhZIvHlDnAk8PAwMHBxgJtyAa7bX" +
|
340
|
+
"UdT8/cvA8Ps3hP7zB4FBYn/+vGbweqyJaoCmpiaKASDFv35BNMBoZMzwGKKOidJYoNgAuBdm" +
|
341
|
+
"naXQgHRKDfgagxD89w8S+iAaFICwGIHFAgjrHUczAByySAaAMEgDLBphhv7/D8EYLgDZhAxA" +
|
342
|
+
"mkAKYYbAMMwwDAOQXYDuDXRXgDC6AR7SW8jITNQAACjZgdj4VjlqAAAAAElFTkSuQmCC"
|
343
|
+
),
|
344
|
+
root.child("png").value,
|
345
|
+
BINARY_DECLARATIONS)
|
346
|
+
end
|
347
|
+
|
348
|
+
######################################
|
349
|
+
# Structure Tests (values, attributes, children)
|
350
|
+
######################################
|
351
|
+
|
352
|
+
def test_empty_tag
|
353
|
+
root = @@root_structures
|
354
|
+
assert_equal(root.child("empty_tag"), Tag.new("empty_tag"), EMPTY_TAG)
|
355
|
+
end
|
356
|
+
|
357
|
+
def test_values
|
358
|
+
root = @@root_structures
|
359
|
+
local_offset = DateTime.now.offset
|
360
|
+
|
361
|
+
assert_equal(root.child("values1").values, ["hi"], VALUES)
|
362
|
+
assert_equal(root.child("values2").values, ["hi","ho"], VALUES)
|
363
|
+
assert_equal(root.child("values3").values, [1, "ho"], VALUES)
|
364
|
+
assert_equal(root.child("values4").values, ["hi",5], VALUES)
|
365
|
+
assert_equal(root.child("values5").values, [1,2], VALUES)
|
366
|
+
assert_equal(root.child("values6").values, [1,2,3], VALUES)
|
367
|
+
assert_equal(
|
368
|
+
root.child("values7").values,
|
369
|
+
[nil,"foo",false,Date.civil(1980,12,5)],
|
370
|
+
VALUES)
|
371
|
+
assert_equal(
|
372
|
+
root.child("values8").values,
|
373
|
+
[nil, "foo", false, DateTime.civil(1980,12,5,12,30,0,local_offset),
|
374
|
+
"there", SdlTimeSpan.new(0,15,23,12,234)],
|
375
|
+
VALUES)
|
376
|
+
assert_equal(
|
377
|
+
root.child("values9").values,
|
378
|
+
[nil, "foo", false, DateTime.civil(1980,12,5,12,30,0,local_offset),
|
379
|
+
"there", DateTime.civil(1989,8,12,15,23,12234.to_r/1000,"JST")],
|
380
|
+
VALUES)
|
381
|
+
assert_equal(
|
382
|
+
root.child("values10").values,
|
383
|
+
[nil, "foo", false, DateTime.civil(1980,12,5,12,30,0,local_offset),
|
384
|
+
"there", SdlTimeSpan.new(0,15,23,12,234), "more stuff"],
|
385
|
+
VALUES)
|
386
|
+
assert_equal(
|
387
|
+
root.child("values11").values,
|
388
|
+
[nil, "foo", false, DateTime.civil(1980,12,5,12,30,0,local_offset),
|
389
|
+
"there", SdlTimeSpan.new(123,15,23,12,234), "more stuff here"],
|
390
|
+
VALUES)
|
391
|
+
assert_equal(root.child("values12").values, [1,3], VALUES)
|
392
|
+
assert_equal(root.child("values13").values, [1,3], VALUES)
|
393
|
+
assert_equal(root.child("values14").values, [1,3], VALUES)
|
394
|
+
assert_equal(root.child("values15").values, [1,2,4,5,6], VALUES)
|
395
|
+
assert_equal(root.child("values16").values, [1,2,5], VALUES)
|
396
|
+
assert_equal(root.child("values17").values, [1,2,5], VALUES)
|
397
|
+
assert_equal(root.child("values18").values, [1,2,7], VALUES)
|
398
|
+
assert_equal(root.child("values19").values, [1,3,5,7], VALUES)
|
399
|
+
assert_equal(root.child("values20").values, [1,3,5], VALUES)
|
400
|
+
assert_equal(root.child("values21").values, [1,3,5], VALUES)
|
401
|
+
assert_equal(root.child("values22").values, ["hi","ho","ho",5,"hi"], VALUES)
|
402
|
+
end
|
403
|
+
|
404
|
+
def test_attributes
|
405
|
+
root = @@root_structures
|
406
|
+
|
407
|
+
assert_equal(
|
408
|
+
root.child("atts1").attributes, {"name" => "joe"}, ATTRIBUTES)
|
409
|
+
assert_equal(root.child("atts2").attributes, {"size" => 5}, ATTRIBUTES)
|
410
|
+
assert_equal(
|
411
|
+
root.child("atts3").attributes, {"name" => "joe","size" => 5}, ATTRIBUTES)
|
412
|
+
assert_equal(
|
413
|
+
root.child("atts4").attributes, {"name"=>"joe","size"=>5,"smoker"=>false},
|
414
|
+
ATTRIBUTES)
|
415
|
+
assert_equal(
|
416
|
+
root.child("atts5").attributes, {"name"=>"joe","smoker"=>false}, ATTRIBUTES)
|
417
|
+
assert_equal(
|
418
|
+
root.child("atts6").attributes, {"name"=>"joe","smoker"=>false}, ATTRIBUTES)
|
419
|
+
assert_equal(root.child("atts7").attributes, {"name"=>"joe"}, ATTRIBUTES)
|
420
|
+
assert_equal(
|
421
|
+
root.child("atts8").attributes,
|
422
|
+
{"name"=>"joe","size"=>5,"smoker"=>false,
|
423
|
+
"text"=>"hi","birthday"=>Date.civil(1972,5,23)},
|
424
|
+
ATTRIBUTES)
|
425
|
+
assert_equal(
|
426
|
+
root.child("atts9").attribute("key"), SDL4R::SdlBinary("mykey"), ATTRIBUTES)
|
427
|
+
end
|
428
|
+
|
429
|
+
def test_values_and_attributes
|
430
|
+
root = @@root_structures
|
431
|
+
|
432
|
+
assert_equal(root.child("valatts1").values, ["joe"], VALUES_AND_ATTRIBUTES)
|
433
|
+
assert_equal(
|
434
|
+
root.child("valatts1").attributes, {"size"=>5}, VALUES_AND_ATTRIBUTES)
|
435
|
+
|
436
|
+
assert_equal(root.child("valatts2").values, ["joe"], VALUES_AND_ATTRIBUTES)
|
437
|
+
assert_equal(root.child("valatts2").attributes, {"size"=>5}, VALUES_AND_ATTRIBUTES)
|
438
|
+
|
439
|
+
assert_equal(root.child("valatts3").values, ["joe"], VALUES_AND_ATTRIBUTES)
|
440
|
+
assert_equal(root.child("valatts3").attributes, {"size"=>5}, VALUES_AND_ATTRIBUTES)
|
441
|
+
|
442
|
+
assert_equal(root.child("valatts4").values, ["joe"], VALUES_AND_ATTRIBUTES)
|
443
|
+
assert_equal(
|
444
|
+
root.child("valatts4").attributes,
|
445
|
+
{"size"=>5, "weight"=>160, "hat"=>"big"},
|
446
|
+
VALUES_AND_ATTRIBUTES)
|
447
|
+
|
448
|
+
assert_equal(
|
449
|
+
root.child("valatts5").values, ["joe", "is a\n nice guy"], VALUES_AND_ATTRIBUTES)
|
450
|
+
assert_equal(
|
451
|
+
root.child("valatts5").attributes,
|
452
|
+
{"size"=>5, "smoker"=>false},
|
453
|
+
VALUES_AND_ATTRIBUTES)
|
454
|
+
|
455
|
+
assert_equal(
|
456
|
+
root.child("valatts6").values, ["joe", "is a\n nice guy"], VALUES_AND_ATTRIBUTES)
|
457
|
+
assert_equal(
|
458
|
+
root.child("valatts6").attributes,
|
459
|
+
{"size"=>5, "house"=>"big and\n blue"},
|
460
|
+
VALUES_AND_ATTRIBUTES)
|
461
|
+
|
462
|
+
#####
|
463
|
+
|
464
|
+
assert_equal(
|
465
|
+
root.child("valatts7").values, ["joe", "is a\n nice guy"], VALUES_AND_ATTRIBUTES)
|
466
|
+
assert_equal(
|
467
|
+
root.child("valatts7").attributes,
|
468
|
+
{"size"=>5, "smoker"=>false},
|
469
|
+
VALUES_AND_ATTRIBUTES)
|
470
|
+
|
471
|
+
assert_equal(
|
472
|
+
root.child("valatts8").values, ["joe", "is a\n nice guy"], VALUES_AND_ATTRIBUTES)
|
473
|
+
assert_equal(
|
474
|
+
root.child("valatts8").attributes,
|
475
|
+
{"size"=>5, "smoker"=>false},
|
476
|
+
VALUES_AND_ATTRIBUTES)
|
477
|
+
|
478
|
+
assert_equal(
|
479
|
+
root.child("valatts9").values,["joe", "is a\n nice guy"], VALUES_AND_ATTRIBUTES)
|
480
|
+
assert_equal(
|
481
|
+
root.child("valatts9").attributes,
|
482
|
+
{"size"=>5, "smoker"=>false},
|
483
|
+
VALUES_AND_ATTRIBUTES)
|
484
|
+
end
|
485
|
+
|
486
|
+
def test_children
|
487
|
+
root = @@root_structures
|
488
|
+
parent = root.child("parent")
|
489
|
+
|
490
|
+
assert_equal(parent.children.size, 2, CHILDREN)
|
491
|
+
assert_equal(parent.children[1].name, "daughter", CHILDREN)
|
492
|
+
|
493
|
+
grandparent = root.child("grandparent")
|
494
|
+
|
495
|
+
assert_equal(grandparent.children.size, 2, CHILDREN)
|
496
|
+
# recursive fetch of children
|
497
|
+
assert_equal(grandparent.children(true).size, 6, CHILDREN)
|
498
|
+
assert_equal(grandparent.children(true, "son").size, 2, CHILDREN)
|
499
|
+
|
500
|
+
grandparent2 = root.child("grandparent2")
|
501
|
+
assert_equal(grandparent2.children(true, "child").size, 5, CHILDREN)
|
502
|
+
assert_equal(
|
503
|
+
grandparent2.child(true, "daughter").attribute("birthday"),
|
504
|
+
Date.civil(1976,04,18),
|
505
|
+
CHILDREN)
|
506
|
+
|
507
|
+
files = root.child("files")
|
508
|
+
|
509
|
+
assert_equal(
|
510
|
+
["c:/file1.txt", "c:/file2.txt", "c:/folder"],
|
511
|
+
files.children_values("content"),
|
512
|
+
CHILDREN)
|
513
|
+
|
514
|
+
matrix = root.child("matrix")
|
515
|
+
|
516
|
+
assert_equal([[1,2,3],[4,5,6]], matrix.children_values("content"), CHILDREN)
|
517
|
+
end
|
518
|
+
|
519
|
+
def test_namespaces
|
520
|
+
root = @@root_structures
|
521
|
+
assert_equal(8, root.children(true, "person", nil).size, NAMESPACES)
|
522
|
+
|
523
|
+
grandparent3 = root.child("grandparent3")
|
524
|
+
|
525
|
+
# get only the attributes for Akiko in the public namespace
|
526
|
+
assert_equal(
|
527
|
+
{"name"=>"Akiko", "birthday"=>Date.civil(1976,04,18)},
|
528
|
+
grandparent3.child(true, "daughter").attributes("public"),
|
529
|
+
NAMESPACES)
|
530
|
+
end
|
531
|
+
|
532
|
+
def test_validate_identifier
|
533
|
+
assert_nothing_raised { SDL4R::validate_identifier('myName') }
|
534
|
+
assert_nothing_raised { SDL4R::validate_identifier('my-name') }
|
535
|
+
assert_nothing_raised { SDL4R::validate_identifier('my_name') }
|
536
|
+
assert_nothing_raised { SDL4R::validate_identifier('_my-name') }
|
537
|
+
assert_nothing_raised { SDL4R::validate_identifier('my_name_') }
|
538
|
+
assert_nothing_raised { SDL4R::validate_identifier('com.ikayzo.foo') }
|
539
|
+
assert_nothing_raised { SDL4R::validate_identifier('com.ikayzo.foo$1') }
|
540
|
+
|
541
|
+
if SDL4R::supports_unicode_identifiers?
|
542
|
+
assert_nothing_raised { SDL4R::validate_identifier('まName') }
|
543
|
+
assert_nothing_raised { SDL4R::validate_identifier('myNäme') }
|
544
|
+
assert_nothing_raised { SDL4R::validate_identifier('なまえ') }
|
545
|
+
end
|
546
|
+
|
547
|
+
assert_raise ArgumentError do SDL4R::validate_identifier('1myName') end
|
548
|
+
assert_raise ArgumentError do SDL4R::validate_identifier('$myName') end
|
549
|
+
assert_raise ArgumentError do SDL4R::validate_identifier('.myName') end
|
550
|
+
assert_raise ArgumentError do SDL4R::validate_identifier('my Name') end
|
551
|
+
assert_raise ArgumentError do SDL4R::validate_identifier(' myName') end
|
552
|
+
assert_raise ArgumentError do SDL4R::validate_identifier('myName ') end
|
553
|
+
end
|
554
|
+
|
555
|
+
def test_coerce_or_fail
|
556
|
+
# Most basic types are considered to be tested in other tests (like ParserTest)
|
557
|
+
tag = Tag.new "tag1"
|
558
|
+
assert_raise ArgumentError do tag.add_value(Object.new) end
|
559
|
+
assert_raise ArgumentError do tag.add_value([1, 2, 3]) end
|
560
|
+
assert_raise ArgumentError do tag.add_value({"a" => "b"}) end
|
561
|
+
|
562
|
+
# check translation of Rational
|
563
|
+
tag.add_value(Rational(3, 10))
|
564
|
+
assert_equal [0.3], tag.values
|
565
|
+
end
|
566
|
+
|
567
|
+
def test_format_times
|
568
|
+
# Using DateTime
|
569
|
+
date = DateTime.civil(1989, 11, 13, 14, 15, 37)
|
570
|
+
assert_equal "1989/11/13 14:15:37", SDL4R::format(date)
|
571
|
+
|
572
|
+
date = DateTime.civil(1989, 11, 13, 14, 15, 37, Rational(-5, 24))
|
573
|
+
assert_equal "1989/11/13 14:15:37-GMT-05:00", SDL4R::format(date)
|
574
|
+
|
575
|
+
date = DateTime.civil(1989, 11, 13, 14, 15, 37055.to_r/1000)
|
576
|
+
assert_equal "1989/11/13 14:15:37.055", SDL4R::format(date)
|
577
|
+
|
578
|
+
date = DateTime.civil(1989, 11, 13, 14, 15, 37055.to_r/1000, Rational(6, 24))
|
579
|
+
assert_equal "1989/11/13 14:15:37.055-GMT+06:00", SDL4R::format(date)
|
580
|
+
|
581
|
+
# Using Time
|
582
|
+
time = Time.gm(1989, 11, 13, 14, 15, 37)
|
583
|
+
assert_equal "1989/11/13 14:15:37", SDL4R::format(time)
|
584
|
+
|
585
|
+
time = Time.gm(1989, 11, 13, 14, 15, 37, 55000)
|
586
|
+
assert_equal "1989/11/13 14:15:37.055", SDL4R::format(time)
|
587
|
+
end
|
588
|
+
|
589
|
+
# Date parsing tests using Time rather than DateTime
|
590
|
+
def test_time
|
591
|
+
SDL4R::use_datetime = false
|
592
|
+
begin
|
593
|
+
# no timezone
|
594
|
+
root = SDL4R::read("tag1 1998/05/12 12:34:56.768")
|
595
|
+
assert_kind_of Time, root.child.value
|
596
|
+
assert_equal_date_time Time.local(1998, 05, 12, 12, 34, 56, 768000), root.child.value
|
597
|
+
|
598
|
+
root = SDL4R::read("tag1 1998/05/12 12:34:56.768-UTC")
|
599
|
+
assert_equal_date_time Time.utc(1998, 05, 12, 12, 34, 56, 768000), root.child.value
|
600
|
+
|
601
|
+
root = SDL4R::read("tag1 1998/05/12 12:34:56.768-JST")
|
602
|
+
assert_equal_date_time Time.xmlschema("1998-05-12T12:34:56.768+09:00"), root.child.value
|
603
|
+
|
604
|
+
root = SDL4R::read("tag1 1998/05/12 12:34:56.768-GMT-01:00")
|
605
|
+
assert_equal_date_time Time.xmlschema("1998-05-12T12:34:56.768-01:00"), root.child.value
|
606
|
+
|
607
|
+
ensure
|
608
|
+
SDL4R::use_datetime = true
|
609
|
+
end
|
610
|
+
end
|
611
|
+
end
|
529
612
|
end
|