Skip to content

Commit

Permalink
Test limiting returned results to xsd:string
Browse files Browse the repository at this point in the history
  • Loading branch information
elrayle committed May 11, 2019
1 parent 89982ea commit 3135360
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
4 changes: 1 addition & 3 deletions lib/ldpath/tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ def initialize(lang)

def evaluate(_program, uri, _context)
return unless uri.literal?

uri if (lang.to_s == "none" && !uri.has_language?) || uri.language.to_s == lang.to_s
end
end
Expand All @@ -41,8 +40,7 @@ def initialize(type)

def evaluate(program, uri, _context)
return unless uri.literal?

uri if uri.has_datatype? && uri.datatype == type
uri if (uri.has_datatype? && uri.datatype == type) || (uri.plain? && uri.datatype == type)
end
end

Expand Down
9 changes: 7 additions & 2 deletions spec/ldpath_program_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
conditional_false = dcterms:isPartOf[dcterms:description] ;
int_value = <info:intProperty>[^^xsd:integer] :: xsd:integer ;
numeric_value = <info:numericProperty> :: xsd:integer ;
string_title = dcterms:title[^^xsd:string] :: xsd:string ;
escaped_string = "\\"" :: xsd:string;
and_test = .[dcterms:title & dcterms:gone] ;
or_test = .[dcterms:title | dcterms:gone] ;
Expand All @@ -38,7 +39,10 @@
end

it "should work" do
b1 = RDF::Node.new('b1')
graph << [object, RDF::Vocab::DC.title, "Hello, world!"]
graph << [object, RDF::Vocab::DC.title, b1]
graph << [b1, RDF::Vocab::SKOS.prefLabel, "Title through blank node"]
graph << [object, RDF::Vocab::DC.isPartOf, parent]
graph << [object, RDF::Vocab::DC.description, RDF::Literal.new("English!", language: "en")]
graph << [object, RDF::Vocab::DC.description, RDF::Literal.new("French!", language: "fr")]
Expand All @@ -53,20 +57,21 @@
graph << [parent, RDF::Vocab::DC.isPartOf, grandparent]

result = subject.evaluate object, context: graph
expect(result["title"]).to match_array "Hello, world!"
expect(result["title"]).to match_array ["Hello, world!", "_:b1"]
expect(result["parent_title"]).to match_array ["Parent title", "Parent English!", "Parent French!"]
expect(result["parent_title_en"]).to match_array "Parent English!"
expect(result["self"]).to match_array(object)
expect(result["wildcard"]).to include "Hello, world!", parent
expect(result["child_title"]).to match_array "Child title"
expect(result["titles"]).to match_array ["Hello, world!", "Parent title", "Child title", "Parent English!", "Parent French!"]
expect(result["titles"]).to match_array ["Hello, world!", "Parent title", "Child title", "Parent English!", "Parent French!", "_:b1"]
expect(result["no_titles"]).to be_empty
expect(result["recursive"]).to match_array [parent, grandparent]
expect(result["en_description"].first.to_s).to eq "English!"
expect(result["conditional"]).to match_array parent
expect(result["conditional_false"]).to be_empty
expect(result["int_value"]).to match_array 1
expect(result["numeric_value"]).to match_array 1
expect(result["string_title"]).to match_array ["Hello, world!"]
expect(result["escaped_string"]).to match_array '\"'
expect(result["and_test"]).to be_empty
expect(result["or_test"]).to match_array(object)
Expand Down

0 comments on commit 3135360

Please sign in to comment.