rubyrdf 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/History.txt +4 -0
- data/License.txt +24 -0
- data/Manifest.txt +52 -0
- data/README.txt +79 -0
- data/Rakefile +4 -0
- data/config/hoe.rb +70 -0
- data/config/requirements.rb +15 -0
- data/lib/rdf/blank_node.rb +41 -0
- data/lib/rdf/exceptions.rb +26 -0
- data/lib/rdf/format/ntriples.rb +493 -0
- data/lib/rdf/graph/base.rb +118 -0
- data/lib/rdf/graph/memory.rb +146 -0
- data/lib/rdf/graph/tests.rb +137 -0
- data/lib/rdf/namespace.rb +90 -0
- data/lib/rdf/plain_literal_node.rb +36 -0
- data/lib/rdf/query/binding.rb +68 -0
- data/lib/rdf/query/executer.rb +42 -0
- data/lib/rdf/query/result.rb +54 -0
- data/lib/rdf/query.rb +54 -0
- data/lib/rdf/triple.rb +61 -0
- data/lib/rdf/typed_literal_node.rb +39 -0
- data/lib/rdf/uri_node.rb +35 -0
- data/lib/rdf/version.rb +9 -0
- data/lib/rubyrdf.rb +59 -0
- data/log/debug.log +0 -0
- data/script/console +11 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/script/txt2html +74 -0
- data/setup.rb +1585 -0
- data/tasks/deployment.rake +34 -0
- data/tasks/environment.rake +7 -0
- data/tasks/website.rake +17 -0
- data/test/helper.rb +14 -0
- data/test/test_blank_node.rb +67 -0
- data/test/test_format_ntriples.rb +247 -0
- data/test/test_graph_base.rb +71 -0
- data/test/test_graph_memory.rb +146 -0
- data/test/test_namespace.rb +130 -0
- data/test/test_plain_literal_node.rb +83 -0
- data/test/test_query.rb +49 -0
- data/test/test_query_binding.rb +84 -0
- data/test/test_query_result.rb +111 -0
- data/test/test_rdf.rb +56 -0
- data/test/test_triple.rb +147 -0
- data/test/test_typed_literal_node.rb +61 -0
- data/test/test_uri_node.rb +45 -0
- data/website/index.html +169 -0
- data/website/index.txt +92 -0
- data/website/javascripts/rounded_corners_lite.inc.js +285 -0
- data/website/stylesheets/screen.css +138 -0
- data/website/template.html.erb +48 -0
- metadata +139 -0
@@ -0,0 +1,130 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper.rb'
|
2
|
+
|
3
|
+
class TestNamespace < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
reset
|
6
|
+
RDF::Namespace.register(:ex, 'http://example.org/')
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_prefixes_should_return_array
|
10
|
+
assert RDF::Namespace.prefixes.is_a?(Array)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_register_should_add_to_prefixes
|
14
|
+
reset
|
15
|
+
RDF::Namespace.register(:ex, 'http://example.org/')
|
16
|
+
assert RDF::Namespace.registered?(:ex)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_register_should_raise_error_when_prefix_invalid
|
20
|
+
reset
|
21
|
+
assert_raise(ArgumentError) {
|
22
|
+
RDF::Namespace.register(nil, 'http://example.org/')
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_register_should_raise_error_when_base_invalid
|
27
|
+
reset
|
28
|
+
assert_raise(ArgumentError) {
|
29
|
+
RDF::Namespace.register(:ex, 'http://example.org')
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_register_should_not_raise_error_when_prefix_is_already_registered
|
34
|
+
reset
|
35
|
+
assert_nothing_raised {
|
36
|
+
RDF::Namespace.register(:ex, 'http://example.org/')
|
37
|
+
RDF::Namespace.register(:ex, 'http://example.org/')
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_register_should_create_module
|
42
|
+
reset
|
43
|
+
RDF::Namespace.register(:ex, 'http://example.org/')
|
44
|
+
assert Object.const_defined?(:EX)
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_register_should_find_module
|
48
|
+
reset
|
49
|
+
mod = Object.const_set(:EX, Module.new)
|
50
|
+
RDF::Namespace.register(:ex, 'http://example.org/')
|
51
|
+
assert mod.equal?(Object.const_get(:EX))
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_expand_should_return_uri
|
55
|
+
assert_equal 'http://example.org/Something', RDF::Namespace.expand(:ex, :Something)
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_split_should_return_base_and_name
|
59
|
+
assert_equal ['http://example.org/', 'Something'], RDF::Namespace.split('http://example.org/Something')
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_prefix_should_return_registered_prefix
|
63
|
+
assert_equal :ex, RDF::Namespace.prefix('http://example.org/Something')
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_method_missing_should_return_uri_node
|
67
|
+
assert_equal RDF::UriNode.new('http://example.org/something'), EX.something
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_const_missing_should_return_uri_node
|
71
|
+
assert_equal RDF::UriNode.new('http://example.org/Something'), EX::Something
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_method_missing_should_raise_error_with_arguments
|
75
|
+
assert_raise(ArgumentError) {
|
76
|
+
EX.something('test')
|
77
|
+
}
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_const_missing_should_raise_error_with_arguments
|
81
|
+
assert_raise(ArgumentError) {
|
82
|
+
EX::Something('test')
|
83
|
+
}
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_type_should_return_uri_node
|
87
|
+
assert_equal RDF::UriNode.new('http://example.org/type'), EX::type
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_name_should_return_uri_node
|
91
|
+
assert_equal RDF::UriNode.new('http://example.org/name'), EX::name
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_id_should_return_uri_node
|
95
|
+
assert_equal RDF::UriNode.new('http://example.org/id'), EX::id
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_should_automatically_define_rdf
|
99
|
+
assert_equal RDF::UriNode.new('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), RDF::type
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_should_automatically_define_rdfs
|
103
|
+
assert_equal RDF::UriNode.new('http://www.w3.org/2000/01/rdf-schema#Class'), RDFS::Class
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_should_automatically_define_owl
|
107
|
+
assert_equal RDF::UriNode.new('http://www.w3.org/2002/07/owl#Thing'), OWL::Thing
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_should_automatically_define_xsd
|
111
|
+
assert_equal RDF::UriNode.new('http://www.w3.org/2001/XMLSchema#string'), XSD::string
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_registered_should_be_false_for_unregistered_namespace
|
115
|
+
assert !RDF::Namespace.registered?(:abc)
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_registered_should_be_true_for_registered_namespace
|
119
|
+
assert RDF::Namespace.registered?(:ex)
|
120
|
+
end
|
121
|
+
|
122
|
+
private
|
123
|
+
def reset
|
124
|
+
RDF::Namespace.class_eval <<-ENDV
|
125
|
+
@@prefixes.delete(:ex) if @@prefixes.has_key?(:ex)
|
126
|
+
@@bases.delete('http://example.org/') if @@bases.has_key?('http://example.org/')
|
127
|
+
ENDV
|
128
|
+
Object.send(:remove_const, :EX) if Object.const_defined?(:EX)
|
129
|
+
end
|
130
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper.rb'
|
2
|
+
|
3
|
+
class TestPlainLiteralNode < Test::Unit::TestCase
|
4
|
+
def test_new_should_initialize_lexical_form
|
5
|
+
assert_equal 'test', RDF::PlainLiteralNode.new('test', 'en').lexical_form
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_new_should_initialize_language_tag
|
9
|
+
assert_equal 'en', RDF::PlainLiteralNode.new('test', 'en').language_tag
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_new_should_default_language_tag_to_nil
|
13
|
+
assert_nil RDF::PlainLiteralNode.new('test').language_tag
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_equal_should_be_true_for_same_lexical_value
|
17
|
+
assert_equal RDF::PlainLiteralNode.new('test'), RDF::PlainLiteralNode.new('test')
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_equal_should_be_true_for_same_lexical_value_and_language_tag
|
21
|
+
assert_equal RDF::PlainLiteralNode.new('test', 'en'), RDF::PlainLiteralNode.new('test', 'en')
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_equal_should_be_true_for_same_lexical_value_and_different_case_language_tag
|
25
|
+
assert_equal RDF::PlainLiteralNode.new('test', 'en'), RDF::PlainLiteralNode.new('test', 'EN')
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_equal_should_be_false_for_same_lexical_value_and_different_language_tag
|
29
|
+
assert_not_equal RDF::PlainLiteralNode.new('test', 'en'), RDF::PlainLiteralNode.new('test', 'fr')
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_equal_should_be_false_for_same_lexical_value_and_missing_language_tag
|
33
|
+
assert_not_equal RDF::PlainLiteralNode.new('test', 'en'), RDF::PlainLiteralNode.new('test')
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_hash_should_be_equal_for_same_lexical_value
|
37
|
+
assert_equal RDF::PlainLiteralNode.new('test').hash, RDF::PlainLiteralNode.new('test').hash
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_hash_should_be_equal_for_same_lexical_value_and_language_tag
|
41
|
+
assert_equal RDF::PlainLiteralNode.new('test', 'en').hash, RDF::PlainLiteralNode.new('test', 'en').hash
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_hash_should_be_equal_for_same_lexical_value_and_different_case_language_tag
|
45
|
+
assert_equal RDF::PlainLiteralNode.new('test', 'en').hash, RDF::PlainLiteralNode.new('test', 'EN').hash
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_hash_should_not_be_equal_for_same_lexical_value_and_different_language_tag
|
49
|
+
assert_not_equal RDF::PlainLiteralNode.new('test', 'en').hash, RDF::PlainLiteralNode.new('test', 'fr').hash
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_hash_should_not_be_equal_for_same_lexical_value_and_missing_language_tag
|
53
|
+
assert_not_equal RDF::PlainLiteralNode.new('test', 'en').hash, RDF::PlainLiteralNode.new('test').hash
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_eql_should_be_true_for_same_lexical_value
|
57
|
+
assert RDF::PlainLiteralNode.new('test').eql?(RDF::PlainLiteralNode.new('test'))
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_eql_should_be_true_for_same_lexical_value_and_language_tag
|
61
|
+
assert RDF::PlainLiteralNode.new('test', 'en').eql?(RDF::PlainLiteralNode.new('test', 'en'))
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_eql_should_be_true_for_same_lexical_value_and_different_case_language_tag
|
65
|
+
assert RDF::PlainLiteralNode.new('test', 'en').eql?(RDF::PlainLiteralNode.new('test', 'EN'))
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_eql_should_be_false_for_same_lexical_value_and_different_language_tag
|
69
|
+
assert !RDF::PlainLiteralNode.new('test', 'en').eql?(RDF::PlainLiteralNode.new('test', 'fr'))
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_eql_should_be_false_for_same_lexical_value_and_missing_language_tag
|
73
|
+
assert !RDF::PlainLiteralNode.new('test', 'en').eql?(RDF::PlainLiteralNode.new('test'))
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_to_s_should_be_ntriples_format
|
77
|
+
assert_equal "\"test\"@en", RDF::PlainLiteralNode.new('test', 'en').to_s
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_to_s_should_be_not_include_nil_language_tag
|
81
|
+
assert_equal "\"test\"", RDF::PlainLiteralNode.new('test').to_s
|
82
|
+
end
|
83
|
+
end
|
data/test/test_query.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper.rb'
|
2
|
+
|
3
|
+
class TestQuery < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@graph = RDF::Graph::Memory.new
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_select_should_set_select_clause
|
9
|
+
query = RDF::Query.new
|
10
|
+
query.select(RDF::BlankNode.new('x', @graph), RDF::BlankNode.new('y', @graph))
|
11
|
+
assert_equal [RDF::BlankNode.new('x', @graph), RDF::BlankNode.new('y', @graph)], query.select_clause
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_select_should_return_self
|
15
|
+
query = RDF::Query.new
|
16
|
+
assert_equal query, query.select(RDF::BlankNode.new('x', @graph), RDF::BlankNode.new('y', @graph))
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_select_clause_should_clone
|
20
|
+
query = RDF::Query.new
|
21
|
+
query.select(RDF::BlankNode.new('x', @graph), RDF::BlankNode.new('y', @graph))
|
22
|
+
query.select_clause.clear
|
23
|
+
assert_equal [RDF::BlankNode.new('x', @graph), RDF::BlankNode.new('y', @graph)], query.select_clause
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_where_should_return_self
|
27
|
+
query = RDF::Query.new
|
28
|
+
assert_equal query, query.where(EX::a, EX::b, EX::c)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_where_should_update_where_clause
|
32
|
+
query = RDF::Query.new
|
33
|
+
query.where(EX::a, EX::b, EX::c)
|
34
|
+
assert_equal [[EX::a, EX::b, EX::c]], query.where_clause
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_where_clause_should_clone
|
38
|
+
query = RDF::Query.new
|
39
|
+
query.where(EX::a, EX::b, EX::c)
|
40
|
+
query.where_clause.clear
|
41
|
+
assert_equal [[EX::a, EX::b, EX::c]], query.where_clause
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_and_should_alias_where
|
45
|
+
query = RDF::Query.new
|
46
|
+
query.and(EX::a, EX::b, EX::c)
|
47
|
+
assert_equal [[EX::a, EX::b, EX::c]], query.where_clause
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper.rb'
|
2
|
+
|
3
|
+
class TestQueryBinding < Test::Unit::TestCase
|
4
|
+
def test_new_should_initialize_hash
|
5
|
+
assert_equal EX::b, RDF::Query::Binding.new(EX::a => EX::b)[EX::a]
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_get_should_return_key_if_not_found
|
9
|
+
assert_equal EX::a, RDF::Query::Binding.new[EX::a]
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_set_should_assign_value_to_key
|
13
|
+
m = RDF::Query::Binding.new
|
14
|
+
m[EX::a] = EX::b
|
15
|
+
assert_equal EX::b, m[EX::a]
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_clone_should_perform_deep_copy
|
19
|
+
ma = RDF::Query::Binding.new
|
20
|
+
mb = ma.clone
|
21
|
+
ma[EX::a] = EX::b
|
22
|
+
assert !mb.bound?(EX::a)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_bound_should_be_true
|
26
|
+
m = RDF::Query::Binding.new
|
27
|
+
m[EX::a] = EX::b
|
28
|
+
assert m.bound?(EX::a)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_bound_should_be_false
|
32
|
+
m = RDF::Query::Binding.new
|
33
|
+
assert !m.bound?(EX::a)
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_equal_should_be_true_for_same_keys_and_values
|
37
|
+
assert_equal RDF::Query::Binding.new(EX::a => EX::b), RDF::Query::Binding.new(EX::a => EX::b)
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_equal_should_be_false_for_same_keys_and_different_values
|
41
|
+
assert_not_equal RDF::Query::Binding.new(EX::a => EX::b), RDF::Query::Binding.new(EX::a => EX::c)
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_equal_should_be_false_for_different_keys_and_same_values
|
45
|
+
assert_not_equal RDF::Query::Binding.new(EX::a => EX::b), RDF::Query::Binding.new(EX::c => EX::b)
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_eql_should_be_true_for_same_keys_and_values
|
49
|
+
assert RDF::Query::Binding.new(EX::a => EX::b).eql?(RDF::Query::Binding.new(EX::a => EX::b))
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_eql_should_be_false_for_same_keys_and_different_values
|
53
|
+
assert !RDF::Query::Binding.new(EX::a => EX::b).eql?(RDF::Query::Binding.new(EX::a => EX::c))
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_eql_should_be_false_for_different_keys_and_same_values
|
57
|
+
assert !RDF::Query::Binding.new(EX::a => EX::b).eql?(RDF::Query::Binding.new(EX::c => EX::b))
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_hash_should_be_equal_for_same_keys_and_values
|
61
|
+
assert_equal RDF::Query::Binding.new(EX::a => EX::b).hash, RDF::Query::Binding.new(EX::a => EX::b).hash
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_hash_should_not_be_equal_for_same_keys_and_different_values
|
65
|
+
assert_not_equal RDF::Query::Binding.new(EX::a => EX::b).hash, RDF::Query::Binding.new(EX::a => EX::c).hash
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_hash_should_not_be_equal_for_different_keys_and_same_values
|
69
|
+
assert_not_equal RDF::Query::Binding.new(EX::a => EX::b).hash, RDF::Query::Binding.new(EX::c => EX::b).hash
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_empty_should_be_true
|
73
|
+
assert RDF::Query::Binding.new.empty?
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_empty_should_be_false
|
77
|
+
assert !RDF::Query::Binding.new(EX::a => EX::b).empty?
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_to_s_should_show_hash_table
|
81
|
+
binding = RDF::Query::Binding.new(EX::a => EX::b)
|
82
|
+
assert_equal "{#{EX::a} => #{EX::b}}", binding.to_s
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper.rb'
|
2
|
+
|
3
|
+
class TestQueryResult < Test::Unit::TestCase
|
4
|
+
def test_success_should_be_false
|
5
|
+
assert !RDF::Query::Result.new.success?
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_failure_should_be_true
|
9
|
+
assert RDF::Query::Result.new.failure?
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_bindings_should_return_set
|
13
|
+
assert RDF::Query::Result.new.bindings.is_a?(Set)
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_new_should_initialize_bindings
|
17
|
+
binding = RDF::Query::Binding.new(EX::a => EX::b)
|
18
|
+
assert RDF::Query::Result.new(binding).bindings.include?(binding)
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_new_should_initialize_bindings_from_params
|
22
|
+
binding1 = RDF::Query::Binding.new(EX::a => EX::b)
|
23
|
+
binding2 = RDF::Query::Binding.new(EX::b => EX::c)
|
24
|
+
result = RDF::Query::Result.new(binding1, binding2)
|
25
|
+
assert result.bindings.include?(binding1)
|
26
|
+
assert result.bindings.include?(binding2)
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_new_should_initialize_bindings_from_array
|
30
|
+
binding1 = RDF::Query::Binding.new(EX::a => EX::b)
|
31
|
+
binding2 = RDF::Query::Binding.new(EX::b => EX::c)
|
32
|
+
result = RDF::Query::Result.new([binding1, binding2])
|
33
|
+
assert result.bindings.include?(binding1)
|
34
|
+
assert result.bindings.include?(binding2)
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_success_bang_should_set_success
|
38
|
+
result = RDF::Query::Result.new
|
39
|
+
result.success!
|
40
|
+
assert result.success?
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_success_bang_should_create_result_and_set_success
|
44
|
+
assert RDF::Query::Result.success!.success?
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_success_bang_should_initialize_bindings
|
48
|
+
binding = RDF::Query::Binding.new(EX::a => EX::b)
|
49
|
+
assert RDF::Query::Result.success!(binding).bindings.include?(binding)
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_inject_should_raise_error_if_not_result
|
53
|
+
assert_raise(ArgumentError) {
|
54
|
+
RDF::Query::Result.new << 'test'
|
55
|
+
}
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_inject_should_ignore_bindings_for_failure
|
59
|
+
result = RDF::Query::Result.new(RDF::Query::Binding.new(EX::a => EX::b))
|
60
|
+
failed_binding = RDF::Query::Binding.new(EX::c => EX::d)
|
61
|
+
result << RDF::Query::Result.new(failed_binding)
|
62
|
+
|
63
|
+
assert !result.bindings.include?(failed_binding)
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_inject_should_insert_bindings_for_success
|
67
|
+
result = RDF::Query::Result.new(RDF::Query::Binding.new(EX::a => EX::b))
|
68
|
+
binding = RDF::Query::Binding.new(EX::c => EX::d)
|
69
|
+
result << RDF::Query::Result.success!(binding)
|
70
|
+
|
71
|
+
assert result.bindings.include?(binding)
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_inject_should_change_to_success
|
75
|
+
result = RDF::Query::Result.new(RDF::Query::Binding.new(EX::a => EX::b))
|
76
|
+
binding = RDF::Query::Binding.new(EX::c => EX::d)
|
77
|
+
result << RDF::Query::Result.success!(binding)
|
78
|
+
|
79
|
+
assert result.success?
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_inject_should_discard_old_values_if_it_was_failed
|
83
|
+
binding = RDF::Query::Binding.new(EX::a => EX::b)
|
84
|
+
result = RDF::Query::Result.new(binding)
|
85
|
+
result << RDF::Query::Result.success!(RDF::Query::Binding.new(EX::c => EX::d))
|
86
|
+
|
87
|
+
assert !result.bindings.include?(binding)
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_inject_should_keep_old_values_if_it_was_success
|
91
|
+
binding = RDF::Query::Binding.new(EX::a => EX::b)
|
92
|
+
result = RDF::Query::Result.success!(binding)
|
93
|
+
result << RDF::Query::Result.success!(RDF::Query::Binding.new(EX::c => EX::d))
|
94
|
+
|
95
|
+
assert result.bindings.include?(binding)
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_inject_should_ignore_empty_bindings
|
99
|
+
result = RDF::Query::Result.success!
|
100
|
+
result << RDF::Query::Result.success!(RDF::Query::Binding.new({}))
|
101
|
+
|
102
|
+
assert result.bindings.empty?
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_to_s_should_be_concatenation_of_bindings
|
106
|
+
result = RDF::Query::Result.success!(RDF::Query::Binding.new(EX::a => EX::b),
|
107
|
+
RDF::Query::Binding.new(EX::a => EX::c))
|
108
|
+
assert_equal "{#{result.bindings.collect{|b| b.to_s}.join(", ")}}",
|
109
|
+
result.to_s
|
110
|
+
end
|
111
|
+
end
|
data/test/test_rdf.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper.rb'
|
2
|
+
|
3
|
+
class TestRDF < Test::Unit::TestCase
|
4
|
+
def test_plain_literal_node_should_be_true_for_plain_literal_node
|
5
|
+
assert RDF::PlainLiteralNode?(RDF::PlainLiteralNode.new('test'))
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_plain_literal_node_should_be_true_for_duck_type
|
9
|
+
assert RDF::PlainLiteralNode?(Struct.new(:lexical_form, :language_tag).new)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_typed_literal_node_should_be_true_for_typed_literal_node
|
13
|
+
assert RDF::TypedLiteralNode?(RDF::TypedLiteralNode.new('test', EX::a))
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_typed_literal_node_should_be_true_for_duck_type
|
17
|
+
assert RDF::TypedLiteralNode?(Struct.new(:lexical_form, :datatype_uri).new)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_literal_node_should_check_both_plain_and_typed_literal_node
|
21
|
+
RDF.expects(:PlainLiteralNode?).returns(false)
|
22
|
+
RDF.expects(:TypedLiteralNode?).returns(false)
|
23
|
+
assert !RDF::LiteralNode?(RDF::PlainLiteralNode.new('test'))
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_uri_node_should_be_true_for_uri_node
|
27
|
+
assert RDF::UriNode?(RDF::UriNode.new(EX::a))
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_uri_node_should_be_true_for_duck_type
|
31
|
+
assert RDF::UriNode?(Struct.new(:uri).new)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_blank_node_should_be_true_for_blank_node
|
35
|
+
assert RDF::BlankNode?(RDF::BlankNode.new(RDF::Graph::Memory.new, 'test'))
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_blank_node_should_be_true_for_duck_type
|
39
|
+
assert RDF::BlankNode?(Struct.new(:graph, :name).new)
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_node_should_check_literal_node_blank_node_and_uri_node
|
43
|
+
RDF.expects(:LiteralNode?).returns(false)
|
44
|
+
RDF.expects(:BlankNode?).returns(false)
|
45
|
+
RDF.expects(:UriNode?).returns(false)
|
46
|
+
assert !RDF::Node?(RDF::PlainLiteralNode.new('test'))
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_triple_should_be_true_for_triple
|
50
|
+
assert RDF::Triple?(RDF::Triple.new(EX::a, EX::b, EX::c))
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_triple_should_be_true_for_duck_type
|
54
|
+
assert RDF::Triple?(Struct.new(:subject, :predicate, :object).new)
|
55
|
+
end
|
56
|
+
end
|
data/test/test_triple.rb
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper.rb'
|
2
|
+
|
3
|
+
class TestTriple < Test::Unit::TestCase
|
4
|
+
def test_construct_should_return_triple
|
5
|
+
t = RDF::Triple.new(EX::a, EX::b, EX::c)
|
6
|
+
assert_same t, RDF::Triple.construct(t)
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_construct_should_return_nil_when_not_triple
|
10
|
+
assert_nil RDF::Triple.construct("test")
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_construct_should_create_triple
|
14
|
+
assert_equal RDF::Triple.new(EX::a, EX::b, EX::c), RDF::Triple.construct(EX::a, EX::b, EX::c)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_construct_should_raise_argument_error_with_two_params
|
18
|
+
assert_raises(ArgumentError) do
|
19
|
+
RDF::Triple.construct(EX::a, EX::b)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_construct_should_raise_argument_error_with_four_params
|
24
|
+
assert_raises(ArgumentError) do
|
25
|
+
RDF::Triple.construct(EX::a, EX::b, EX::c, EX::d)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_new_should_initialize_subject
|
30
|
+
assert_equal EX::a, RDF::Triple.new(EX::a, EX::b, EX::c).subject
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_new_should_raise_error_for_nil_subject
|
34
|
+
assert_raise(ArgumentError) {
|
35
|
+
RDF::Triple.new(nil, EX::b, EX::c)
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_new_should_raise_error_for_non_node_subject
|
40
|
+
assert_raise(ArgumentError) {
|
41
|
+
RDF::Triple.new(:a, EX::b, EX::c)
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_new_should_raise_error_for_invalid_subject
|
46
|
+
assert_raise(RDF::InvalidSubjectError) {
|
47
|
+
RDF::Triple.new(RDF::PlainLiteralNode.new("test"), EX::b, EX::c)
|
48
|
+
}
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_new_should_initialize_predicate
|
52
|
+
assert_equal EX::b, RDF::Triple.new(EX::a, EX::b, EX::c).predicate
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_new_should_raise_error_for_nil_predicate
|
56
|
+
assert_raise(ArgumentError) {
|
57
|
+
RDF::Triple.new(EX::a, nil, EX::c)
|
58
|
+
}
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_new_should_raise_error_for_non_node_predicate
|
62
|
+
assert_raise(ArgumentError) {
|
63
|
+
RDF::Triple.new(EX::a, :a, EX::c)
|
64
|
+
}
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_new_should_raise_error_for_literal_node_predicate
|
68
|
+
assert_raise(RDF::InvalidPredicateError) {
|
69
|
+
RDF::Triple.new(EX::a, RDF::PlainLiteralNode.new('test'), EX::c)
|
70
|
+
}
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_new_should_raise_error_for_blank_node_predicate
|
74
|
+
assert_raise(RDF::InvalidPredicateError) {
|
75
|
+
RDF::Triple.new(EX::a, RDF::Graph::Memory.new.new_blank_node('x'), EX::c)
|
76
|
+
}
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_new_should_initialize_object
|
80
|
+
assert_equal EX::c, RDF::Triple.new(EX::a, EX::b, EX::c).object
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_new_should_raise_error_for_nil_object
|
84
|
+
assert_raise(ArgumentError) {
|
85
|
+
RDF::Triple.new(EX::a, EX::b, nil)
|
86
|
+
}
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_new_should_raise_error_for_non_node_object
|
90
|
+
assert_raise(ArgumentError) {
|
91
|
+
RDF::Triple.new(EX::a, EX::b, :a)
|
92
|
+
}
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_equal_should_be_true_for_same_subject_predicate_and_object
|
96
|
+
assert_equal RDF::Triple.new(EX::a, EX::b, EX::c), RDF::Triple.new(EX::a, EX::b, EX::c)
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_equal_should_be_false_for_same_predicate_object_but_different_subject
|
100
|
+
assert_not_equal RDF::Triple.new(EX::a, EX::b, EX::c), RDF::Triple.new(EX::d, EX::b, EX::c)
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_equal_should_be_false_for_same_subject_object_but_different_predicate
|
104
|
+
assert_not_equal RDF::Triple.new(EX::a, EX::b, EX::c), RDF::Triple.new(EX::a, EX::d, EX::c)
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_equal_should_be_false_for_same_subject_predicate_but_different_object
|
108
|
+
assert_not_equal RDF::Triple.new(EX::a, EX::b, EX::c), RDF::Triple.new(EX::a, EX::b, EX::d)
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_hash_should_be_equal_for_same_subject_predicate_and_object
|
112
|
+
assert_equal RDF::Triple.new(EX::a, EX::b, EX::c).hash, RDF::Triple.new(EX::a, EX::b, EX::c).hash
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_hash_should_not_be_equal_for_same_predicate_object_but_different_subject
|
116
|
+
assert_not_equal RDF::Triple.new(EX::a, EX::b, EX::c).hash, RDF::Triple.new(EX::d, EX::b, EX::c).hash
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_hash_should_not_be_equal_for_same_subject_object_but_different_predicate
|
120
|
+
assert_not_equal RDF::Triple.new(EX::a, EX::b, EX::c).hash, RDF::Triple.new(EX::a, EX::d, EX::c).hash
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_hash_should_not_be_equal_for_same_subject_predicate_but_different_object
|
124
|
+
assert_not_equal RDF::Triple.new(EX::a, EX::b, EX::c).hash, RDF::Triple.new(EX::a, EX::b, EX::d).hash
|
125
|
+
end
|
126
|
+
|
127
|
+
def test_eql_should_be_true_for_same_subject_predicate_and_object
|
128
|
+
assert RDF::Triple.new(EX::a, EX::b, EX::c).eql?(RDF::Triple.new(EX::a, EX::b, EX::c))
|
129
|
+
end
|
130
|
+
|
131
|
+
def test_eql_should_be_false_for_same_predicate_object_but_different_subject
|
132
|
+
assert !RDF::Triple.new(EX::a, EX::b, EX::c).eql?(RDF::Triple.new(EX::d, EX::b, EX::c))
|
133
|
+
end
|
134
|
+
|
135
|
+
def test_eql_should_be_false_for_same_subject_object_but_different_predicate
|
136
|
+
assert !RDF::Triple.new(EX::a, EX::b, EX::c).eql?(RDF::Triple.new(EX::a, EX::d, EX::c))
|
137
|
+
end
|
138
|
+
|
139
|
+
def test_eql_should_be_false_for_same_subject_predicate_but_different_object
|
140
|
+
assert !RDF::Triple.new(EX::a, EX::b, EX::c).eql?(RDF::Triple.new(EX::a, EX::b, EX::d))
|
141
|
+
end
|
142
|
+
|
143
|
+
def test_to_s_should_be_ntriples_format
|
144
|
+
assert_equal "<http://example.org/a> <http://example.org/b> <http://example.org/c>.",
|
145
|
+
RDF::Triple.new(EX::a, EX::b, EX::c).to_s
|
146
|
+
end
|
147
|
+
end
|