Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions frontend/core_services/tests/uuid_v4_validation_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#[cfg(test)]

Copy link
Copy Markdown
Contributor

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_services has no Cargo.toml and is not a member of the frontend/rust-lib workspace, 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 tests directory or add frontend/core_services as a valid Cargo package and workspace member.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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());
}
}
Loading