You've already forked ctap-types
mirror of
https://github.com/trussed-dev/ctap-types.git
synced 2026-06-20 04:16:17 -07:00
Add tests for enum counts and conversions
This commit is contained in:
@@ -27,6 +27,7 @@ ciborium = "0.2"
|
||||
hex = "0.4"
|
||||
hex-literal = "0.4.1"
|
||||
serde_test = "1.0.176"
|
||||
strum = { version = "0.28", features = ["derive"] }
|
||||
|
||||
[features]
|
||||
std = []
|
||||
|
||||
@@ -258,6 +258,7 @@ impl ResponseBuilder {
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
|
||||
#[cfg_attr(test, derive(strum::EnumCount, strum::VariantArray))]
|
||||
#[non_exhaustive]
|
||||
#[serde(into = "&str", try_from = "&str")]
|
||||
pub enum Version {
|
||||
@@ -308,6 +309,7 @@ impl TryFrom<&str> for Version {
|
||||
pub const EXTENSION_COUNT: usize = 7;
|
||||
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
|
||||
#[cfg_attr(test, derive(strum::EnumCount, strum::VariantArray))]
|
||||
#[non_exhaustive]
|
||||
#[serde(into = "&str", try_from = "&str")]
|
||||
pub enum Extension {
|
||||
@@ -364,6 +366,7 @@ impl TryFrom<&str> for Extension {
|
||||
pub const TRANSPORT_COUNT: usize = 3;
|
||||
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
|
||||
#[cfg_attr(test, derive(strum::EnumCount, strum::VariantArray))]
|
||||
#[non_exhaustive]
|
||||
#[serde(into = "&str", try_from = "&str")]
|
||||
pub enum Transport {
|
||||
@@ -526,7 +529,42 @@ pub struct Certifications {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use core::fmt::Debug;
|
||||
use serde_test::{assert_ser_tokens, assert_tokens, Token};
|
||||
use strum::{EnumCount, VariantArray};
|
||||
|
||||
fn test_enum<T>(count: usize)
|
||||
where
|
||||
T: EnumCount
|
||||
+ VariantArray
|
||||
+ Into<&'static str>
|
||||
+ for<'a> TryFrom<&'a str>
|
||||
+ PartialEq
|
||||
+ Debug
|
||||
+ Copy,
|
||||
{
|
||||
assert_eq!(count, T::COUNT);
|
||||
|
||||
for variant in T::VARIANTS {
|
||||
let variant_str: &str = (*variant).into();
|
||||
assert_eq!(Some(*variant), T::try_from(variant_str).ok());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_version() {
|
||||
test_enum::<Version>(VERSION_COUNT);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_transport() {
|
||||
test_enum::<Transport>(TRANSPORT_COUNT);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_extension() {
|
||||
test_enum::<Extension>(EXTENSION_COUNT);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_serde_version() {
|
||||
|
||||
@@ -137,6 +137,7 @@ impl PublicKeyCredentialUserEntity {
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
|
||||
#[cfg_attr(test, derive(strum::EnumCount, strum::VariantArray))]
|
||||
#[non_exhaustive]
|
||||
pub enum KnownPublicKeyCredentialParameters {
|
||||
ES256,
|
||||
@@ -289,6 +290,16 @@ pub struct PublicKeyCredentialDescriptorRef<'a> {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use strum::{EnumCount as _, VariantArray as _};
|
||||
|
||||
#[test]
|
||||
fn test_known_cred_params() {
|
||||
assert_eq!(KnownPublicKeyCredentialParameters::COUNT, COUNT_KNOWN_ALGS);
|
||||
assert_eq!(
|
||||
KnownPublicKeyCredentialParameters::ALL,
|
||||
KnownPublicKeyCredentialParameters::VARIANTS
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_truncate() {
|
||||
|
||||
Reference in New Issue
Block a user