diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f985be5..7c58808 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -46,7 +46,7 @@ jobs: steps: - uses: actions/checkout@v4 - name: Generate code coverage - run: cargo tarpaulin -p ptrie --doc --tests --out xml + run: cargo tarpaulin -p ptrie --doc --tests --out xml --all-features - name: Upload to codecov.io uses: codecov/codecov-action@v3 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 80f36c7..2076d46 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -27,13 +27,13 @@ pre-commit install Run tests: ```bash -cargo test +cargo test --all-features ``` Tests with coverage: ```bash -cargo tarpaulin -p ptrie --doc --tests --out html +cargo tarpaulin -p ptrie --doc --tests --all-features --out html ``` > Start web server for the cov report: `python -m http.server` diff --git a/Cargo.toml b/Cargo.toml index 13e42e9..40af940 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,6 +20,9 @@ edition = "2021" [dependencies] serde = { version = "1.0", optional = true, features = ["derive"] } +[dev-dependencies] +serde_json = "1.0" + [features] serde = ["dep:serde"] diff --git a/README.md b/README.md index fd21376..f904e49 100644 --- a/README.md +++ b/README.md @@ -100,11 +100,9 @@ for (k, v) in trie.iter() { The `serde` feature adds Serde `Serialize` and `Deserialize` traits to the `Trie` and `TrieNode` struct. ```toml -ptrie = { version = "0.5", features = ["serde"] } +ptrie = { version = "0.6", features = ["serde"] } ``` -> ⚠️ Feature not yet tested - ## 🛠️ Contributing Contributions are welcome, checkout the [`CONTRIBUTING.md`](https://github.com/vemonet/ptrie/blob/main/CONTRIBUTING.md) for instructions to run the project in development. diff --git a/tests/trie_tests.rs b/tests/trie_tests.rs index 0c4f58e..5056869 100644 --- a/tests/trie_tests.rs +++ b/tests/trie_tests.rs @@ -70,4 +70,17 @@ mod tests { assert!(v.starts_with("tes")); } } + + #[cfg(feature = "serde")] + #[test] + fn serde_serialize() { + use serde_json; + let mut trie = Trie::new(); + trie.insert("key".bytes(), 42); + let serialized = serde_json::to_string(&trie).expect("Failed to serialize"); + // println!("serialized! {}", serialized); + let deserialized: Trie = + serde_json::from_str(&serialized).expect("Failed to deserialize"); + assert_eq!(deserialized.get("key".bytes()), Some(42).as_ref()); + } }