diff options
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | src/api_interface_definition.rs | 132 | ||||
-rw-r--r-- | src/command.rs | 377 |
3 files changed, 315 insertions, 196 deletions
@@ -30,7 +30,7 @@ thiserror = "1.0.38" [dev-dependencies] pretty_assertions = "1.3.0" criterion = "0.4.0" -ridicule = { git = "https://git.hampusmat.com/ridicule" } +ridicule = "0.3.0" [[bench]] name = "registry" diff --git a/src/api_interface_definition.rs b/src/api_interface_definition.rs index 441d3f7..784b7d0 100644 --- a/src/api_interface_definition.rs +++ b/src/api_interface_definition.rs @@ -614,12 +614,15 @@ mod tests { let mut mock_deserializer = MockDeserializer::new(); - mock_deserializer.expect_de_list().times(1).returning(|_| { - Ok(vec![ - Feature::new(FeatureKind::Command, "glNewList", None), - Feature::new(FeatureKind::Command, "glEndList", None), - ]) - }); + // SAFETY: No argument lifetime is mistreated + unsafe { + mock_deserializer.expect_de_list().times(1).returning(|_| { + Ok(vec![ + Feature::new(FeatureKind::Command, "glNewList", None), + Feature::new(FeatureKind::Command, "glEndList", None), + ]) + }); + } let removal = Removal::deserialize( &BytesStart::new("remove").with_attributes([ @@ -648,27 +651,36 @@ mod tests { let mut mock_deserializer = MockDeserializer::new(); - mock_deserializer.expect_de_list().times(1).returning(|_| { - Ok(vec![ - Feature::new(FeatureKind::Command, "glNewList", None), - Feature::new(FeatureKind::Command, "glEndList", None), - ]) - }); - - mock_deserializer.expect_de_list().times(1).returning(|_| { - Ok(vec![ - Feature::new(FeatureKind::Enum, "GL_COLOR_TABLE", None), - Feature::new(FeatureKind::Enum, "GL_MINMAX", None), - Feature::new(FeatureKind::Enum, "GL_HISTOGRAM", None), - ]) - }); - - mock_deserializer.expect_de_list().times(1).returning(|_| { - Ok(vec![ - Feature::new(FeatureKind::Enum, "GL_STACK_UNDERFLOW", None), - Feature::new(FeatureKind::Enum, "GL_STACK_OVERFLOW", None), - ]) - }); + // SAFETY: No argument lifetime is mistreated + unsafe { + mock_deserializer.expect_de_list().times(1).returning(|_| { + Ok(vec![ + Feature::new(FeatureKind::Command, "glNewList", None), + Feature::new(FeatureKind::Command, "glEndList", None), + ]) + }); + } + + // SAFETY: No argument lifetime is mistreated + unsafe { + mock_deserializer.expect_de_list().times(1).returning(|_| { + Ok(vec![ + Feature::new(FeatureKind::Enum, "GL_COLOR_TABLE", None), + Feature::new(FeatureKind::Enum, "GL_MINMAX", None), + Feature::new(FeatureKind::Enum, "GL_HISTOGRAM", None), + ]) + }); + } + + // SAFETY: No argument lifetime is mistreated + unsafe { + mock_deserializer.expect_de_list().times(1).returning(|_| { + Ok(vec![ + Feature::new(FeatureKind::Enum, "GL_STACK_UNDERFLOW", None), + Feature::new(FeatureKind::Enum, "GL_STACK_OVERFLOW", None), + ]) + }); + } let requirement = Requirement::deserialize(&BytesStart::new("require"), &mut mock_deserializer) @@ -722,37 +734,43 @@ mod tests { let mut mock_deserializer = MockDeserializer::new(); - mock_deserializer - .expect_de_tag_list() - .times(1) - .returning(|_, _| { - Ok(vec![ - Requirement::new( - None, - None, - vec![ - Feature::new(FeatureKind::Command, "glFenceSync", None), - Feature::new(FeatureKind::Enum, "GL_WAIT_FAILED", None), - ], - ), - Requirement::new( - None, - Some("Reuse ARB_sync".to_string()), - [Feature::new(FeatureKind::Enum, "GL_OBJECT_TYPE", None)], - ), - ]) - }); + // SAFETY: No argument lifetime is mistreated + unsafe { + mock_deserializer + .expect_de_tag_list() + .times(1) + .returning(|_, _| { + Ok(vec![ + Requirement::new( + None, + None, + vec![ + Feature::new(FeatureKind::Command, "glFenceSync", None), + Feature::new(FeatureKind::Enum, "GL_WAIT_FAILED", None), + ], + ), + Requirement::new( + None, + Some("Reuse ARB_sync".to_string()), + [Feature::new(FeatureKind::Enum, "GL_OBJECT_TYPE", None)], + ), + ]) + }); + } - mock_deserializer - .expect_de_tag_list() - .times(1) - .returning(|_, _| { - Ok(vec![Removal::new( - "core", - "Compatibility-only GL 1.0 features removed from GL 3.2", - vec![Feature::new(FeatureKind::Command, "glBegin", None)], - )]) - }); + // SAFETY: No argument lifetime is mistreated + unsafe { + mock_deserializer + .expect_de_tag_list() + .times(1) + .returning(|_, _| { + Ok(vec![Removal::new( + "core", + "Compatibility-only GL 1.0 features removed from GL 3.2", + vec![Feature::new(FeatureKind::Command, "glBegin", None)], + )]) + }); + } let api_interface_definition = APIInterfaceDefinition::deserialize( &BytesStart::new("feature").with_attributes([ diff --git a/src/command.rs b/src/command.rs index fd449aa..deab0eb 100644 --- a/src/command.rs +++ b/src/command.rs @@ -320,22 +320,30 @@ mod tests { let mut mock_deserializer = MockDeserializer::new(); - mock_deserializer - .expect_de_text() - .returning(|_| { - Err(DeserializerError::UnexpectedEvent { - expected_event_name: "text".to_string(), - found_event: Event::Start(BytesStart::new("ptype")), + // SAFETY: No argument lifetime is mistreated + unsafe { + mock_deserializer + .expect_de_text() + .returning(|_| { + Err(DeserializerError::UnexpectedEvent { + expected_event_name: "text".to_string(), + found_event: Event::Start(BytesStart::new("ptype")), + }) }) - }) - .times(1); + .times(1); + } - mock_deserializer - .expect_de_text() - .returning(|_| Ok("GLuint".to_string())) - .times(1); + // SAFETY: No argument lifetime is mistreated + unsafe { + mock_deserializer + .expect_de_text() + .returning(|_| Ok("GLuint".to_string())) + .times(1); + } - mock_deserializer + // SAFETY: No argument lifetime is mistreated + unsafe { + mock_deserializer .expect_de_tag_with::<String, DeserializerError, DeserializeWithFn<_, _, _>>() .with( eq("ptype"), @@ -346,33 +354,43 @@ mod tests func(&BytesStart::new(tag_name), deserializer) }) .times(1); + } - mock_deserializer - .expect_de_text() - .returning(|_| { - Err(DeserializerError::UnexpectedEvent { - expected_event_name: "text".to_string(), - found_event: Event::Start(BytesStart::new("name")), + // SAFETY: No argument lifetime is mistreated + unsafe { + mock_deserializer + .expect_de_text() + .returning(|_| { + Err(DeserializerError::UnexpectedEvent { + expected_event_name: "text".to_string(), + found_event: Event::Start(BytesStart::new("name")), + }) }) - }) - .times(1); + .times(1); + } - mock_deserializer - .expect_de_text() - .returning(|_| Ok("glDoComplicatedThing".to_string())) - .times(1); + // SAFETY: No argument lifetime is mistreated + unsafe { + mock_deserializer + .expect_de_text() + .returning(|_| Ok("glDoComplicatedThing".to_string())) + .times(1); + } - mock_deserializer - .expect_de_tag_with::<String, DeserializerError, DeserializeWithFn<_, _, _>>() - .with( - eq("name"), - function(|ignore_end| matches!(ignore_end, IgnoreEnd::No)), - always(), - ) - .returning(|deserializer, tag_name, _, func| { - func(&BytesStart::new(tag_name), deserializer) - }) - .times(1); + // SAFETY: No argument lifetime is mistreated + unsafe { + mock_deserializer + .expect_de_tag_with::<String, DeserializerError, DeserializeWithFn<_, _, _>>() + .with( + eq("name"), + function(|ignore_end| matches!(ignore_end, IgnoreEnd::No)), + always(), + ) + .returning(|deserializer, tag_name, _, func| { + func(&BytesStart::new(tag_name), deserializer) + }) + .times(1); + } let prototype = Prototype::deserialize(&BytesStart::new("proto"), &mut mock_deserializer) @@ -387,12 +405,17 @@ mod tests { let mut mock_deserializer = MockDeserializer::new(); - mock_deserializer - .expect_de_text() - .returning(|_| Ok("void".to_string())) - .times(1); + // SAFETY: No argument lifetime is mistreated + unsafe { + mock_deserializer + .expect_de_text() + .returning(|_| Ok("void".to_string())) + .times(1); + } - mock_deserializer + // SAFETY: No argument lifetime is mistreated + unsafe { + mock_deserializer .expect_de_tag_with::<String, DeserializerError, DeserializeWithFn<_, _, _>>() .with( eq("ptype"), @@ -406,23 +429,32 @@ mod tests }) }) .times(1); + } - mock_deserializer - .expect_de_text() - .returning(|_| { - Err(DeserializerError::UnexpectedEvent { - expected_event_name: "text".to_string(), - found_event: Event::Start(BytesStart::new("name")), + // SAFETY: No argument lifetime is mistreated + unsafe { + mock_deserializer + .expect_de_text() + .returning(|_| { + Err(DeserializerError::UnexpectedEvent { + expected_event_name: "text".to_string(), + found_event: Event::Start(BytesStart::new("name")), + }) }) - }) - .times(1); + .times(1); + } - mock_deserializer - .expect_de_text() - .returning(|_| Ok("glDoSomeThing".to_string())) - .times(1); + // SAFETY: No argument lifetime is mistreated + unsafe { + mock_deserializer + .expect_de_text() + .returning(|_| Ok("glDoSomeThing".to_string())) + .times(1); + } - mock_deserializer + // SAFETY: No argument lifetime is mistreated + unsafe { + mock_deserializer .expect_de_tag_with::<String, DeserializerError, DeserializeWithFn<_, _, _>>() .with( eq("name"), @@ -433,6 +465,7 @@ mod tests func(&BytesStart::new(tag_name), deserializer) }) .times(1); + } let prototype = Prototype::deserialize(&BytesStart::new("proto"), &mut mock_deserializer) @@ -447,22 +480,30 @@ mod tests { let mut mock_deserializer = MockDeserializer::new(); - mock_deserializer - .expect_de_text() - .returning(|_| { - Err(DeserializerError::UnexpectedEvent { - expected_event_name: "text".to_string(), - found_event: Event::Start(BytesStart::new("ptype")), + // SAFETY: No argument lifetime is mistreated + unsafe { + mock_deserializer + .expect_de_text() + .returning(|_| { + Err(DeserializerError::UnexpectedEvent { + expected_event_name: "text".to_string(), + found_event: Event::Start(BytesStart::new("ptype")), + }) }) - }) - .times(1); + .times(1); + } - mock_deserializer - .expect_de_text() - .returning(|_| Ok("GLenum".to_string())) - .times(1); + // SAFETY: No argument lifetime is mistreated + unsafe { + mock_deserializer + .expect_de_text() + .returning(|_| Ok("GLenum".to_string())) + .times(1); + } - mock_deserializer + // SAFETY: No argument lifetime is mistreated + unsafe { + mock_deserializer .expect_de_tag_with::<String, DeserializerError, DeserializeWithFn<_, _, _>>() .with( eq("ptype"), @@ -473,23 +514,32 @@ mod tests func(&BytesStart::new(tag_name), deserializer) }) .times(1); + } - mock_deserializer - .expect_de_text() - .returning(|_| { - Err(DeserializerError::UnexpectedEvent { - expected_event_name: "text".to_string(), - found_event: Event::Start(BytesStart::new("name")), + // SAFETY: No argument lifetime is mistreated + unsafe { + mock_deserializer + .expect_de_text() + .returning(|_| { + Err(DeserializerError::UnexpectedEvent { + expected_event_name: "text".to_string(), + found_event: Event::Start(BytesStart::new("name")), + }) }) - }) - .times(1); + .times(1); + } - mock_deserializer - .expect_de_text() - .returning(|_| Ok("value".to_string())) - .times(1); + // SAFETY: No argument lifetime is mistreated + unsafe { + mock_deserializer + .expect_de_text() + .returning(|_| Ok("value".to_string())) + .times(1); + } - mock_deserializer + // SAFETY: No argument lifetime is mistreated + unsafe { + mock_deserializer .expect_de_tag_with::<String, DeserializerError, DeserializeWithFn<_, _, _>>() .with( eq("name"), @@ -500,6 +550,7 @@ mod tests func(&BytesStart::new(tag_name), deserializer) }) .times(1); + } let parameter = Parameter::deserialize(&BytesStart::new("param"), &mut mock_deserializer) @@ -514,22 +565,29 @@ mod tests { let mut mock_deserializer = MockDeserializer::new(); - mock_deserializer - .expect_de_text() - .returning(|_| { - Err(DeserializerError::UnexpectedEvent { - expected_event_name: "text".to_string(), - found_event: Event::Start(BytesStart::new("ptype")), + // SAFETY: No argument lifetime is mistreated + unsafe { + mock_deserializer + .expect_de_text() + .returning(|_| { + Err(DeserializerError::UnexpectedEvent { + expected_event_name: "text".to_string(), + found_event: Event::Start(BytesStart::new("ptype")), + }) }) - }) - .times(1); + .times(1); + } - mock_deserializer - .expect_de_text() - .returning(|_| Ok("GLchar".to_string())) - .times(1); + // SAFETY: No argument lifetime is mistreated + unsafe { + mock_deserializer + .expect_de_text() + .returning(|_| Ok("GLchar".to_string())) + .times(1); + } - mock_deserializer + unsafe { + mock_deserializer .expect_de_tag_with::<String, DeserializerError, DeserializeWithFn<_, _, _>>() .with( eq("ptype"), @@ -540,18 +598,27 @@ mod tests func(&BytesStart::new(tag_name), deserializer) }) .times(1); + } - mock_deserializer - .expect_de_text() - .returning(|_| Ok("*".to_string())) - .times(1); + // SAFETY: No argument lifetime is mistreated + unsafe { + mock_deserializer + .expect_de_text() + .returning(|_| Ok("*".to_string())) + .times(1); + } - mock_deserializer - .expect_de_text() - .returning(|_| Ok("source".to_string())) - .times(1); + // SAFETY: No argument lifetime is mistreated + unsafe { + mock_deserializer + .expect_de_text() + .returning(|_| Ok("source".to_string())) + .times(1); + } - mock_deserializer + // SAFETY: No argument lifetime is mistreated + unsafe { + mock_deserializer .expect_de_tag_with::<String, DeserializerError, DeserializeWithFn<_, _, _>>() .with( eq("name"), @@ -562,6 +629,7 @@ mod tests func(&BytesStart::new(tag_name), deserializer) }) .times(1); + } let parameter = Parameter::deserialize(&BytesStart::new("param"), &mut mock_deserializer) @@ -576,17 +644,25 @@ mod tests { let mut mock_deserializer = MockDeserializer::new(); - mock_deserializer - .expect_de_text() - .returning(|_| Ok("const".to_string())) - .times(1); + // SAFETY: No argument lifetime is mistreated + unsafe { + mock_deserializer + .expect_de_text() + .returning(|_| Ok("const".to_string())) + .times(1); + } - mock_deserializer - .expect_de_text() - .returning(|_| Ok("GLchar".to_string())) - .times(1); + // SAFETY: No argument lifetime is mistreated + unsafe { + mock_deserializer + .expect_de_text() + .returning(|_| Ok("GLchar".to_string())) + .times(1); + } - mock_deserializer + // SAFETY: No argument lifetime is mistreated + unsafe { + mock_deserializer .expect_de_tag_with::<String, DeserializerError, DeserializeWithFn<_, _, _>>() .with( eq("ptype"), @@ -597,18 +673,27 @@ mod tests func(&BytesStart::new(tag_name), deserializer) }) .times(1); + } - mock_deserializer - .expect_de_text() - .returning(|_| Ok("*".to_string())) - .times(1); + // SAFETY: No argument lifetime is mistreated + unsafe { + mock_deserializer + .expect_de_text() + .returning(|_| Ok("*".to_string())) + .times(1); + } - mock_deserializer - .expect_de_text() - .returning(|_| Ok("name".to_string())) - .times(1); + // SAFETY: No argument lifetime is mistreated + unsafe { + mock_deserializer + .expect_de_text() + .returning(|_| Ok("name".to_string())) + .times(1); + } - mock_deserializer + // SAFETY: No argument lifetime is mistreated + unsafe { + mock_deserializer .expect_de_tag_with::<String, DeserializerError, DeserializeWithFn<_, _, _>>() .with( eq("name"), @@ -619,6 +704,7 @@ mod tests func(&BytesStart::new(tag_name), deserializer) }) .times(1); + } let parameter = Parameter::deserialize(&BytesStart::new("param"), &mut mock_deserializer) @@ -633,12 +719,17 @@ mod tests { let mut mock_deserializer = MockDeserializer::new(); - mock_deserializer - .expect_de_text() - .returning(|_| Ok("void *".to_string())) - .times(1); + // SAFETY: No argument lifetime is mistreated + unsafe { + mock_deserializer + .expect_de_text() + .returning(|_| Ok("void *".to_string())) + .times(1); + } - mock_deserializer + // SAFETY: No argument lifetime is mistreated + unsafe { + mock_deserializer .expect_de_tag_with::<String, DeserializerError, DeserializeWithFn<_, _, _>>() .with( eq("ptype"), @@ -652,23 +743,32 @@ mod tests }) }) .times(1); + } - mock_deserializer - .expect_de_text() - .returning(|_| { - Err(DeserializerError::UnexpectedEvent { - expected_event_name: "text".to_string(), - found_event: Event::Start(BytesStart::new("name")), + // SAFETY: No argument lifetime is mistreated + unsafe { + mock_deserializer + .expect_de_text() + .returning(|_| { + Err(DeserializerError::UnexpectedEvent { + expected_event_name: "text".to_string(), + found_event: Event::Start(BytesStart::new("name")), + }) }) - }) - .times(1); + .times(1); + } - mock_deserializer - .expect_de_text() - .returning(|_| Ok("pixels".to_string())) - .times(1); + // SAFETY: No argument lifetime is mistreated + unsafe { + mock_deserializer + .expect_de_text() + .returning(|_| Ok("pixels".to_string())) + .times(1); + } - mock_deserializer + // SAFETY: No argument lifetime is mistreated + unsafe { + mock_deserializer .expect_de_tag_with::<String, DeserializerError, DeserializeWithFn<_, _, _>>() .with( eq("name"), @@ -679,6 +779,7 @@ mod tests func(&BytesStart::new(tag_name), deserializer) }) .times(1); + } let parameter = Parameter::deserialize(&BytesStart::new("param"), &mut mock_deserializer) |