diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-03-21 16:37:51 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-03-21 16:37:51 +0800 |
| commit | c811c5818d21a67280ef9dd35ad40f6f5411daa5 (patch) | |
| tree | 46062311242da24771466ad99be26b530e83d497 /legacy_utils/cfg_file/cfg_file_test | |
| parent | 9a60751a901f568bdeb154c4115235d4f3a0f8b9 (diff) | |
Good Bye! Legacy JVCS
Diffstat (limited to 'legacy_utils/cfg_file/cfg_file_test')
| -rw-r--r-- | legacy_utils/cfg_file/cfg_file_test/Cargo.toml | 9 | ||||
| -rw-r--r-- | legacy_utils/cfg_file/cfg_file_test/src/lib.rs | 95 |
2 files changed, 0 insertions, 104 deletions
diff --git a/legacy_utils/cfg_file/cfg_file_test/Cargo.toml b/legacy_utils/cfg_file/cfg_file_test/Cargo.toml deleted file mode 100644 index 5db1010..0000000 --- a/legacy_utils/cfg_file/cfg_file_test/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "cfg_file_test" -version = "0.1.0" -edition = "2024" - -[dependencies] -cfg_file = { path = "../../cfg_file", features = ["default"] } -tokio = { version = "1.48.0", features = ["full"] } -serde = { version = "1.0.228", features = ["derive"] } diff --git a/legacy_utils/cfg_file/cfg_file_test/src/lib.rs b/legacy_utils/cfg_file/cfg_file_test/src/lib.rs deleted file mode 100644 index f70d00d..0000000 --- a/legacy_utils/cfg_file/cfg_file_test/src/lib.rs +++ /dev/null @@ -1,95 +0,0 @@ -#[cfg(test)] -mod test_cfg_file { - use cfg_file::ConfigFile; - use cfg_file::config::ConfigFile; - use serde::{Deserialize, Serialize}; - use std::collections::HashMap; - - #[derive(ConfigFile, Deserialize, Serialize, Default)] - #[cfg_file(path = "./.temp/example_cfg.toml")] - struct ExampleConfig { - name: String, - age: i32, - hobby: Vec<String>, - secret: HashMap<String, String>, - } - - #[derive(ConfigFile, Deserialize, Serialize, Default)] - #[cfg_file(path = "./.temp/example_bincode.bcfg")] - struct ExampleBincodeConfig { - name: String, - age: i32, - hobby: Vec<String>, - secret: HashMap<String, String>, - } - - #[tokio::test] - async fn test_config_file_serialization() { - let mut example = ExampleConfig { - name: "Weicao".to_string(), - age: 22, - hobby: ["Programming", "Painting"] - .iter() - .map(|m| m.to_string()) - .collect(), - secret: HashMap::new(), - }; - let secret_no_comments = - "Actually, I'm really too lazy to write comments, documentation, and unit tests."; - example - .secret - .entry("No comments".to_string()) - .insert_entry(secret_no_comments.to_string()); - - let secret_peek = "Of course, it's peeking at you who's reading the source code."; - example - .secret - .entry("Peek".to_string()) - .insert_entry(secret_peek.to_string()); - - ExampleConfig::write(&example).await.unwrap(); // Write to default path. - - // Read from default path. - let read_cfg = ExampleConfig::read().await.unwrap(); - assert_eq!(read_cfg.name, "Weicao"); - assert_eq!(read_cfg.age, 22); - assert_eq!(read_cfg.hobby, vec!["Programming", "Painting"]); - assert_eq!(read_cfg.secret["No comments"], secret_no_comments); - assert_eq!(read_cfg.secret["Peek"], secret_peek); - } - - #[tokio::test] - async fn test_bincode_config_file_serialization() { - let mut example = ExampleBincodeConfig { - name: "Weicao".to_string(), - age: 22, - hobby: ["Programming", "Painting"] - .iter() - .map(|m| m.to_string()) - .collect(), - secret: HashMap::new(), - }; - let secret_no_comments = - "Actually, I'm really too lazy to write comments, documentation, and unit tests."; - example - .secret - .entry("No comments".to_string()) - .insert_entry(secret_no_comments.to_string()); - - let secret_peek = "Of course, it's peeking at you who's reading the source code."; - example - .secret - .entry("Peek".to_string()) - .insert_entry(secret_peek.to_string()); - - ExampleBincodeConfig::write(&example).await.unwrap(); // Write to default path. - - // Read from default path. - let read_cfg = ExampleBincodeConfig::read().await.unwrap(); - assert_eq!(read_cfg.name, "Weicao"); - assert_eq!(read_cfg.age, 22); - assert_eq!(read_cfg.hobby, vec!["Programming", "Painting"]); - assert_eq!(read_cfg.secret["No comments"], secret_no_comments); - assert_eq!(read_cfg.secret["Peek"], secret_peek); - } -} |
