|
| 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 | + |
1 | 7 | use json2rdf::json_to_rdf; |
| 8 | +use oxrdfio::{RdfFormat, RdfParser}; |
| 9 | +use std::fs::{self, File}; |
2 | 10 |
|
3 | 11 | #[test] |
4 | 12 | fn test_graph_triple_count() { |
5 | 13 | let triple_count_string = json_to_rdf(&"tests/airplane.json".to_string(), &None, &None); |
6 | 14 |
|
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()); |
13 | 41 | } |
0 commit comments