667667 %q(
668668 [<http://rdfs.org/sioc/ns#content> "foo"^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral>] .
669669 )
670- ]
670+ ] ,
671671 } . each do |title , ( js , ttl ) |
672672 it title do
673673 ttl = "@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . #{ ttl } "
674674 expect ( parse ( js ) ) . to be_equivalent_graph ( ttl , logger : logger , inputDocument : js )
675675 end
676676 end
677677 end
678+
679+ context "exceptions" do
680+ {
681+ "Invalid subject" => {
682+ input : %({
683+ "@id": "http://example.com/a b",
684+ "http://example.com/foo": "bar"
685+ }) ,
686+ output : %()
687+ } ,
688+ "Invalid predicate" => {
689+ input : %({
690+ "@id": "http://example.com/foo",
691+ "http://example.com/a b": "bar"
692+ }) ,
693+ output : %()
694+ } ,
695+ "Invalid object" => {
696+ input : %({
697+ "@id": "http://example.com/foo",
698+ "http://example.com/bar": {"@id": "http://example.com/baz z"}
699+ }) ,
700+ output : %()
701+ } ,
702+ "Invalid type" => {
703+ input : %({
704+ "@id": "http://example.com/foo",
705+ "@type": ["http://example.com/bar", "relative"]
706+ }) ,
707+ output : %(<http://example.com/foo> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.com/bar> .)
708+ } ,
709+ "Invalid language" => {
710+ input : %({
711+ "@id": "http://example.com/foo",
712+ "http://example.com/bar": {"@value": "bar", "@language": "a b"}
713+ }) ,
714+ output : %()
715+ } ,
716+ "Invalid datatype" => {
717+ input : %({
718+ "@id": "http://example.com/foo",
719+ "http://example.com/bar": {"@value": "bar", "@type": "http://example.com/baz z"}
720+ }) ,
721+ output : %()
722+ } ,
723+ "Injected IRIs check" => {
724+ input : %({
725+ "@id": "http://foo/> <http://bar/> <http://baz> .\n <data:little> <data:bobby> <data:tables> .\n <data:in-ur-base",
726+ "http://killin/#yer": "dudes"
727+ }) ,
728+ output : %()
729+ } ,
730+ } . each do |title , params |
731+ it ( title ) { run_to_rdf params }
732+ end
733+ end
678734 end
679735
680736 def parse ( input , options = { } )
@@ -683,4 +739,17 @@ def parse(input, options = {})
683739 JSON ::LD ::API . toRdf ( StringIO . new ( input ) , options ) { |st | graph << st }
684740 graph
685741 end
742+
743+ def run_to_rdf ( params )
744+ input , output , processingMode = params [ :input ] , params [ :output ] , params [ :processingMode ]
745+ graph = params [ :graph ] || RDF ::Graph . new
746+ input = StringIO . new ( input ) if input . is_a? ( String )
747+ pending params . fetch ( :pending , "test implementation" ) unless input
748+ if params [ :exception ]
749+ expect { JSON ::LD ::API . toRdf ( input , { processingMode : processingMode } . merge ( params ) ) } . to raise_error ( params [ :exception ] )
750+ else
751+ JSON ::LD ::API . toRdf ( input , base : params [ :base ] , logger : logger , processingMode : processingMode ) { |st | graph << st }
752+ expect ( graph ) . to be_equivalent_graph ( output , logger : logger , inputDocument : input )
753+ end
754+ end
686755end
0 commit comments