diff options
author | Yusuke Tanaka <yusuktan@maguro.dev> | 2021-02-02 00:55:23 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-01 10:55:23 -0500 |
commit | 84f8b87f1b0fc6b7ec3a7f157f99d7f098d43101 (patch) | |
tree | 37ad25f567cbce1cb4f1e6b1f33360233de8fe78 /runtime/ops | |
parent | 23281be33a378ca548f0a407f642331f20b00a43 (diff) |
chore: make all tests annotated with `#[cfg(test)]` (#9347)
Diffstat (limited to 'runtime/ops')
-rw-r--r-- | runtime/ops/dispatch_minimal.rs | 77 |
1 files changed, 41 insertions, 36 deletions
diff --git a/runtime/ops/dispatch_minimal.rs b/runtime/ops/dispatch_minimal.rs index 01a47e2ab..b35d0def5 100644 --- a/runtime/ops/dispatch_minimal.rs +++ b/runtime/ops/dispatch_minimal.rs @@ -75,23 +75,6 @@ impl Into<Box<[u8]>> for ErrorRecord { } } -#[test] -fn test_error_record() { - let expected = vec![ - 1, 0, 0, 0, 255, 255, 255, 255, 11, 0, 0, 0, 66, 97, 100, 82, 101, 115, - 111, 117, 114, 99, 101, 69, 114, 114, 111, 114, - ]; - let err_record = ErrorRecord { - promise_id: 1, - arg: -1, - error_len: 11, - error_class: b"BadResource", - error_message: b"Error".to_vec(), - }; - let buf: Box<[u8]> = err_record.into(); - assert_eq!(buf, expected.into_boxed_slice()); -} - pub fn parse_min_record(bytes: &[u8]) -> Option<Record> { if bytes.len() % std::mem::size_of::<i32>() != 0 { return None; @@ -113,25 +96,6 @@ pub fn parse_min_record(bytes: &[u8]) -> Option<Record> { }) } -#[test] -fn test_parse_min_record() { - let buf = vec![1, 0, 0, 0, 3, 0, 0, 0, 4, 0, 0, 0]; - assert_eq!( - parse_min_record(&buf), - Some(Record { - promise_id: 1, - arg: 3, - result: 4 - }) - ); - - let buf = vec![]; - assert_eq!(parse_min_record(&buf), None); - - let buf = vec![5]; - assert_eq!(parse_min_record(&buf), None); -} - pub fn minimal_op<F>(op_fn: F) -> Box<OpFn> where F: Fn(Rc<RefCell<OpState>>, bool, i32, BufVec) -> MinimalOp + 'static, @@ -203,3 +167,44 @@ where } }) } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_error_record() { + let expected = vec![ + 1, 0, 0, 0, 255, 255, 255, 255, 11, 0, 0, 0, 66, 97, 100, 82, 101, 115, + 111, 117, 114, 99, 101, 69, 114, 114, 111, 114, + ]; + let err_record = ErrorRecord { + promise_id: 1, + arg: -1, + error_len: 11, + error_class: b"BadResource", + error_message: b"Error".to_vec(), + }; + let buf: Box<[u8]> = err_record.into(); + assert_eq!(buf, expected.into_boxed_slice()); + } + + #[test] + fn test_parse_min_record() { + let buf = vec![1, 0, 0, 0, 3, 0, 0, 0, 4, 0, 0, 0]; + assert_eq!( + parse_min_record(&buf), + Some(Record { + promise_id: 1, + arg: 3, + result: 4 + }) + ); + + let buf = vec![]; + assert_eq!(parse_min_record(&buf), None); + + let buf = vec![5]; + assert_eq!(parse_min_record(&buf), None); + } +} |