Skip to content

Commit 4bb1ff9

Browse files
committed
test(parse): wrap unit tests in cfg(test) module
Signed-off-by: Takuma IMAMURA <209989118+hyperfinitism@users.noreply.github.com>
1 parent 55cb0ef commit 4bb1ff9

1 file changed

Lines changed: 74 additions & 73 deletions

File tree

src/parse.rs

Lines changed: 74 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -680,86 +680,87 @@ pub fn parse_tpm2_operation(s: &str) -> Result<u16, String> {
680680
}
681681
}
682682

683-
// ===========================================================================
684-
// Tests
685-
// ===========================================================================
686-
687-
#[test]
688-
fn symdef_aes_256_cbc() {
689-
let def = parse_symmetric_definition("aes-256-cbc").unwrap();
690-
assert!(matches!(
691-
def,
692-
SymmetricDefinition::Aes {
693-
key_bits: AesKeyBits::Aes256,
694-
mode: SymmetricMode::Cbc,
695-
}
696-
));
697-
}
683+
#[cfg(test)]
684+
mod tests {
685+
use super::*;
686+
687+
#[test]
688+
fn symdef_aes_256_cbc() {
689+
let def = parse_symmetric_definition("aes-256-cbc").unwrap();
690+
assert!(matches!(
691+
def,
692+
SymmetricDefinition::Aes {
693+
key_bits: AesKeyBits::Aes256,
694+
mode: SymmetricMode::Cbc,
695+
}
696+
));
697+
}
698698

699-
#[test]
700-
fn symdef_camellia_192_ecb() {
701-
let def = parse_symmetric_definition("camellia-192-ecb").unwrap();
702-
assert!(matches!(
703-
def,
704-
SymmetricDefinition::Camellia {
705-
key_bits: CamelliaKeyBits::Camellia192,
706-
mode: SymmetricMode::Ecb,
707-
}
708-
));
709-
}
699+
#[test]
700+
fn symdef_camellia_192_ecb() {
701+
let def = parse_symmetric_definition("camellia-192-ecb").unwrap();
702+
assert!(matches!(
703+
def,
704+
SymmetricDefinition::Camellia {
705+
key_bits: CamelliaKeyBits::Camellia192,
706+
mode: SymmetricMode::Ecb,
707+
}
708+
));
709+
}
710710

711-
#[test]
712-
fn symdef_xor_sha1() {
713-
let def = parse_symmetric_definition("xor-sha1").unwrap();
714-
assert!(matches!(
715-
def,
716-
SymmetricDefinition::Xor {
717-
hashing_algorithm: HashingAlgorithm::Sha1,
718-
}
719-
));
720-
}
711+
#[test]
712+
fn symdef_xor_sha1() {
713+
let def = parse_symmetric_definition("xor-sha1").unwrap();
714+
assert!(matches!(
715+
def,
716+
SymmetricDefinition::Xor {
717+
hashing_algorithm: HashingAlgorithm::Sha1,
718+
}
719+
));
720+
}
721721

722-
// Legacy shorthand forms
723-
#[test]
724-
fn symdef_aes128cfb() {
725-
let def = parse_symmetric_definition("aes128cfb").unwrap();
726-
assert!(matches!(def, SymmetricDefinition::AES_128_CFB));
727-
}
722+
// Legacy shorthand forms
723+
#[test]
724+
fn symdef_aes128cfb() {
725+
let def = parse_symmetric_definition("aes128cfb").unwrap();
726+
assert!(matches!(def, SymmetricDefinition::AES_128_CFB));
727+
}
728728

729-
#[test]
730-
fn symdef_aes256cfb() {
731-
let def = parse_symmetric_definition("aes256cfb").unwrap();
732-
assert!(matches!(def, SymmetricDefinition::AES_256_CFB));
733-
}
729+
#[test]
730+
fn symdef_aes256cfb() {
731+
let def = parse_symmetric_definition("aes256cfb").unwrap();
732+
assert!(matches!(def, SymmetricDefinition::AES_256_CFB));
733+
}
734734

735-
#[test]
736-
fn symdef_xor() {
737-
let def = parse_symmetric_definition("xor").unwrap();
738-
assert!(matches!(
739-
def,
740-
SymmetricDefinition::Xor {
741-
hashing_algorithm: HashingAlgorithm::Sha256,
742-
}
743-
));
744-
}
735+
#[test]
736+
fn symdef_xor() {
737+
let def = parse_symmetric_definition("xor").unwrap();
738+
assert!(matches!(
739+
def,
740+
SymmetricDefinition::Xor {
741+
hashing_algorithm: HashingAlgorithm::Sha256,
742+
}
743+
));
744+
}
745745

746-
// Error cases
747-
#[test]
748-
fn symdef_unknown_algo() {
749-
assert!(parse_symmetric_definition("foobar-128-cfb").is_err());
750-
}
746+
// Error cases
747+
#[test]
748+
fn symdef_unknown_algo() {
749+
assert!(parse_symmetric_definition("foobar-128-cfb").is_err());
750+
}
751751

752-
#[test]
753-
fn symdef_aes_128_with_invalid_null_mode() {
754-
assert!(parse_symmetric_definition("aes-128-null").is_err());
755-
}
752+
#[test]
753+
fn symdef_aes_128_with_invalid_null_mode() {
754+
assert!(parse_symmetric_definition("aes-128-null").is_err());
755+
}
756756

757-
#[test]
758-
fn symdef_sm4_cbc_with_unavailable_192_bits() {
759-
assert!(parse_symmetric_definition("sm4-192-cbc").is_err());
760-
}
757+
#[test]
758+
fn symdef_sm4_cbc_with_unavailable_192_bits() {
759+
assert!(parse_symmetric_definition("sm4-192-cbc").is_err());
760+
}
761761

762-
#[test]
763-
fn symdef_empty_string() {
764-
assert!(parse_symmetric_definition("").is_err());
762+
#[test]
763+
fn symdef_empty_string() {
764+
assert!(parse_symmetric_definition("").is_err());
765+
}
765766
}

0 commit comments

Comments
 (0)