@@ -99,13 +99,23 @@ def run_tc(man, tc, options)
9999 compare_results ( tc , output , expected )
100100 when 'jld:FromRDFTest'
101101 repo = RDF ::Repository . load ( tc . input_loc , format : :nquads )
102- output = JSON ::LD ::API . fromRdf ( repo , validate : true , **tc . options )
102+ output = if options [ :stream ]
103+ JSON . parse ( JSON ::LD ::Writer . buffer ( stream : true , validate : true , **tc . options ) { |w | w << repo } )
104+ else
105+ JSON ::LD ::API . fromRdf ( repo , validate : true , **tc . options )
106+ end
103107 expected = JSON . load ( tc . expect ) if tc . evaluationTest? && tc . positiveTest?
104108 compare_results ( tc , output , expected )
105109 when 'jld:ToRDFTest'
106110 output = RDF ::Repository . new . extend ( RDF ::Isomorphic )
107- JSON ::LD ::API . toRdf ( tc . input_loc , **tc . options ) . map do |statement |
108- output << statement
111+ if options [ :stream ]
112+ JSON ::LD ::Reader . open ( tc . input_loc , stream : true , **tc . options . merge ( logger : false ) ) do |statement |
113+ output << statement
114+ end
115+ else
116+ JSON ::LD ::API . toRdf ( tc . input_loc , **tc . options ) . map do |statement |
117+ output << statement
118+ end
109119 end
110120
111121 if tc . evaluationTest? && tc . positiveTest?
@@ -122,7 +132,7 @@ def run_tc(man, tc, options)
122132 expected = RDF ::Repository . new << RDF ::NQuads ::Reader . new ( tc . expect , validate : false , logger : [ ] )
123133 output . isomorphic? ( expected ) ? 'passed' : 'failed'
124134 end
125- rescue RDF ::ReaderError
135+ rescue RDF ::ReaderError , JSON :: LD :: JsonLdError
126136 quads = JSON ::LD ::API . toRdf ( tc . input_loc , tc . options . merge ( validate : false ) ) . map do |statement |
127137 # Not really RDF, try different test method
128138 tc . to_quad ( statement )
@@ -131,14 +141,13 @@ def run_tc(man, tc, options)
131141 # FIXME: toRDF is outputing duplicate quads
132142 output = quads . sort . uniq . join ( "" )
133143 output == tc . expect ? 'passed' : 'failed'
134- ensure
135- output = output . dump ( :nquads , validate : false ) rescue output . to_s unless output . is_a? ( String )
136144 end
137145 else
138146 output . count > 0 ? 'passed' : 'failed'
139147 end
140148 end || "untested"
141149
150+ output = output . dump ( :nquads , validate : false ) rescue output . to_s if output . is_a? ( RDF ::Enumerable )
142151 puts "\n Output:\n " + ( tc . testType == 'jld:ToRDFTest' ? output : output . to_json ( JSON ::LD ::JSON_STATE ) ) if !tc . syntaxTest? && options [ :verbose ]
143152
144153 result = result ? 'failed' : 'passed' unless tc . positiveTest?
@@ -206,6 +215,7 @@ opts = GetoptLong.new(
206215 [ "--earl" , GetoptLong ::NO_ARGUMENT ] ,
207216 [ "--quiet" , "-q" , GetoptLong ::NO_ARGUMENT ] ,
208217 [ "--output" , "-o" , GetoptLong ::REQUIRED_ARGUMENT ] ,
218+ [ "--stream" , GetoptLong ::NO_ARGUMENT ] ,
209219 [ "--validate" , GetoptLong ::NO_ARGUMENT ] ,
210220 [ "--verbose" , "-v" , GetoptLong ::NO_ARGUMENT ]
211221)
@@ -217,6 +227,7 @@ def help(options)
217227 puts " --earl: Generate EARL report"
218228 puts " --quiet: Minimal output"
219229 puts " --output: Output to specified file"
230+ puts " --stream: Use streaming RDF reader/writer"
220231 puts " --validate: Validate input"
221232 puts " --verbose: Verbose processing"
222233 puts " --help,-?: This message"
@@ -234,21 +245,25 @@ opts.each do |opt, arg|
234245 when '--quiet'
235246 options [ :quiet ] = true
236247 logger . level = Logger ::FATAL
248+ when '--stream' then options [ :stream ] = true
237249 when '--validate' then options [ :validate ] = true
238250 when '--verbose' then options [ :verbose ] = true
239251 end
240252end
241253
242254manifests = %w( expand compact flatten fromRdf html remote-doc toRdf ) . map do |man |
243255 "#{ Fixtures ::SuiteTest ::SUITE } #{ man } -manifest.jsonld"
244- end + [ "#{ Fixtures ::SuiteTest ::FRAME_SUITE } frame-manifest.jsonld" ]
256+ end +
257+ [ "#{ Fixtures ::SuiteTest ::FRAME_SUITE } frame-manifest.jsonld" ] +
258+ [ "#{ Fixtures ::SuiteTest ::STREAM_SUITE } stream-toRdf-manifest.jsonld" ]
245259
246260earl_preamble ( options ) if options [ :earl ]
247261
248262manifests . each do |man |
249263 Fixtures ::SuiteTest ::Manifest . open ( man ) do |m |
250264 m . entries . each do |tc |
251265 next unless ARGV . empty? || ARGV . any? { |n | tc . property ( '@id' ) . match ( /#{ n } / ) || tc . property ( 'input' ) . match ( /#{ n } / ) }
266+ options = { stream : true } . merge ( options ) if man . include? ( 'stream' )
252267 run_tc ( man . sub ( ".jsonld" , "" ) , tc , options )
253268 end
254269 end
0 commit comments