Skip to content

Commit

Permalink
chore: replace std::fs by include_str! to load test data (#198)
Browse files Browse the repository at this point in the history
  • Loading branch information
pythonbrad authored Mar 16, 2024
1 parent 7114448 commit 5e91b86
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
4 changes: 2 additions & 2 deletions engine/preprocessor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -625,9 +625,9 @@ mod tests {

#[test]
fn test_advanced() {
use std::{fs, rc::Rc};
use std::rc::Rc;

let data = fs::read_to_string("./data/sample.txt").unwrap();
let data = include_str!("../data/sample.txt");
let data = utils::load_data(&data);
let memory = utils::build_map(data);
let mut preprocessor = Preprocessor::new(Rc::new(memory), 64);
Expand Down
10 changes: 4 additions & 6 deletions memory/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,9 @@
//!
//! ```no_run
//! use afrim_memory::utils;
//! use std::fs;
//!
//! // Import data from a file.
//! let data = fs::read_to_string("./data/sample.txt")
//! .expect("Failed to load the data file");
//! // Import data from a string.
//! let data = "a1 à\ne2 é";
//! let data = utils::load_data(&data);
//! let text_buffer = utils::build_map(data);
//! ```
Expand Down Expand Up @@ -581,7 +579,7 @@ mod tests {
#[test]
fn test_cursor() {
use crate::{utils, Cursor};
use std::{fs, rc::Rc};
use std::rc::Rc;

macro_rules! hit {
( $cursor:ident $( $c:expr ),* ) => (
Expand All @@ -597,7 +595,7 @@ mod tests {
};
}

let data = fs::read_to_string("./data/sample.txt").unwrap();
let data = include_str!("../data/sample.txt");
let root = utils::build_map(utils::load_data(&data));

let mut cursor = Cursor::new(Rc::new(root), 8);
Expand Down
6 changes: 2 additions & 4 deletions memory/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,11 @@ pub fn build_map(data: Vec<Vec<&str>>) -> Node {

#[cfg(test)]
mod tests {
use std::fs;

#[test]
fn test_load_data() {
use crate::utils;

let data = fs::read_to_string("./data/sample.txt").unwrap();
let data = include_str!("../data/sample.txt");

utils::load_data(&data)
.iter()
Expand All @@ -93,7 +91,7 @@ mod tests {
let data = vec![vec!["af11", "ɑ̀ɑ̀"], vec!["?.", "ʔ"]];
utils::build_map(data);

let data = fs::read_to_string("./data/sample.txt").unwrap();
let data = include_str!("../data/sample.txt");
let data = utils::load_data(&data);

utils::build_map(data);
Expand Down

0 comments on commit 5e91b86

Please sign in to comment.