@@ -10,73 +10,65 @@ use std::fs::{self, File};
1010
1111#[ test]
1212fn test_graph_triple_count ( ) {
13- let triple_count_string = json_to_rdf ( & "tests/airplane.json" . to_string ( ) , & None , & None ) ;
13+ let triple_count_string = json_to_rdf ( & [ "tests/airplane.json" ] , None , None ) ;
1414
1515 assert ! ( triple_count_string. is_ok( ) ) ;
1616 assert_eq ! ( triple_count_string. unwrap( ) . unwrap( ) . len( ) , 23 ) ;
1717}
1818
1919#[ test]
2020fn test_graph_write ( ) {
21- let output = "out.nt" . to_string ( ) ;
21+ let output = "out.nt" ;
2222
23- let res = json_to_rdf (
24- & "tests/airplane.json" . to_string ( ) ,
25- & None ,
26- & Some ( output. clone ( ) ) ,
27- ) ;
23+ let res = json_to_rdf ( & [ "tests/airplane.json" ] , None , Some ( output) ) ;
2824
2925 assert ! ( res. is_ok( ) ) ;
3026 assert ! ( res. unwrap( ) . is_none( ) ) ;
3127
32- let f = File :: open ( output. clone ( ) ) . expect ( "unable to open output file for result verification" ) ;
28+ let f = File :: open ( output) . expect ( "unable to open output file for result verification" ) ;
3329 let quads = RdfParser :: from_format ( RdfFormat :: NTriples )
3430 . for_reader ( f)
3531 . collect :: < Result < Vec < _ > , _ > > ( )
3632 . expect ( "failed to parse generated output file" ) ;
3733
3834 assert_eq ! ( quads. len( ) , 23 ) ;
39- let _ = fs:: remove_file ( output. clone ( ) ) ;
35+ let _ = fs:: remove_file ( output) ;
4036}
4137
4238#[ test]
4339fn test_graph_write_truncates_existing ( ) {
44- let output = "out_truncate.nt" . to_string ( ) ;
40+ let output = "out_truncate.nt" ;
4541
4642 // Pre-populate with junk to prove truncation happens.
47- fs:: write ( & output, "stale garbage\n " ) . expect ( "unable to seed stale output" ) ;
43+ fs:: write ( output, "stale garbage\n " ) . expect ( "unable to seed stale output" ) ;
4844
4945 // Two writes in a row should not accumulate; final file should hold one run's worth.
5046 for _ in 0 ..2 {
51- let res = json_to_rdf (
52- & "tests/airplane.json" . to_string ( ) ,
53- & None ,
54- & Some ( output. clone ( ) ) ,
55- ) ;
47+ let res = json_to_rdf ( & [ "tests/airplane.json" ] , None , Some ( output) ) ;
5648 assert ! ( res. is_ok( ) ) ;
5749 }
5850
59- let f = File :: open ( & output) . expect ( "unable to open output file for result verification" ) ;
51+ let f = File :: open ( output) . expect ( "unable to open output file for result verification" ) ;
6052 let quads = RdfParser :: from_format ( RdfFormat :: NTriples )
6153 . for_reader ( f)
6254 . collect :: < Result < Vec < _ > , _ > > ( )
6355 . expect ( "failed to parse generated output file" ) ;
6456
6557 assert_eq ! ( quads. len( ) , 23 ) ;
66- let _ = fs:: remove_file ( & output) ;
58+ let _ = fs:: remove_file ( output) ;
6759}
6860
6961#[ test]
7062fn test_root_array ( ) {
71- let graph = json_to_rdf ( & "tests/root_array.json" . to_string ( ) , & None , & None )
63+ let graph = json_to_rdf ( & [ "tests/root_array.json" ] , None , None )
7264 . expect ( "conversion failed" )
7365 . expect ( "expected graph" ) ;
7466 assert_eq ! ( graph. len( ) , 2 ) ;
7567}
7668
7769#[ test]
7870fn test_root_primitive_errors ( ) {
79- let result = json_to_rdf ( & "tests/root_primitive.json" . to_string ( ) , & None , & None ) ;
71+ let result = json_to_rdf ( & [ "tests/root_primitive.json" ] , None , None ) ;
8072 assert ! ( matches!(
8173 result,
8274 Err ( Json2RdfError :: UnsupportedRootValue { kind: "number" } )
@@ -85,18 +77,103 @@ fn test_root_primitive_errors() {
8577
8678#[ test]
8779fn test_ndjson_stream_isolated ( ) {
88- let graph = json_to_rdf ( & "tests/ndjson.json" . to_string ( ) , & None , & None )
80+ let graph = json_to_rdf ( & [ "tests/ndjson.json" ] , None , None )
8981 . expect ( "conversion failed" )
9082 . expect ( "expected graph" ) ;
9183 assert_eq ! ( graph. len( ) , 2 ) ;
9284}
9385
86+ #[ test]
87+ fn test_multi_file_merges_graphs ( ) {
88+ // root_array.json → 2 triples; ndjson.json → 2 triples; merged = 4.
89+ let graph = json_to_rdf ( & [ "tests/root_array.json" , "tests/ndjson.json" ] , None , None )
90+ . expect ( "conversion failed" )
91+ . expect ( "expected graph" ) ;
92+ assert_eq ! ( graph. len( ) , 4 ) ;
93+ }
94+
95+ #[ test]
96+ fn test_large_integers_preserve_precision ( ) {
97+ let graph = json_to_rdf ( & [ "tests/large_int.json" ] , None , None )
98+ . expect ( "conversion failed" )
99+ . expect ( "expected graph" ) ;
100+ let serialized = graph. to_string ( ) ;
101+ assert ! (
102+ serialized. contains( "\" 9223372036854775807\" ^^<http://www.w3.org/2001/XMLSchema#integer>" ) ,
103+ "i64::MAX should round-trip as xsd:integer, got:\n {}" ,
104+ serialized
105+ ) ;
106+ assert ! (
107+ serialized. contains( "\" 18446744073709551615\" ^^<http://www.w3.org/2001/XMLSchema#integer>" ) ,
108+ "u64::MAX should round-trip as xsd:integer (not xsd:double), got:\n {}" ,
109+ serialized
110+ ) ;
111+ }
112+
113+ #[ test]
114+ fn test_empty_file_returns_empty_graph ( ) {
115+ let graph = json_to_rdf ( & [ "tests/empty_file.json" ] , None , None )
116+ . expect ( "conversion failed" )
117+ . expect ( "expected graph" ) ;
118+ assert_eq ! ( graph. len( ) , 0 ) ;
119+ }
120+
121+ #[ test]
122+ fn test_empty_object_at_root_produces_no_triples ( ) {
123+ let graph = json_to_rdf ( & [ "tests/empty_object.json" ] , None , None )
124+ . expect ( "conversion failed" )
125+ . expect ( "expected graph" ) ;
126+ assert_eq ! ( graph. len( ) , 0 ) ;
127+ }
128+
129+ #[ test]
130+ fn test_malformed_json_returns_error ( ) {
131+ let result = json_to_rdf ( & [ "tests/malformed.json" ] , None , None ) ;
132+ assert ! (
133+ matches!( result, Err ( Json2RdfError :: Json ( _) ) ) ,
134+ "expected Json2RdfError::Json, got {:?}" ,
135+ result. err( )
136+ ) ;
137+ }
138+
139+ #[ test]
140+ fn test_missing_file_returns_error ( ) {
141+ let result = json_to_rdf ( & [ "tests/does_not_exist.json" ] , None , None ) ;
142+ assert ! (
143+ matches!( result, Err ( Json2RdfError :: Io ( _) ) ) ,
144+ "expected Json2RdfError::Io, got {:?}" ,
145+ result. err( )
146+ ) ;
147+ }
148+
149+ #[ test]
150+ fn test_invalid_iri_key_returns_error ( ) {
151+ let result = json_to_rdf ( & [ "tests/invalid_iri_key.json" ] , None , None ) ;
152+ assert ! (
153+ matches!( result, Err ( Json2RdfError :: InvalidIri { .. } ) ) ,
154+ "expected Json2RdfError::InvalidIri, got {:?}" ,
155+ result. err( )
156+ ) ;
157+ }
158+
159+ #[ test]
160+ fn test_unicode_key_in_iri_range ( ) {
161+ let graph = json_to_rdf ( & [ "tests/unicode_key.json" ] , None , None )
162+ . expect ( "conversion failed" )
163+ . expect ( "expected graph" ) ;
164+ assert_eq ! ( graph. len( ) , 1 ) ;
165+ assert ! (
166+ graph. to_string( ) . contains( "中文" ) ,
167+ "expected unicode predicate in output"
168+ ) ;
169+ }
170+
94171#[ test]
95172fn test_hash_namespace_not_mangled ( ) {
96173 let graph = json_to_rdf (
97- & "tests/airplane.json" . to_string ( ) ,
98- & Some ( "http://example.com/ns#" . to_string ( ) ) ,
99- & None ,
174+ & [ "tests/airplane.json" ] ,
175+ Some ( "http://example.com/ns#" ) ,
176+ None ,
100177 )
101178 . expect ( "conversion failed" )
102179 . expect ( "expected graph" ) ;
@@ -117,9 +194,9 @@ fn test_hash_namespace_not_mangled() {
117194#[ test]
118195fn test_slash_namespace_no_double_slash ( ) {
119196 let graph = json_to_rdf (
120- & "tests/airplane.json" . to_string ( ) ,
121- & Some ( "http://example.com/ns/" . to_string ( ) ) ,
122- & None ,
197+ & [ "tests/airplane.json" ] ,
198+ Some ( "http://example.com/ns/" ) ,
199+ None ,
123200 )
124201 . expect ( "conversion failed" )
125202 . expect ( "expected graph" ) ;
0 commit comments