Skip to content

Commit

Permalink
text tests
Browse files Browse the repository at this point in the history
  • Loading branch information
subalterngames committed Jan 19, 2024
1 parent 84e504c commit 2efd075
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 25 deletions.
5 changes: 5 additions & 0 deletions common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,8 @@ pub fn get_bytes(path: &Path) -> Vec<u8> {
pub fn get_default_data_folder() -> PathBuf {
current_dir().unwrap().join("data")
}

#[cfg(debug_assertions)]
pub fn get_test_config() -> ini::Ini {
ini::Ini::load_from_file("../data/config.ini").unwrap()
}
39 changes: 25 additions & 14 deletions common/src/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,19 @@ impl Paths {
/// Setup the paths, needs to be be called at least once.
pub fn init(data_directory_from_cli: &Path) {
let data_directory = get_data_directory(data_directory_from_cli);
PATHS
.set(Self::new(&data_directory))
.unwrap();
}

/// Returns a new `Paths` that can be used for testing.
#[cfg(debug_assertions)]
pub fn get_test_paths() -> Self {
Self::new(&PathBuf::from("../data"))
}

/// Returns a new `Paths` object.
fn new(data_directory: &Path) -> Self {
let user_directory = match UserDirs::new() {
Some(user_dirs) => match user_dirs.document_dir() {
Some(documents) => documents.join("cacophony"),
Expand All @@ -60,20 +73,18 @@ impl Paths {
let export_directory = get_directory("exports", &user_directory);
let splash_path = data_directory.join("splash.png");
let default_soundfont_path = data_directory.join("CT1MBGMRSV1.06.sf2");
PATHS
.set(Self {
default_ini_path,
user_directory,
user_ini_path,
text_path,
soundfonts_directory,
saves_directory,
export_directory,
splash_path,
default_soundfont_path,
data_directory,
})
.unwrap();
Self {
default_ini_path,
user_directory,
user_ini_path,
text_path,
soundfonts_directory,
saves_directory,
export_directory,
splash_path,
default_soundfont_path,
data_directory: data_directory.to_path_buf(),
}
}

/// Get a reference to the paths, panics when not initialized.
Expand Down
7 changes: 2 additions & 5 deletions common/src/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,7 @@ impl View {

#[cfg(test)]
mod tests {
use crate::time::PPQ_U;
use crate::view::View;
use crate::EditMode;
use ini::Ini;
use crate::{get_test_config, EditMode, View, PPQ_U};

const VIEW_T1: u64 = PPQ_U * 133;

Expand Down Expand Up @@ -250,6 +247,6 @@ mod tests {
}

fn get_new_view() -> View {
View::new(&Ini::load_from_file("../data/config.ini").unwrap())
View::new(&get_test_config())
}
}
5 changes: 2 additions & 3 deletions io/src/piano_roll/edit_mode_deltas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,11 @@ impl EditModeDeltas {
#[cfg(test)]
mod tests {
use super::EditModeDeltas;
use common::PPQ_U;
use ini::Ini;
use common::{get_test_config, PPQ_U};

#[test]
fn edit_mode_deltas() {
let e = EditModeDeltas::new(&Ini::load_from_file("../data/config.ini").unwrap());
let e = EditModeDeltas::new(&get_test_config());
assert_eq!(e.quick_time_factor, 4, "{}", e.quick_time_factor);
assert_eq!(e.precise_time, PPQ_U / 32, "{}", e.precise_time);
assert_eq!(e.normal_note, 1, "{}", e.normal_note);
Expand Down
4 changes: 1 addition & 3 deletions text/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,10 @@ const KEYCODE_LOOKUPS: [&str; 121] = [
"Unknown",
];

type TextMap = HashMap<String, String>;

/// Localized text lookup.
pub struct Text {
/// The text key-value map.
text: TextMap,
text: HashMap<String, String>,
/// A map of key codes to spoken text.
keycodes_spoken: HashMap<KeyCode, String>,
/// A map of key codes to seen text.
Expand Down

0 comments on commit 2efd075

Please sign in to comment.