Skip to content

Commit

Permalink
test: add test deserializing Wasm CM name style LibraryPath
Browse files Browse the repository at this point in the history
  • Loading branch information
greenhat committed Dec 20, 2024
1 parent f845006 commit 9e240e0
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion assembly/src/library/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,16 @@ fn validate_component(component: &str) -> Result<(), PathError> {
/// Tests
#[cfg(test)]
mod tests {
use vm_core::assert_matches;
use crate::alloc::string::ToString;
use std::sync::Arc;

use vm_core::{
assert_matches,
debuginfo::{SourceSpan, Span},
utils::{Deserializable, Serializable},
};

use crate::{ast::Ident, LibraryNamespace};

use super::{super::LibraryNamespaceError, IdentError, LibraryPath, PathError};

Expand Down Expand Up @@ -608,4 +617,18 @@ mod tests {
Err(PathError::InvalidNamespace(LibraryNamespaceError::InvalidStart))
);
}

#[test]
fn path_serialization_wasm_cm_style_module_name() {
// Tests that Wasm Component Model names are serialized and deserialized correctly
let wasm_cm_style_module_name = "namespace:package/[email protected]";
let module_id = Ident::new_unchecked(Span::new(
SourceSpan::default(),
Arc::from(wasm_cm_style_module_name.to_string()),
));
let path = LibraryPath::new_from_components(LibraryNamespace::Anon, [module_id]);
let bytes = path.to_bytes();
let deserialized = LibraryPath::read_from_bytes(&bytes).unwrap();
assert_eq!(path, deserialized);
}
}

0 comments on commit 9e240e0

Please sign in to comment.