redlander 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,85 @@
1
+ require "spec_helper"
2
+
3
+ require 'date'
4
+
5
+ describe Node do
6
+
7
+ it "should be created with default options" do
8
+ lambda { Node.new }.should_not raise_exception
9
+ end
10
+
11
+ it "should create a blank node" do
12
+ Node.new.should be_blank
13
+ end
14
+
15
+ it "should create a resource node" do
16
+ resource_uri = URI.parse('http://example.com/nodes#node_1')
17
+ Node.new(resource_uri).should be_resource
18
+ end
19
+
20
+ it "should create a string literal" do
21
+ node = Node.new("hello, world")
22
+ node.should be_literal
23
+ node.datatype.should eql("http://www.w3.org/2001/XMLSchema#string")
24
+ end
25
+
26
+ it "should create a boolean literal" do
27
+ node = Node.new(true)
28
+ node.should be_literal
29
+ node.datatype.should eql("http://www.w3.org/2001/XMLSchema#boolean")
30
+ end
31
+
32
+ it "should create an integer number literal" do
33
+ node = Node.new(10)
34
+ node.should be_literal
35
+ node.datatype.should eql("http://www.w3.org/2001/XMLSchema#int")
36
+ end
37
+
38
+ it "should create a floating-point number literal" do
39
+ node = Node.new(3.1416)
40
+ node.should be_literal
41
+ node.datatype.should eql("http://www.w3.org/2001/XMLSchema#float")
42
+ end
43
+
44
+ it "should create a time literal" do
45
+ node = Node.new(Time.now)
46
+ node.should be_literal
47
+ node.datatype.should eql("http://www.w3.org/2001/XMLSchema#time")
48
+ end
49
+
50
+ it "should create a date literal" do
51
+ node = Node.new(Date.today)
52
+ node.should be_literal
53
+ node.datatype.should eql("http://www.w3.org/2001/XMLSchema#date")
54
+ end
55
+
56
+ it "should create a datetime literal" do
57
+ node = Node.new(DateTime.now)
58
+ node.should be_literal
59
+ node.datatype.should eql("http://www.w3.org/2001/XMLSchema#dateTime")
60
+ end
61
+
62
+ it "should have proper string representation" do
63
+ node = Node.new("Bye-bye, cruel world...")
64
+ node.to_s.should eql('"Bye-bye, cruel world..."^^<http://www.w3.org/2001/XMLSchema#string>')
65
+ end
66
+
67
+ it "should have a proper value for a literal node" do
68
+ t = Time.now
69
+ node = Node.new(t)
70
+ node.value.should be_an_instance_of(Time)
71
+ # surprisingly, two instances of the same time do not compare
72
+ node.value.xmlschema.should eql(t.xmlschema)
73
+ end
74
+
75
+ it "should have a blank identifier for a blank node" do
76
+ node = Node.new
77
+ node.value.should match(/^\(\w+\)$/)
78
+ end
79
+
80
+ it "should have an instance of URI for a resource node" do
81
+ resource_uri = URI.parse('http://example.com/nodes#node_1')
82
+ Node.new(resource_uri).value.should be_an_instance_of(URI::HTTP)
83
+ end
84
+
85
+ end
@@ -0,0 +1,96 @@
1
+ require "spec_helper"
2
+
3
+ describe Parser do
4
+
5
+ it "should be created with default values" do
6
+ lambda {
7
+ Parser.new
8
+ }.should_not raise_exception
9
+ end
10
+
11
+ describe "string source" do
12
+
13
+ it "should be parsed into the model" do
14
+ parser = Parser.new
15
+ model = Model.new
16
+ lambda {
17
+ parser.from_string(model, content[:rdfxml], :base_uri => base_uri[:rdfxml])
18
+ }.should change(model.statements, :size).by(1)
19
+ end
20
+
21
+ end
22
+
23
+ describe "file source" do
24
+
25
+ before :each do
26
+ reference_model = Model.new
27
+ reference_model.from_rdfxml(content[:rdfxml], :base_uri => base_uri[:rdfxml])
28
+ reference_model.to_file(filename)
29
+ end
30
+
31
+ after :each do
32
+ cleanup
33
+ end
34
+
35
+ it "should be parsed into the model" do
36
+ parser = Parser.new
37
+ model = Model.new
38
+ lambda {
39
+ parser.from_file(model, filename, :base_uri => base_uri[:rdfxml])
40
+ }.should change(model.statements, :size).by(1)
41
+ end
42
+
43
+ end
44
+
45
+
46
+ describe "statements" do
47
+
48
+ it do
49
+ Parser.new(:ntriples).statements(content[:ntriples]).should be_an_instance_of(ParserProxy)
50
+ end
51
+
52
+ [:rdfxml, :turtle, :ntriples].each do |format|
53
+ it "should parse #{format} content" do
54
+ parser = Parser.new(format)
55
+ statements = []
56
+ lambda {
57
+ parser.statements(content[format], :base_uri => base_uri[format]).each do |st|
58
+ statements << st
59
+ end
60
+ }.should change(statements, :size).by(1)
61
+ end
62
+ end
63
+
64
+ end
65
+
66
+
67
+ private
68
+
69
+ def cleanup
70
+ File.delete(filename) if File.exists?(filename)
71
+ end
72
+
73
+ def filename
74
+ "test_model.rdf"
75
+ end
76
+
77
+ def content
78
+ {
79
+ :ntriples => '<http://example.org/ns/a2> <http://example.org/ns/b2> <http://example.org/ns/c2> .',
80
+ :turtle => '# this is a complete turtle document
81
+ @prefix foo: <http://example.org/ns#> .
82
+ @prefix : <http://other.example.org/ns#> .
83
+ foo:bar foo: : .',
84
+ :rdfxml => '<?xml version="1.0" encoding="utf-8"?><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"><rdf:Description rdf:about="http://example.com/concepts#two-dimensional_seismic_imaging"><ns0:label xmlns:ns0="http://www.w3.org/2000/01/rdf-schema#" xml:lang="en">2-D seismic imaging</ns0:label></rdf:Description></rdf:RDF>'
85
+ }
86
+ end
87
+
88
+ def base_uri
89
+ {
90
+ :ntriples => nil,
91
+ :turtle => 'http://example.com/concepts',
92
+ :rdfxml => 'http://example.com/concepts'
93
+ }
94
+ end
95
+
96
+ end
@@ -0,0 +1,52 @@
1
+ require "spec_helper"
2
+
3
+ describe Serializer do
4
+
5
+ it "should be created with default values" do
6
+ lambda {
7
+ Serializer.new
8
+ }.should_not raise_exception
9
+ end
10
+
11
+ describe "model" do
12
+
13
+ before :each do
14
+ @model = Model.new
15
+ s = URI.parse("http://example.com/concepts#two-dimensional_seismic_imaging")
16
+ p = URI.parse("http://www.w3.org/2000/01/rdf-schema#label")
17
+ o = "2-D seismic imaging@en"
18
+ @model.statements.create(:subject => s, :predicate => p, :object => o)
19
+ end
20
+
21
+ [:rdfxml, :ntriples, :turtle, :dot, :json].each do |format|
22
+ it "should be serialized into a #{format} string" do
23
+ serializer = Serializer.new(format)
24
+ output = serializer.to_string(@model)
25
+ output.should be_an_instance_of(String)
26
+ output.should_not be_empty
27
+ end
28
+ end
29
+
30
+ it "should be serialized into a file" do
31
+ cleanup
32
+ serializer = Serializer.new(:ntriples)
33
+ serializer.to_file(@model, filename)
34
+ File.should be_exists(filename)
35
+ File.size(filename).should_not be_zero
36
+ cleanup
37
+ end
38
+
39
+
40
+ private
41
+
42
+ def cleanup
43
+ File.delete(filename) if File.exists?(filename)
44
+ end
45
+
46
+ def filename
47
+ "test_model.nt"
48
+ end
49
+
50
+ end
51
+
52
+ end
@@ -0,0 +1,86 @@
1
+ require "spec_helper"
2
+
3
+ describe Statement do
4
+
5
+ it "should be created with default values" do
6
+ statement = nil
7
+ lambda { statement = Statement.new }.should_not raise_exception
8
+ statement.subject.should be_nil
9
+ statement.predicate.should be_nil
10
+ statement.object.should be_nil
11
+ end
12
+
13
+ it "should be created with the given values" do
14
+ statement = create_statement
15
+ statement.subject.should be_an_instance_of(Node)
16
+ statement.predicate.should be_an_instance_of(Node)
17
+ statement.object.should be_an_instance_of(Node)
18
+ end
19
+
20
+ it "should have proper attributes" do
21
+ statement = create_statement
22
+ statement.subject.value.to_s.should eql('http://example.com/concepts#subject')
23
+ statement.predicate.value.to_s.should eql('http://example.com/concepts#label')
24
+ statement.object.value.should eql('subject!')
25
+ end
26
+
27
+ it do
28
+ statement = Statement.new
29
+ lambda {
30
+ statement.should_not be_valid
31
+ }.should change(statement.errors, :size).by(1)
32
+ end
33
+
34
+ it do
35
+ create_statement.should be_valid
36
+ end
37
+
38
+ it "should be added to the model" do
39
+ model = Model.new
40
+ statement = create_statement
41
+ lambda {
42
+ statement.model = model
43
+ }.should change(model.statements, :size).by(1)
44
+ statement.model.should be(model)
45
+ end
46
+
47
+ [:subject, :predicate, :object].each do |attribute|
48
+ it "should be assigned a #{attribute}" do
49
+ statement = Statement.new
50
+ attr = Node.new(statement_attributes[attribute])
51
+ lambda {
52
+ statement.send("#{attribute}=", attr)
53
+ }.should change(statement, attribute).from(nil).to(attr)
54
+ end
55
+ end
56
+
57
+ it "should not be assigned the same attribute twice" do
58
+ statement = Statement.new
59
+ object = "object!"
60
+ lambda {
61
+ 2.times do
62
+ statement.object = object
63
+ end
64
+ }.should raise_exception
65
+ object.should be_frozen
66
+ end
67
+
68
+
69
+ private
70
+
71
+ def create_statement
72
+ Statement.new(statement_attributes)
73
+ end
74
+
75
+ def statement_attributes
76
+ s = URI.parse('http://example.com/concepts#subject')
77
+ p = URI.parse('http://example.com/concepts#label')
78
+ o = "subject!"
79
+ {
80
+ :subject => s,
81
+ :predicate => p,
82
+ :object => o
83
+ }
84
+ end
85
+
86
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,10 @@
1
+ $:.unshift(File.join(File.dirname(__FILE__), "..")) unless
2
+ $:.include?(File.join(File.dirname(__FILE__), "..")) || $:.include?(File.expand_path(File.join(File.dirname(__FILE__), "..")))
3
+
4
+ require 'spec/autorun'
5
+
6
+ require 'lib/redlander'
7
+ include Redlander
8
+
9
+ Spec::Runner.configure do |config|
10
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: redlander
3
+ version: !ruby/object:Gem::Version
4
+ hash: 21
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 2
9
+ - 1
10
+ version: 0.2.1
11
+ platform: ruby
12
+ authors:
13
+ - Slava Kravchenko
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-06-18 00:00:00 +03:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: xml_schema
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - "="
28
+ - !ruby/object:Gem::Version
29
+ hash: 29
30
+ segments:
31
+ - 0
32
+ - 0
33
+ - 1
34
+ version: 0.0.1
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: rspec
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ hash: 1
46
+ segments:
47
+ - 1
48
+ version: "1"
49
+ type: :development
50
+ version_requirements: *id002
51
+ description: " Advanced Redland bindings.\n"
52
+ email: slava.kravchenko@gmail.com
53
+ executables: []
54
+
55
+ extensions:
56
+ - ext/extconf.rb
57
+ extra_rdoc_files:
58
+ - README.rdoc
59
+ files:
60
+ - lib/redlander/error_container.rb
61
+ - lib/redlander/model.rb
62
+ - lib/redlander/model_proxy.rb
63
+ - lib/redlander/node.rb
64
+ - lib/redlander/parser_proxy.rb
65
+ - lib/redlander/serializer.rb
66
+ - lib/redlander/statement.rb
67
+ - lib/redlander/statement_iterator.rb
68
+ - lib/redlander/storage.rb
69
+ - lib/redlander/version.rb
70
+ - lib/redlander/parser.rb
71
+ - spec/redlander/model_spec.rb
72
+ - spec/redlander/node_spec.rb
73
+ - spec/redlander/parser_spec.rb
74
+ - spec/redlander/serializer_spec.rb
75
+ - spec/redlander/statement_spec.rb
76
+ - spec/spec.opts
77
+ - spec/spec_helper.rb
78
+ - ext/extconf.rb
79
+ - ext/redland-pre.i
80
+ - ext/redland-types.i
81
+ - ext/redland_wrap.c
82
+ - ext/README
83
+ - Rakefile
84
+ - lib/redlander.rb
85
+ - README.rdoc
86
+ has_rdoc: true
87
+ homepage: https://github.com/cordawyn/redlander
88
+ licenses: []
89
+
90
+ post_install_message:
91
+ rdoc_options: []
92
+
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ hash: 3
101
+ segments:
102
+ - 0
103
+ version: "0"
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ hash: 3
110
+ segments:
111
+ - 0
112
+ version: "0"
113
+ requirements: []
114
+
115
+ rubyforge_project:
116
+ rubygems_version: 1.6.2
117
+ signing_key:
118
+ specification_version: 3
119
+ summary: Advanced Redland bindings.
120
+ test_files:
121
+ - spec/redlander/model_spec.rb
122
+ - spec/redlander/node_spec.rb
123
+ - spec/redlander/parser_spec.rb
124
+ - spec/redlander/serializer_spec.rb
125
+ - spec/redlander/statement_spec.rb
126
+ - spec/spec.opts
127
+ - spec/spec_helper.rb