summaryrefslogtreecommitdiff
path: root/tests/dev_cargo_bins.rs
diff options
context:
space:
mode:
authormo8it <mo8it@proton.me>2024-04-01 02:11:52 +0200
committermo8it <mo8it@proton.me>2024-04-01 02:11:52 +0200
commit14f3585816ae12091956efcc45c1e4aefc2f91ce (patch)
tree78820c4df79df450a80b572031e6dc561a9d242b /tests/dev_cargo_bins.rs
parent8ad18de54cdad2e94d40d7d4cb67e4a6a274c293 (diff)
Make `cargo run` work
Diffstat (limited to 'tests/dev_cargo_bins.rs')
-rw-r--r--tests/dev_cargo_bins.rs39
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/dev_cargo_bins.rs b/tests/dev_cargo_bins.rs
new file mode 100644
index 0000000..7f1771b
--- /dev/null
+++ b/tests/dev_cargo_bins.rs
@@ -0,0 +1,39 @@
+// Makes sure that `dev/Cargo.toml` is synced with `info.toml`.
+// When this test fails, you just need to run `cargo run --bin gen-dev-cargo-toml`.
+
+use serde::Deserialize;
+use std::fs;
+
+#[derive(Deserialize)]
+struct Exercise {
+ name: String,
+ path: String,
+}
+
+#[derive(Deserialize)]
+struct InfoToml {
+ exercises: Vec<Exercise>,
+}
+
+#[test]
+fn dev_cargo_bins() {
+ let content = fs::read_to_string("exercises/Cargo.toml").unwrap();
+
+ let exercises = toml_edit::de::from_str::<InfoToml>(&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]);
+
+ // +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]);
+
+ start_ind = path_end + 1;
+ }
+}