Skip to content

Commit

Permalink
test: add test for serde serialize feature
Browse files Browse the repository at this point in the history
  • Loading branch information
vemonet committed Dec 22, 2023
1 parent fd1e530 commit 308a2ab
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
13 changes: 13 additions & 0 deletions tests/trie_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8, i32> =
serde_json::from_str(&serialized).expect("Failed to deserialize");
assert_eq!(deserialized.get("key".bytes()), Some(42).as_ref());
}
}

0 comments on commit 308a2ab

Please sign in to comment.