mirror of
https://github.com/notohh/rustlings.git
synced 2024-11-21 21:42:23 -05:00
Fix tests
This commit is contained in:
parent
bee62c89de
commit
9831cbb139
5 changed files with 39 additions and 37 deletions
|
@ -10,18 +10,18 @@ use std::{
|
|||
};
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct Exercise {
|
||||
struct ExerciseInfo {
|
||||
name: String,
|
||||
path: String,
|
||||
dir: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct InfoToml {
|
||||
exercises: Vec<Exercise>,
|
||||
struct InfoFile {
|
||||
exercises: Vec<ExerciseInfo>,
|
||||
}
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let exercises = toml_edit::de::from_str::<InfoToml>(
|
||||
let exercise_infos = toml_edit::de::from_str::<InfoFile>(
|
||||
&fs::read_to_string("info.toml").context("Failed to read `info.toml`")?,
|
||||
)
|
||||
.context("Failed to deserialize `info.toml`")?
|
||||
|
@ -36,12 +36,16 @@ fn main() -> Result<()> {
|
|||
bin = [\n",
|
||||
);
|
||||
|
||||
for exercise in exercises {
|
||||
for exercise_info in exercise_infos {
|
||||
buf.extend_from_slice(b" { name = \"");
|
||||
buf.extend_from_slice(exercise.name.as_bytes());
|
||||
buf.extend_from_slice(b"\", path = \"../");
|
||||
buf.extend_from_slice(exercise.path.as_bytes());
|
||||
buf.extend_from_slice(b"\" },\n");
|
||||
buf.extend_from_slice(exercise_info.name.as_bytes());
|
||||
buf.extend_from_slice(b"\", path = \"../exercises/");
|
||||
if let Some(dir) = &exercise_info.dir {
|
||||
buf.extend_from_slice(dir.as_bytes());
|
||||
buf.extend_from_slice(b"/");
|
||||
}
|
||||
buf.extend_from_slice(exercise_info.name.as_bytes());
|
||||
buf.extend_from_slice(b".rs\" },\n");
|
||||
}
|
||||
|
||||
buf.extend_from_slice(
|
||||
|
|
|
@ -5,34 +5,39 @@ use serde::Deserialize;
|
|||
use std::fs;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct Exercise {
|
||||
struct ExerciseInfo {
|
||||
name: String,
|
||||
path: String,
|
||||
dir: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct InfoToml {
|
||||
exercises: Vec<Exercise>,
|
||||
struct InfoFile {
|
||||
exercises: Vec<ExerciseInfo>,
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dev_cargo_bins() {
|
||||
let content = fs::read_to_string("dev/Cargo.toml").unwrap();
|
||||
let cargo_toml = fs::read_to_string("dev/Cargo.toml").unwrap();
|
||||
|
||||
let exercises = toml_edit::de::from_str::<InfoToml>(&fs::read_to_string("info.toml").unwrap())
|
||||
let exercise_infos =
|
||||
toml_edit::de::from_str::<InfoFile>(&fs::read_to_string("info.toml").unwrap())
|
||||
.unwrap()
|
||||
.exercises;
|
||||
|
||||
let mut start_ind = 0;
|
||||
for exercise in exercises {
|
||||
let name_start = start_ind + content[start_ind..].find('"').unwrap() + 1;
|
||||
let name_end = name_start + content[name_start..].find('"').unwrap();
|
||||
assert_eq!(exercise.name, &content[name_start..name_end]);
|
||||
for exercise_info in exercise_infos {
|
||||
let name_start = start_ind + cargo_toml[start_ind..].find('"').unwrap() + 1;
|
||||
let name_end = name_start + cargo_toml[name_start..].find('"').unwrap();
|
||||
assert_eq!(exercise_info.name, &cargo_toml[name_start..name_end]);
|
||||
|
||||
// +3 to skip `../` at the begeinning of the path.
|
||||
let path_start = name_end + content[name_end + 1..].find('"').unwrap() + 5;
|
||||
let path_end = path_start + content[path_start..].find('"').unwrap();
|
||||
assert_eq!(exercise.path, &content[path_start..path_end]);
|
||||
let path_start = name_end + cargo_toml[name_end + 1..].find('"').unwrap() + 2;
|
||||
let path_end = path_start + cargo_toml[path_start..].find('"').unwrap();
|
||||
let expected_path = if let Some(dir) = exercise_info.dir {
|
||||
format!("../exercises/{dir}/{}.rs", exercise_info.name)
|
||||
} else {
|
||||
format!("../exercises/{}.rs", exercise_info.name)
|
||||
};
|
||||
assert_eq!(expected_path, &cargo_toml[path_start..path_end]);
|
||||
|
||||
start_ind = path_end + 1;
|
||||
}
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
[[exercises]]
|
||||
name = "compFailure"
|
||||
path = "exercises/compFailure.rs"
|
||||
mode = "compile"
|
||||
mode = "run"
|
||||
hint = ""
|
||||
|
||||
[[exercises]]
|
||||
name = "testFailure"
|
||||
path = "exercises/testFailure.rs"
|
||||
mode = "test"
|
||||
hint = "Hello!"
|
||||
|
|
|
@ -1,17 +1,14 @@
|
|||
[[exercises]]
|
||||
name = "pending_exercise"
|
||||
path = "exercises/pending_exercise.rs"
|
||||
mode = "compile"
|
||||
mode = "run"
|
||||
hint = """"""
|
||||
|
||||
[[exercises]]
|
||||
name = "pending_test_exercise"
|
||||
path = "exercises/pending_test_exercise.rs"
|
||||
mode = "test"
|
||||
hint = """"""
|
||||
|
||||
[[exercises]]
|
||||
name = "finished_exercise"
|
||||
path = "exercises/finished_exercise.rs"
|
||||
mode = "compile"
|
||||
mode = "run"
|
||||
hint = """"""
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
[[exercises]]
|
||||
name = "compSuccess"
|
||||
path = "exercises/compSuccess.rs"
|
||||
mode = "compile"
|
||||
mode = "run"
|
||||
hint = """"""
|
||||
|
||||
[[exercises]]
|
||||
name = "testSuccess"
|
||||
path = "exercises/testSuccess.rs"
|
||||
mode = "test"
|
||||
hint = """"""
|
||||
|
|
Loading…
Reference in a new issue