Formatted files
This commit is contained in:
parent
6fd9e66ce8
commit
e18a62267f
@ -3,8 +3,17 @@ use localizer_rs;
|
||||
fn main() {
|
||||
let config: localizer_rs::Config = localizer_rs::Config::new("translations", "en");
|
||||
|
||||
println!("{:}", config.t("error", vec![("details", "Something went wrong when trying to do stuff")]));
|
||||
println!("{:}", config.t("success", vec![("balance", "$10"), ("user", "John Doe")]));
|
||||
println!(
|
||||
"{:}",
|
||||
config.t(
|
||||
"error",
|
||||
vec![("details", "Something went wrong when trying to do stuff")]
|
||||
)
|
||||
);
|
||||
println!(
|
||||
"{:}",
|
||||
config.t("success", vec![("balance", "$10"), ("user", "John Doe")])
|
||||
);
|
||||
|
||||
println!("{:}", config.t("all", vec![]));
|
||||
}
|
||||
|
||||
@ -96,7 +96,7 @@ impl Error {
|
||||
return Error {
|
||||
name: name.to_owned(),
|
||||
description: description.to_owned(),
|
||||
exit_code: exit_code
|
||||
exit_code: exit_code,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -37,25 +37,35 @@ use localizer_rs;
|
||||
mod tests {
|
||||
#[test]
|
||||
fn test_error() {
|
||||
let error: localizer_rs::errors::Error = localizer_rs::errors::Error::new("name", "description", 1);
|
||||
let error: localizer_rs::errors::Error =
|
||||
localizer_rs::errors::Error::new("name", "description", 1);
|
||||
|
||||
assert_eq!(error, localizer_rs::errors::Error {
|
||||
name: "name".to_owned(),
|
||||
description: "description".to_owned(),
|
||||
exit_code: 1
|
||||
});
|
||||
assert_eq!(
|
||||
error,
|
||||
localizer_rs::errors::Error {
|
||||
name: "name".to_owned(),
|
||||
description: "description".to_owned(),
|
||||
exit_code: 1
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn raise_helper() {
|
||||
let error: localizer_rs::errors::Error = localizer_rs::errors::Error::new("name", "description", 1);
|
||||
let error: localizer_rs::errors::Error =
|
||||
localizer_rs::errors::Error::new("name", "description", 1);
|
||||
error.raise("details");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_raise() {
|
||||
let status = std::process::Command::new("cargo").args(&["test", "--", "--ignored"]).stdout(std::process::Stdio::null()).stderr(std::process::Stdio::null()).status().expect("Unable to run program");
|
||||
let status = std::process::Command::new("cargo")
|
||||
.args(&["test", "--", "--ignored"])
|
||||
.stdout(std::process::Stdio::null())
|
||||
.stderr(std::process::Stdio::null())
|
||||
.status()
|
||||
.expect("Unable to run program");
|
||||
|
||||
assert_eq!(Some(1), status.code())
|
||||
}
|
||||
|
||||
45
tests/lib.rs
45
tests/lib.rs
@ -39,33 +39,43 @@ mod tests {
|
||||
fn test_config() {
|
||||
let config: localizer_rs::Config = localizer_rs::Config::new("examples/translations", "en");
|
||||
|
||||
assert_eq!(config, localizer_rs::Config {
|
||||
path: "examples/translations".to_owned(),
|
||||
language: "en".to_owned()
|
||||
});
|
||||
assert_eq!(
|
||||
config,
|
||||
localizer_rs::Config {
|
||||
path: "examples/translations".to_owned(),
|
||||
language: "en".to_owned()
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_set_path() {
|
||||
let mut config: localizer_rs::Config = localizer_rs::Config::new("examples/translations", "en");
|
||||
let mut config: localizer_rs::Config =
|
||||
localizer_rs::Config::new("examples/translations", "en");
|
||||
config.set_path("examples");
|
||||
|
||||
assert_eq!(config, localizer_rs::Config {
|
||||
path: "examples".to_owned(),
|
||||
language: "en".to_owned()
|
||||
});
|
||||
|
||||
assert_eq!(
|
||||
config,
|
||||
localizer_rs::Config {
|
||||
path: "examples".to_owned(),
|
||||
language: "en".to_owned()
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_set_language() {
|
||||
let mut config: localizer_rs::Config = localizer_rs::Config::new("examples/translations", "en");
|
||||
let mut config: localizer_rs::Config =
|
||||
localizer_rs::Config::new("examples/translations", "en");
|
||||
config.set_language("not_en");
|
||||
|
||||
assert_eq!(config, localizer_rs::Config {
|
||||
path: "examples/translations".to_owned(),
|
||||
language: "not_en".to_owned()
|
||||
});
|
||||
assert_eq!(
|
||||
config,
|
||||
localizer_rs::Config {
|
||||
path: "examples/translations".to_owned(),
|
||||
language: "not_en".to_owned()
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -73,6 +83,9 @@ mod tests {
|
||||
let config: localizer_rs::Config = localizer_rs::Config::new("examples/translations", "en");
|
||||
let translation: String = config.t("error", vec![("details", "Something went wrong")]);
|
||||
|
||||
assert_eq!(translation.as_str(), "\x1b[31m\x1b[1mError:\x1b[0m Something went wrong");
|
||||
assert_eq!(
|
||||
translation.as_str(),
|
||||
"\x1b[31m\x1b[1mError:\x1b[0m Something went wrong"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user