Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slightly beautify unit tests #24

Merged
merged 1 commit into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions udf-jsonify/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,21 +89,21 @@ mod tests {
(111.001, "float", true),
];

let mut s = String::from("{");
s.push_str(r#""decimal":1234.56,"#);
s.push_str(r#""empty_decimal":null,"#);
s.push_str(r#""empty_float":null,"#);
s.push_str(r#""empty_int":null,"#);
s.push_str(r#""empty_string":null,"#);
s.push_str(r#""float":111.001,"#);
s.push_str(r#""int":500,"#);
s.push_str(r#""neg_int":-500,"#);
s.push_str(r#""string":"some string""#);
s.push('}');
let expected = serde_json::json! {{
"decimal": 1234.56,
"empty_decimal": None::<()>,
"empty_float": None::<()>,
"empty_int": None::<()>,
"empty_string": None::<()>,
"float": 111.001,
"int": 500,
"neg_int": -500,
"string": "some string"
}};

let mut jsonify = Jsonify::init(cfg.as_init(), arglist.as_init()).unwrap();
let res = jsonify.process(cfg.as_process(), arglist.as_process(), None);

assert_eq!(res, Ok(s.as_str()));
assert_eq!(res, Ok(serde_json::to_string(&expected).unwrap().as_str()));
}
}
20 changes: 9 additions & 11 deletions udf-uuid/src/valid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,16 @@ mod tests {
fn test_validate_wrong_args() {
// Test with 0 and >1 args
let mut arglists = [
(mock_args![], 0),
(mock_args![("", "", false), ("", "", false)], 2),
(mock_args!(), 0),
(mock_args!(("", "", false), ("", "", false)), 2),
];

let mut cfg = MockUdfCfg::new();

for (args, count) in arglists.iter_mut() {
let res = UuidIsValid::init(cfg.as_init(), args.as_init());
assert_eq!(
res,
Err(format!("uuid_is_valid takes 1 argument but got {count}"))
);
let emsg = format!("uuid_is_valid takes 1 argument but got {count}");
assert_eq!(res, Err(emsg));
}
}

Expand All @@ -68,23 +66,23 @@ mod tests {
// Test with 0 and >1 args
let mut arglists = [
(
mock_args![("00908d94-c78d-4ea5-8aa5-5a06868f0420", "", false)],
mock_args!(("00908d94-c78d-4ea5-8aa5-5a06868f0420", "", false)),
1,
),
(
mock_args![("00908d94c78d4ea58aa55a06868f0420", "", false)],
mock_args!(("00908d94c78d4ea58aa55a06868f0420", "", false)),
1,
),
(
mock_args![("00908d94c78d-4ea5-8aa55a06868f0420", "", false)],
mock_args!(("00908d94c78d-4ea5-8aa55a06868f0420", "", false)),
1,
),
(
mock_args![("00908d94-c78d-4ea5-8aa5-5a06868f042", "", false)],
mock_args!(("00908d94-c78d-4ea5-8aa5-5a06868f042", "", false)),
0,
),
(
mock_args![("00908d94c78d4ea58aa55a06868f042", "", false)],
mock_args!(("00908d94c78d4ea58aa55a06868f042", "", false)),
0,
),
];
Expand Down
Loading