Skip to content

Commit b22fbca

Browse files
refactor: centralize Rust tests in lib/tests and rename concurrency file
Co-authored-by: aider (openai/gpt-5) <[email protected]>
1 parent c5c0424 commit b22fbca

File tree

4 files changed

+109
-115
lines changed

4 files changed

+109
-115
lines changed

lib/src/ontology.rs

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -565,44 +565,3 @@ impl Ontology {
565565
}
566566
}
567567

568-
#[cfg(test)]
569-
mod tests {
570-
use super::*;
571-
572-
use oxigraph::model::NamedNode;
573-
574-
#[test]
575-
fn test_ontology_location() {
576-
let url = "http://example.com/ontology.ttl";
577-
let file = "/tmp/ontology.ttl";
578-
let url_location = OntologyLocation::from_str(url).unwrap();
579-
let file_location = OntologyLocation::from_str(file).unwrap();
580-
assert!(url_location.is_url());
581-
assert!(!url_location.is_file());
582-
assert!(!file_location.is_url());
583-
assert!(file_location.is_file());
584-
}
585-
586-
#[test]
587-
fn test_ontology_location_display() {
588-
let url = "http://example.com/ontology.ttl";
589-
let file = "/tmp/ontology.ttl";
590-
let url_location = OntologyLocation::from_str(url).unwrap();
591-
let file_location = OntologyLocation::from_str(file).unwrap();
592-
assert_eq!(url_location.to_string(), url);
593-
assert_eq!(file_location.to_string(), format!("file://{}", file));
594-
}
595-
596-
#[test]
597-
fn test_ontology_location_to_iri() {
598-
let url = "http://example.com/ontology.ttl";
599-
let file = "/tmp/ontology.ttl";
600-
let url_location = OntologyLocation::from_str(url).unwrap();
601-
let file_location = OntologyLocation::from_str(file).unwrap();
602-
assert_eq!(url_location.to_iri(), NamedNode::new(url).unwrap());
603-
assert_eq!(
604-
file_location.to_iri(),
605-
NamedNode::new(format!("file://{}", file)).unwrap()
606-
);
607-
}
608-
}

lib/src/util.rs

Lines changed: 0 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -189,77 +189,3 @@ pub fn graph_to_quads<'a>(
189189
.map(move |triple| triple.in_graph(graph_name))
190190
}
191191

192-
#[cfg(test)]
193-
mod tests {
194-
use super::*;
195-
use oxigraph::model::{Dataset, GraphNameRef, NamedNodeRef, QuadRef};
196-
197-
#[test]
198-
fn test_read_file() {
199-
// testing turtle file
200-
let graph = read_file(Path::new("fixtures/fileendings/model.ttl")).unwrap();
201-
assert_eq!(graph.len(), 5);
202-
203-
// testing ntriples file
204-
let graph = read_file(Path::new("fixtures/fileendings/model.nt")).unwrap();
205-
assert_eq!(graph.len(), 5);
206-
207-
// testing n3 file
208-
let graph = read_file(Path::new("fixtures/fileendings/model.n3")).unwrap();
209-
assert_eq!(graph.len(), 5);
210-
//
211-
// testing xml file
212-
let graph = read_file(Path::new("fixtures/fileendings/model.xml")).unwrap();
213-
assert_eq!(graph.len(), 5);
214-
215-
// testing default turtle file
216-
let graph = read_file(Path::new("fixtures/fileendings/model")).unwrap();
217-
assert_eq!(graph.len(), 5);
218-
219-
// reading non-existent file should return an error
220-
let result = read_file(Path::new("fixtures/data/non-existent.ttl"));
221-
assert!(result.is_err());
222-
}
223-
224-
#[test]
225-
fn test_read_url() {
226-
let graph =
227-
read_url("https://github.com/BrickSchema/Brick/releases/download/v1.4.0-rc1/Brick.ttl")
228-
.unwrap();
229-
assert_eq!(graph.len(), 53478);
230-
231-
// reading non-existent url should return an error
232-
let result = read_url("http://example.org/non-existent.ttl");
233-
assert!(result.is_err());
234-
}
235-
236-
#[test]
237-
fn test_write_dataset_to_file() {
238-
// create in-memory dataset
239-
let mut graph = Dataset::new();
240-
let model = read_file(Path::new("fixtures/fileendings/model.ttl")).unwrap();
241-
let model_name =
242-
GraphNameRef::NamedNode(NamedNodeRef::new("http://example.org/model").unwrap());
243-
let brick = read_file(Path::new("fixtures/brick-stuff/Brick-1.3.ttl")).unwrap();
244-
let brick_name =
245-
GraphNameRef::NamedNode(NamedNodeRef::new("http://example.org/brick").unwrap());
246-
for quad in model.iter() {
247-
graph.insert(QuadRef::new(
248-
quad.subject,
249-
quad.predicate,
250-
quad.object,
251-
model_name,
252-
));
253-
}
254-
for quad in brick.iter() {
255-
graph.insert(QuadRef::new(
256-
quad.subject,
257-
quad.predicate,
258-
quad.object,
259-
brick_name,
260-
));
261-
}
262-
263-
write_dataset_to_file(&graph, "model_out.ttl").unwrap();
264-
}
265-
}

lib/tests/test_ontology.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
use ontoenv::ontology::OntologyLocation;
2+
use oxigraph::model::NamedNode;
3+
4+
#[test]
5+
fn test_ontology_location() {
6+
let url = "http://example.com/ontology.ttl";
7+
let file = "/tmp/ontology.ttl";
8+
let url_location = OntologyLocation::from_str(url).unwrap();
9+
let file_location = OntologyLocation::from_str(file).unwrap();
10+
assert!(url_location.is_url());
11+
assert!(!url_location.is_file());
12+
assert!(!file_location.is_url());
13+
assert!(file_location.is_file());
14+
}
15+
16+
#[test]
17+
fn test_ontology_location_display() {
18+
let url = "http://example.com/ontology.ttl";
19+
let file = "/tmp/ontology.ttl";
20+
let url_location = OntologyLocation::from_str(url).unwrap();
21+
let file_location = OntologyLocation::from_str(file).unwrap();
22+
assert_eq!(url_location.to_string(), url);
23+
assert_eq!(file_location.to_string(), format!("file://{}", file));
24+
}
25+
26+
#[test]
27+
fn test_ontology_location_to_iri() {
28+
let url = "http://example.com/ontology.ttl";
29+
let file = "/tmp/ontology.ttl";
30+
let url_location = OntologyLocation::from_str(url).unwrap();
31+
let file_location = OntologyLocation::from_str(file).unwrap();
32+
assert_eq!(url_location.to_iri(), NamedNode::new(url).unwrap());
33+
assert_eq!(
34+
file_location.to_iri(),
35+
NamedNode::new(format!("file://{}", file)).unwrap()
36+
);
37+
}

lib/tests/test_util.rs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
use ontoenv::util::{read_file, read_url, write_dataset_to_file};
2+
use oxigraph::model::{Dataset, GraphNameRef, NamedNodeRef, QuadRef};
3+
use std::path::Path;
4+
5+
#[test]
6+
fn test_read_file() {
7+
// testing turtle file
8+
let graph = read_file(Path::new("fixtures/fileendings/model.ttl")).unwrap();
9+
assert_eq!(graph.len(), 5);
10+
11+
// testing ntriples file
12+
let graph = read_file(Path::new("fixtures/fileendings/model.nt")).unwrap();
13+
assert_eq!(graph.len(), 5);
14+
15+
// testing n3 file
16+
let graph = read_file(Path::new("fixtures/fileendings/model.n3")).unwrap();
17+
assert_eq!(graph.len(), 5);
18+
//
19+
// testing xml file
20+
let graph = read_file(Path::new("fixtures/fileendings/model.xml")).unwrap();
21+
assert_eq!(graph.len(), 5);
22+
23+
// testing default turtle file
24+
let graph = read_file(Path::new("fixtures/fileendings/model")).unwrap();
25+
assert_eq!(graph.len(), 5);
26+
27+
// reading non-existent file should return an error
28+
let result = read_file(Path::new("fixtures/data/non-existent.ttl"));
29+
assert!(result.is_err());
30+
}
31+
32+
#[test]
33+
fn test_read_url() {
34+
let graph =
35+
read_url("https://github.com/BrickSchema/Brick/releases/download/v1.4.0-rc1/Brick.ttl")
36+
.unwrap();
37+
assert_eq!(graph.len(), 53478);
38+
39+
// reading non-existent url should return an error
40+
let result = read_url("http://example.org/non-existent.ttl");
41+
assert!(result.is_err());
42+
}
43+
44+
#[test]
45+
fn test_write_dataset_to_file() {
46+
// create in-memory dataset
47+
let mut graph = Dataset::new();
48+
let model = read_file(Path::new("fixtures/fileendings/model.ttl")).unwrap();
49+
let model_name =
50+
GraphNameRef::NamedNode(NamedNodeRef::new("http://example.org/model").unwrap());
51+
let brick = read_file(Path::new("fixtures/brick-stuff/Brick-1.3.ttl")).unwrap();
52+
let brick_name =
53+
GraphNameRef::NamedNode(NamedNodeRef::new("http://example.org/brick").unwrap());
54+
for quad in model.iter() {
55+
graph.insert(QuadRef::new(
56+
quad.subject,
57+
quad.predicate,
58+
quad.object,
59+
model_name,
60+
));
61+
}
62+
for quad in brick.iter() {
63+
graph.insert(QuadRef::new(
64+
quad.subject,
65+
quad.predicate,
66+
quad.object,
67+
brick_name,
68+
));
69+
}
70+
71+
write_dataset_to_file(&graph, "model_out.ttl").unwrap();
72+
}

0 commit comments

Comments
 (0)