From 3232f2b1dad3983729c670ccbbcf82fd3b74babf Mon Sep 17 00:00:00 2001 From: dietrich Date: Wed, 23 Sep 2020 10:57:04 +0200 Subject: [PATCH] add test case if gecos has no other field. --- src/passwd.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/passwd.rs b/src/passwd.rs index 2ef1c61..0d41ed1 100644 --- a/src/passwd.rs +++ b/src/passwd.rs @@ -281,9 +281,10 @@ fn test_parse_gecos() { // test if the Gecos field can be parsed and the resulting struct is populated correctly. let gcd = "Full Name,504,11345342,ä1-2312,myemail@test.com"; let gcs = "A böring comment →"; - let gc_failed: &str = "systemd Network Management,,,"; + let gc_no_other: &str = "systemd Network Management,,,"; let res_detail = Gecos::try_from(gcd).unwrap(); let res_simple = Gecos::try_from(gcs).unwrap(); + let res_no_other = Gecos::try_from(gc_no_other).unwrap(); match res_simple { Gecos::Simple { comment } => assert_eq!(comment, "A böring comment →"), _ => unreachable!(), @@ -304,6 +305,22 @@ fn test_parse_gecos() { } _ => unreachable!(), } + match res_no_other { + Gecos::Detail { + full_name, + room, + phone_work, + phone_home, + other, + } => { + assert_eq!(full_name, "systemd Network Management"); + assert_eq!(room, ""); + assert_eq!(phone_work, ""); + assert_eq!(phone_home, ""); + assert_eq!(other, ""); + } + _ => unreachable!(), + } } #[test]