RXAAL 0.0.1
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.
- data/COPYING +674 -0
- data/README +0 -0
- data/RXAAL.gemspec +15 -0
- data/Rakefile +60 -0
- data/lib/angle.rb +9 -0
- data/lib/arc.rb +13 -0
- data/lib/arrow.rb +23 -0
- data/lib/attribute.rb +13 -0
- data/lib/bound_array.rb +56 -0
- data/lib/center.rb +7 -0
- data/lib/circle.rb +11 -0
- data/lib/circle_segment.rb +9 -0
- data/lib/contents.rb +7 -0
- data/lib/coordinate.rb +20 -0
- data/lib/core_ext/class.rb +17 -0
- data/lib/core_ext/module.rb +23 -0
- data/lib/core_ext/object.rb +7 -0
- data/lib/core_ext/string.rb +11 -0
- data/lib/ellipse.rb +8 -0
- data/lib/enum.rb +8 -0
- data/lib/enum/anchor.rb +16 -0
- data/lib/enum/color_name.rb +24 -0
- data/lib/enum/offset_mode.rb +9 -0
- data/lib/enum/stroke_type.rb +9 -0
- data/lib/enum/text_alignment.rb +9 -0
- data/lib/font.rb +25 -0
- data/lib/generic_color.rb +7 -0
- data/lib/graphic_prim.rb +25 -0
- data/lib/line.rb +9 -0
- data/lib/metadata.rb +78 -0
- data/lib/metadata_mod.rb +34 -0
- data/lib/named_color.rb +16 -0
- data/lib/node_prim.rb +15 -0
- data/lib/ns_container.rb +30 -0
- data/lib/offset.rb +63 -0
- data/lib/operation.rb +5 -0
- data/lib/par.rb +25 -0
- data/lib/par_container.rb +2 -0
- data/lib/point.rb +8 -0
- data/lib/polygon.rb +22 -0
- data/lib/polyline.rb +29 -0
- data/lib/privtest.rb +24 -0
- data/lib/r_xaal_error.rb +2 -0
- data/lib/r_xaal_object.rb +5 -0
- data/lib/radius.rb +5 -0
- data/lib/rectangle.rb +10 -0
- data/lib/rgb_color.rb +20 -0
- data/lib/rxaal.rb +28 -0
- data/lib/seq.rb +31 -0
- data/lib/serializable.rb +11 -0
- data/lib/shape.rb +5 -0
- data/lib/show_hide.rb +27 -0
- data/lib/square.rb +35 -0
- data/lib/stroke.rb +27 -0
- data/lib/style.rb +91 -0
- data/lib/style_container.rb +5 -0
- data/lib/style_mod.rb +63 -0
- data/lib/text.rb +34 -0
- data/lib/top_level_elem.rb +12 -0
- data/lib/triangle.rb +9 -0
- data/lib/xaal_doc.rb +93 -0
- data/lib/xaal_element.rb +77 -0
- data/lib/xaalns.rb +14 -0
- data/test/arrow_test.rb +43 -0
- data/test/attribute_test.rb +10 -0
- data/test/bound_array_test.rb +54 -0
- data/test/metadata_test.rb +35 -0
- data/test/module_test.rb +36 -0
- data/test/ns_container_test.rb +18 -0
- data/test/serializable_test.rb +19 -0
- data/test/style_test.rb +64 -0
- data/test/test_base.rb +19 -0
- data/test/xaal_element_test.rb +47 -0
- metadata +145 -0
data/lib/xaal_element.rb
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
require "rexml/element"
|
2
|
+
|
3
|
+
module RXaal
|
4
|
+
class XaalElement
|
5
|
+
include Serializable
|
6
|
+
@@default_id_num=0
|
7
|
+
attr_accessor_of_class XaalNS, :ns
|
8
|
+
attr_reader :refs
|
9
|
+
attr_reader :id
|
10
|
+
attr_reader :doc
|
11
|
+
cattr_reader :default_id_num
|
12
|
+
|
13
|
+
def initialize(doc, id=nil, elem_ns = nil)
|
14
|
+
@refs = 0
|
15
|
+
@attribs = Array.new
|
16
|
+
if (elem_ns != nil)
|
17
|
+
@ns = elem_ns
|
18
|
+
else
|
19
|
+
@ns = doc.namespaces.name_to_ns[""]
|
20
|
+
end
|
21
|
+
|
22
|
+
@doc = doc
|
23
|
+
|
24
|
+
if id == nil
|
25
|
+
klass = self.class
|
26
|
+
|
27
|
+
id = klass.name_minus_mod + "_" + XaalElement.get_new_default_id.to_s
|
28
|
+
end
|
29
|
+
|
30
|
+
@id = id
|
31
|
+
end
|
32
|
+
|
33
|
+
def add_attribute(name, value, attrib_ns = ns)
|
34
|
+
temp = Attribute.new
|
35
|
+
temp.name = name
|
36
|
+
temp.value = value
|
37
|
+
temp.ns = attrib_ns
|
38
|
+
@attribs.push(temp)
|
39
|
+
end
|
40
|
+
|
41
|
+
# increments the ref count of new_obj and decrements the ref count of curr_obj
|
42
|
+
def self.modify_ref(curr_obj, new_obj)
|
43
|
+
if (curr_obj != nil)
|
44
|
+
curr_obj.rm_ref
|
45
|
+
end
|
46
|
+
|
47
|
+
new_obj.add_ref
|
48
|
+
end
|
49
|
+
|
50
|
+
#decrements self's ref count by 1
|
51
|
+
def rm_ref
|
52
|
+
@refs -= 1
|
53
|
+
end
|
54
|
+
|
55
|
+
#increments self's ref count by 1
|
56
|
+
def add_ref
|
57
|
+
@refs +=1
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.get_new_default_id
|
61
|
+
if @@default_id_num == 0
|
62
|
+
@@default_id_num = 1
|
63
|
+
return 0
|
64
|
+
else
|
65
|
+
return @@default_id_num += 1
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def superclass_serialize(element)
|
70
|
+
element.attributes["id"] = @id
|
71
|
+
|
72
|
+
if @ns != doc.namespaces.name_to_ns[""]
|
73
|
+
element.name = @ns.prefix + ":" + element.name
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
data/lib/xaalns.rb
ADDED
data/test/arrow_test.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require "test/serializable_test"
|
2
|
+
class ArrowTest < SerializableTest
|
3
|
+
include RXaal
|
4
|
+
|
5
|
+
def test_initialize
|
6
|
+
# flunk "Not yet implemented"
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_boolean_equals_true
|
10
|
+
[:forward, :backward].each {|s|
|
11
|
+
arrow = Arrow.new(@doc)
|
12
|
+
arrow.send("#{s.to_s}=", true)
|
13
|
+
assert arrow.send(s), s.to_s + "is not true."
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_boolean_equals_false
|
18
|
+
[:forward, :backward].each {|s|
|
19
|
+
arrow = Arrow.new(@doc)
|
20
|
+
arrow.send("#{s.to_s}=", false)
|
21
|
+
assert_equal false, arrow.send(s), s.to_s + "is not false."
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_boolean_only
|
26
|
+
[:forward, :backward].each {|s|
|
27
|
+
arrow = Arrow.new(@doc)
|
28
|
+
arrow.send("#{s.to_s}=", "true")
|
29
|
+
assert_not_equal "true", arrow.send(s), s.to_s + "accepts non-booleans."
|
30
|
+
assert_nil arrow.send(s), s.to_s + "isn't nil."
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_boolean_keep
|
35
|
+
[:forward, :backward].each {|s|
|
36
|
+
arrow = Arrow.new(@doc)
|
37
|
+
arrow.send("#{s.to_s}=", false)
|
38
|
+
assert_equal false, arrow.send(s), s.to_s + "is not false."
|
39
|
+
arrow.send("#{s.to_s}=", "false")
|
40
|
+
assert_equal false, arrow.send(s), s.to_s + "was modified."
|
41
|
+
}
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require "test/test_base"
|
2
|
+
class BoundArrayTest < TestBase
|
3
|
+
include RXaal
|
4
|
+
def test_gt_gt_accept_type
|
5
|
+
array = BoundArray.new(Integer)
|
6
|
+
array << 4
|
7
|
+
assert_equal 1, array.length, "Array length isn't 1."
|
8
|
+
assert_equal 4, array[0], "First element isn't 4."
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_gt_gt_restrict
|
12
|
+
array = BoundArray.new(Integer)
|
13
|
+
array << "4"
|
14
|
+
assert_equal 0, array.length, "Array length isn't 0."
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_index_set_accept
|
18
|
+
array = BoundArray.new(Integer)
|
19
|
+
array << 5 << 3
|
20
|
+
array[1] = 67
|
21
|
+
assert_equal 67, array[1], "Array[1] isn't 67."
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_index_set_restrict
|
25
|
+
array = BoundArray.new(Integer)
|
26
|
+
array << 5 << 3
|
27
|
+
array[1] = "67"
|
28
|
+
assert_equal 3, array[1], "Array[1] isn't 3."
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_add_accept
|
32
|
+
array = BoundArray.new(Integer)
|
33
|
+
array << 5 << 3
|
34
|
+
|
35
|
+
array2 = BoundArray.new(Integer)
|
36
|
+
array2 << 7
|
37
|
+
|
38
|
+
array = array + array2
|
39
|
+
assert_equal 3, array.length, "Array length isn't 3"
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_add_reject
|
43
|
+
array = BoundArray.new(Integer)
|
44
|
+
array << 5 << 3
|
45
|
+
|
46
|
+
array2 = BoundArray.new(String)
|
47
|
+
array2 << "home"
|
48
|
+
|
49
|
+
array = array + array2
|
50
|
+
array3 = ["str"]
|
51
|
+
array = array + array3
|
52
|
+
assert_equal 2, array.length, "Array length isn't 2"
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require "test/test_base"
|
2
|
+
|
3
|
+
class MetadataTest < TestBase
|
4
|
+
include RXaal
|
5
|
+
def test_serialize
|
6
|
+
metadata = Metadata.new(@doc)
|
7
|
+
methods = metadata.public_methods.select { |i| i.to_s =~ /.*#(app_|auth_)\w*=.*/ }
|
8
|
+
methods.each {|name|
|
9
|
+
metadata.send(name.to_sym, "value")
|
10
|
+
serialize = metadata.send(serialize?)
|
11
|
+
assert(serialize, "serialization not done right")
|
12
|
+
metadata = Metadata.new
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_takes_string
|
17
|
+
metadata = Metadata.new(@doc)
|
18
|
+
methods = metadata.public_methods.select { |i| i.to_s =~ /.*#(app_|auth_)\w*=.*/ }
|
19
|
+
methods.each {|name|
|
20
|
+
metadata.send(name.to_sym, "value")
|
21
|
+
val = metadata.send(name.chop)
|
22
|
+
assert("value", val)
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_wont_take_integer
|
27
|
+
metadata = Metadata.new(@doc)
|
28
|
+
methods = metadata.public_methods.select { |i| i.to_s =~ /.*#(app_|auth_)\w*=.*/ }
|
29
|
+
methods.each {|name|
|
30
|
+
metadata.send(name.to_sym, "value")
|
31
|
+
val = metadata.send(name.chop)
|
32
|
+
assert_nil val
|
33
|
+
}
|
34
|
+
end
|
35
|
+
end
|
data/test/module_test.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require "test/test_base"
|
2
|
+
|
3
|
+
class ModuleTest < TestBase
|
4
|
+
attr_accessor_bool(:home) {|n| n.class == String}
|
5
|
+
|
6
|
+
attr_accessor_of_class(String, :foo, :bar, :baz)
|
7
|
+
def test_attr_accessor_bool_home_exists
|
8
|
+
assert_equal false, instance_variable_defined?(:@home)
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_should_return_instance_variable_when_sent
|
12
|
+
@home = 0
|
13
|
+
assert_equal 0, home
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_should_set_instance_variable_when
|
17
|
+
self.home = 'home'
|
18
|
+
assert_equal 'home', @home
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_shouldnt_set_instance_variable_when_sent_odd
|
22
|
+
self.home = 3
|
23
|
+
assert_not_equal 3, home
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_attr_accessor_of_class
|
27
|
+
self.foo = "home"
|
28
|
+
self.bar = :string
|
29
|
+
self.baz = 0
|
30
|
+
assert_equal 'home', foo
|
31
|
+
assert_not_equal :string, bar
|
32
|
+
assert_not_equal 0, baz
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "test/test_base"
|
2
|
+
class NSContainerTest < TestBase
|
3
|
+
include RXaal
|
4
|
+
def test_add_ns
|
5
|
+
ns = NSContainer.new
|
6
|
+
ns.add_ns("http://sample.com", "new")
|
7
|
+
|
8
|
+
assert(ns.name_to_ns.key?("new"), "Not added to name_to_ns")
|
9
|
+
assert(ns.uri_to_ns.key?("http://sample.com"), "Not added to uri_to_ns")
|
10
|
+
|
11
|
+
name_ns = ns.name_to_ns["new"]
|
12
|
+
uri_ns = ns.uri_to_ns["http://sample.com"]
|
13
|
+
|
14
|
+
assert(name_ns == uri_ns, "Uri and Name NS' aren't the same")
|
15
|
+
|
16
|
+
assert(ns.namespaces.index(name_ns) != nil, "NS not found in namespaces")
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "test/test_base"
|
2
|
+
|
3
|
+
class SerializableTest < TestBase
|
4
|
+
|
5
|
+
# def test_serialize_overridden
|
6
|
+
# #we're removing "Test"
|
7
|
+
# klass_name = self.class.to_s.chop.chop.chop.chop
|
8
|
+
# obj = Kernel.const_get(klass_name).new
|
9
|
+
# begin
|
10
|
+
# self.serialize(nil)
|
11
|
+
# rescue NotImplementedError
|
12
|
+
# flunk "serialize not overridden"
|
13
|
+
# end
|
14
|
+
# end
|
15
|
+
|
16
|
+
def test_none
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
data/test/style_test.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
|
2
|
+
require "test/serializable_test"
|
3
|
+
|
4
|
+
class StyleTest < SerializableTest
|
5
|
+
include RXaal
|
6
|
+
def test_initialize
|
7
|
+
#flunk "Not yet implemented"
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_boolean_equals_true
|
11
|
+
[:forward_arrow, :backwards_arrow].each {|s|
|
12
|
+
style = Style.new(@doc)
|
13
|
+
style.send("#{s.to_s}=", true)
|
14
|
+
assert_equal true, style.send(s), s.to_s + "is not true."
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_boolean_equals_false
|
19
|
+
[:forward_arrow, :backwards_arrow].each {|s|
|
20
|
+
style = Style.new(@doc)
|
21
|
+
style.send("#{s.to_s}=", false)
|
22
|
+
assert_equal false, style.send(s), s.to_s + "is not false."
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_boolean_inherit_true
|
27
|
+
[:forward_arrow, :backwards_arrow].each {|s|
|
28
|
+
style1 = Style.new(@doc)
|
29
|
+
style1.send("#{s.to_s}=", true)
|
30
|
+
style2 = Style.new(@doc, nil, style1)
|
31
|
+
assert_equal true, style2.send(s), s.to_s + "did not inherit true."
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_boolean_inherit_false
|
36
|
+
[:forward_arrow, :backwards_arrow].each {|s|
|
37
|
+
style1 = Style.new(@doc)
|
38
|
+
style1.send("#{s.to_s}=", false)
|
39
|
+
style2 = Style.new(@doc, nil, style1)
|
40
|
+
assert_equal false, style2.send(s), s.to_s + "did not inherit false."
|
41
|
+
}
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_boolean_inherit_nil
|
45
|
+
[:forward_arrow, :backwards_arrow].each {|s|
|
46
|
+
style1 = Style.new(@doc)
|
47
|
+
style2 = Style.new(@doc, nil, style1)
|
48
|
+
assert_nil style2.send(s), s.to_s + "did not inherit nil."
|
49
|
+
}
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_boolean_override
|
53
|
+
[:forward_arrow, :backwards_arrow].each {|s|
|
54
|
+
style1 = Style.new(@doc)
|
55
|
+
style1.send("#{s.to_s}=", false)
|
56
|
+
style2 = Style.new(@doc, nil, style1)
|
57
|
+
assert_equal false, style1.send(s), "style1." + s.to_s + "was not false."
|
58
|
+
assert_equal false, style2.send(s), "style2." + s.to_s + "did not inherit false."
|
59
|
+
style2.send("#{s.to_s}=", true)
|
60
|
+
assert_equal true, style2.send(s), "style2." + s.to_s + "was not true."
|
61
|
+
assert_equal false, style1.send(s), "style1." + s.to_s + "was improperly overridden."
|
62
|
+
}
|
63
|
+
end
|
64
|
+
end
|
data/test/test_base.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require "test/serializable_test"
|
2
|
+
module RXaal
|
3
|
+
class XaalElementTest < SerializableTest
|
4
|
+
def test_initialize
|
5
|
+
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_no_id_set
|
9
|
+
id = XaalElement.default_id_num
|
10
|
+
e = XaalElement.new(@doc)
|
11
|
+
assert_equal "XaalElement_"+ (id+1).to_s, e.id, "Id isn't class + 0"
|
12
|
+
e1 = XaalElement.new(@doc)
|
13
|
+
assert_equal "XaalElement_" + (id+2).to_s, e1.id, "Id isn't class + 1"
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_id_set
|
17
|
+
id = XaalElement.default_id_num
|
18
|
+
e = XaalElement.new(@doc, "neato")
|
19
|
+
assert_equal "neato", e.id, "Element id isn't correct"
|
20
|
+
assert_equal id, XaalElement.default_id_num, "default_id_num was incremented"
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_no_ns_set
|
24
|
+
e = XaalElement.new(@doc, "neato")
|
25
|
+
assert_equal e.ns, @doc.namespaces.name_to_ns[""], "NS isn't default"
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_ns_set
|
29
|
+
ns = @doc.namespaces.add_ns("http://simple.com", "blank")
|
30
|
+
e = XaalElement.new(@doc, "neato", ns)
|
31
|
+
assert_equal ns, e.ns, "NS isn't custom"
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_superclass_serialize
|
35
|
+
e = XaalElement.new(@doc)
|
36
|
+
id = e.id
|
37
|
+
re = REXML::Element.new "none"
|
38
|
+
e.superclass_serialize(re)
|
39
|
+
assert_equal re.attributes["id"], id, "Attribute id isn't right"
|
40
|
+
assert_equal "none", re.name, "Name was not the default"
|
41
|
+
|
42
|
+
e.ns = @doc.namespaces.add_ns("http://simple.com", "blank")
|
43
|
+
e.superclass_serialize(re)
|
44
|
+
assert_equal "blank:none", re.expanded_name, "NS wasn't serialized"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|