-
-
Notifications
You must be signed in to change notification settings - Fork 6k
test(uuid): add unit test fixtures for UUID v4 format and casing verification #9012
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| #[cfg(test)] | ||
| mod tests { | ||
| use uuid::Uuid; | ||
|
|
||
| #[test] | ||
| fn test_appflowy_uuid_v4_generation_format() { | ||
| let id = Uuid::new_v4(); | ||
| let id_str = id.to_string(); | ||
| assert_eq!(id_str.len(), 36); | ||
| assert_eq!(id_str.chars().filter(|&c| c == '-').count(), 4); | ||
|
Comment on lines
+7
to
+10
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpick (testing): The test only checks canonical UUID length and delimiter count; it passes for UUID v1, v3, v5, or any other 36-character hyphenated UUID and therefore never verifies the v4 version or required variant bits. Triggers: When UUID version/variant formatting regresses while the string retains the same length and delimiter layout. Suggested fix: Assert the UUID version is random/v4 and the variant is RFC 4122, in addition to checking the string shape. |
||
| } | ||
|
|
||
| #[test] | ||
| fn test_appflowy_uuid_nil_parsing() { | ||
| let nil_uuid = Uuid::nil(); | ||
| assert_eq!(nil_uuid.to_string(), "00000000-0000-0000-0000-000000000000"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_appflowy_uuid_case_insensitive_parse() { | ||
| let valid_str = "6ba7b810-9dad-11d1-80b4-00c04fd430c8"; | ||
| let parsed_lower = Uuid::parse_str(valid_str); | ||
| let parsed_upper = Uuid::parse_str(&valid_str.to_uppercase()); | ||
| assert!(parsed_lower.is_ok()); | ||
| assert!(parsed_upper.is_ok()); | ||
| assert_eq!(parsed_lower.unwrap(), parsed_upper.unwrap()); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (testing): This test file is not attached to any Cargo package:
frontend/core_serviceshas noCargo.tomland is not a member of thefrontend/rust-libworkspace, so Cargo does not compile or run these tests.Triggers: When the Rust workspace test suite is run through Cargo.
Suggested fix: Place the test under an existing package's
testsdirectory or addfrontend/core_servicesas a valid Cargo package and workspace member.