Skip to content

Commit 6a33d05

Browse files
committed
add test for writing to file
1 parent f76e2d5 commit 6a33d05

1 file changed

Lines changed: 34 additions & 6 deletions

File tree

tests/integration_test.rs

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,41 @@
1+
// Copyright (c) 2024-2025, DeciSym, LLC
2+
// Licensed under either of:
3+
// - Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
4+
// - BSD 3-Clause License (https://opensource.org/licenses/BSD-3-Clause)
5+
// at your option.
6+
17
use json2rdf::json_to_rdf;
8+
use oxrdfio::{RdfFormat, RdfParser};
9+
use std::fs::{self, File};
210

311
#[test]
412
fn test_graph_triple_count() {
513
let triple_count_string = json_to_rdf(&"tests/airplane.json".to_string(), &None, &None);
614

7-
match triple_count_string {
8-
Ok(res) => {
9-
assert_eq!(res.unwrap().len(), 23)
10-
}
11-
Err(e) => eprintln!("Error writing: {}", e),
12-
}
15+
assert!(triple_count_string.is_ok());
16+
assert_eq!(triple_count_string.unwrap().unwrap().len(), 23);
17+
}
18+
19+
#[test]
20+
fn test_graph_write() {
21+
let output = "out.nt".to_string();
22+
let _ = fs::remove_file(output.clone());
23+
24+
let res = json_to_rdf(
25+
&"tests/airplane.json".to_string(),
26+
&None,
27+
&Some(output.clone()),
28+
);
29+
30+
assert!(res.is_ok());
31+
assert!(res.unwrap().is_none());
32+
33+
let f = File::open(output.clone()).expect("unable to open output file for result verification");
34+
let quads = RdfParser::from_format(RdfFormat::NTriples)
35+
.for_reader(f)
36+
.collect::<Result<Vec<_>, _>>()
37+
.expect("failed to parse generated output file");
38+
39+
assert_eq!(quads.len(), 23);
40+
let _ = fs::remove_file(output.clone());
1341
}

0 commit comments

Comments
 (0)