Download codex-rs/protocol/src/response_item_id_tests.rs from SaylorTwift/codex: direct link, hf CLI and curl.
- Browser
- Download file 1.45 kB
-
https://huggingface.co/SaylorTwift/codex/resolve/main/codex-rs/protocol/src/response_item_id_tests.rs
- Command line
-
hf download hf://SaylorTwift/codex/codex-rs/protocol/src/response_item_id_tests.rs
-
curl -L -o response_item_id_tests.rs https://huggingface.co/SaylorTwift/codex/resolve/main/codex-rs/protocol/src/response_item_id_tests.rs
1.45 kB
| use pretty_assertions::assert_eq; | |
| use uuid::Uuid; | |
| use super::ResponseItemId; | |
| fn creates_prefixed_uuid_v7_ids() { | |
| let id = ResponseItemId::new("msg"); | |
| let uuid = id.strip_prefix("msg_").expect("message prefix"); | |
| assert_eq!( | |
| Uuid::parse_str(uuid).expect("UUID suffix").get_version(), | |
| Some(uuid::Version::SortRand) | |
| ); | |
| } | |
| fn creates_prefixed_ids_with_explicit_suffix() { | |
| let id = ResponseItemId::with_suffix("msg", "test"); | |
| assert_eq!(id.as_str(), "msg_test"); | |
| assert_eq!(id.to_string(), "msg_test"); | |
| assert_eq!(String::from(id), "msg_test"); | |
| } | |
| fn accepts_server_ids_verbatim() { | |
| let id = ResponseItemId::from_server("legacy-id".to_string()); | |
| assert_eq!(id.as_str(), "legacy-id"); | |
| } | |
| fn deserializes_arbitrary_ids_as_strings() { | |
| let id: ResponseItemId = serde_json::from_str("\"legacy-id\"").expect("id"); | |
| assert_eq!(id.as_str(), "legacy-id"); | |
| assert_eq!( | |
| serde_json::to_string(&id).expect("serialized id"), | |
| "\"legacy-id\"" | |
| ); | |
| } | |
| fn recognizes_non_empty_prefix_and_suffix() { | |
| for (value, expected) in [ | |
| ("msg_test", true), | |
| ("legacy-id", false), | |
| ("", false), | |
| ("_test", false), | |
| ("msg_", false), | |
| ] { | |
| let id: ResponseItemId = | |
| serde_json::from_value(value.into()).expect("ID should deserialize"); | |
| assert_eq!(id.is_prefixed(), expected, "{value}"); | |
| } | |
| } | |