Merge rust-bitcoin/rust-bitcoin#3971: primitives: Add tests to `script::borrowed` and `script::owned`
6cde537d9b
Add `ScriptBuf` tests (Jamil Lambert, PhD)566a6e5da6
Add `Script` tests (Jamil Lambert, PhD) Pull request description: Add tests to both `primitives/src/script/borrowed.rs` and `primitives/src/script/owned.rs` to kill the mutants found by running `cargo mutants`. ACKs for top commit: tcharding: ACK6cde537d9b
apoelstra: ACK 6cde537d9ba9bd56495ca47afb3f9a560e9b4358; successfully ran local tests Kixunil: ACK6cde537d9b
Tree-SHA512: fc36c1e9249753ebcb0f72e8195c85a7eccd3a0b8b3e4e753102d405494e1f72cd1cdfb6f12af41a9aa6f2ff10142b95827039fa428997b96510a5e262007b25
This commit is contained in:
commit
98db7bca74
|
@ -152,3 +152,62 @@ delegate_index!(
|
|||
RangeToInclusive<usize>,
|
||||
(Bound<usize>, Bound<usize>)
|
||||
);
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn script_from_bytes() {
|
||||
let script = Script::from_bytes(&[1, 2, 3]);
|
||||
assert_eq!(script.as_bytes(), [1, 2, 3]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn script_from_bytes_mut() {
|
||||
let bytes = &mut [1, 2, 3];
|
||||
let script = Script::from_bytes_mut(bytes);
|
||||
script.as_mut_bytes()[0] = 4;
|
||||
assert_eq!(script.as_mut_bytes(), [4, 2, 3]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn script_to_vec() {
|
||||
let script = Script::from_bytes(&[1, 2, 3]);
|
||||
assert_eq!(script.to_vec(), vec![1, 2, 3]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn script_len() {
|
||||
let script = Script::from_bytes(&[1, 2, 3]);
|
||||
assert_eq!(script.len(), 3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn script_is_empty() {
|
||||
let script = Script::new();
|
||||
assert!(script.is_empty());
|
||||
|
||||
let script = Script::from_bytes(&[1, 2, 3]);
|
||||
assert!(!script.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn script_to_owned() {
|
||||
let script = Script::from_bytes(&[1, 2, 3]);
|
||||
let script_buf = script.to_owned();
|
||||
assert_eq!(script_buf.as_bytes(), [1, 2, 3]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_index() {
|
||||
let script = Script::from_bytes(&[1, 2, 3, 4, 5]);
|
||||
|
||||
assert_eq!(script[1..3].as_bytes(), &[2, 3]);
|
||||
assert_eq!(script[2..].as_bytes(), &[3, 4, 5]);
|
||||
assert_eq!(script[..3].as_bytes(), &[1, 2, 3]);
|
||||
assert_eq!(script[..].as_bytes(), &[1, 2, 3, 4, 5]);
|
||||
assert_eq!(script[1..=3].as_bytes(), &[2, 3, 4]);
|
||||
assert_eq!(script[..=2].as_bytes(), &[1, 2, 3]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -94,3 +94,69 @@ impl<'a> Arbitrary<'a> for ScriptBuf {
|
|||
Ok(ScriptBuf(v))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn script_buf_from_bytes() {
|
||||
let bytes = vec![1, 2, 3];
|
||||
let script = ScriptBuf::from_bytes(bytes.clone());
|
||||
assert_eq!(script.0, bytes);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn script_buf_as_script() {
|
||||
let bytes = vec![1, 2, 3];
|
||||
let script = ScriptBuf::from_bytes(bytes.clone());
|
||||
let script_ref = script.as_script();
|
||||
assert_eq!(script_ref.as_bytes(), bytes);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn script_buf_as_mut_script() {
|
||||
let bytes = vec![1, 2, 3];
|
||||
let mut script = ScriptBuf::from_bytes(bytes.clone());
|
||||
let script_mut_ref = script.as_mut_script();
|
||||
script_mut_ref.as_mut_bytes()[0] = 4;
|
||||
assert_eq!(script.0, vec![4, 2, 3]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn script_buf_into_bytes() {
|
||||
let bytes = vec![1, 2, 3];
|
||||
let script = ScriptBuf::from_bytes(bytes.clone());
|
||||
let result = script.into_bytes();
|
||||
assert_eq!(result, bytes);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn script_buf_into_boxed_script() {
|
||||
let bytes = vec![1, 2, 3];
|
||||
let script = ScriptBuf::from_bytes(bytes.clone());
|
||||
let boxed_script = script.into_boxed_script();
|
||||
assert_eq!(boxed_script.as_bytes(), bytes);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn script_buf_capacity() {
|
||||
let script = ScriptBuf::with_capacity(10);
|
||||
assert!(script.0.capacity() >= 10);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn script_buf_reserve() {
|
||||
let mut script = ScriptBuf::new();
|
||||
script.reserve(10);
|
||||
assert!(script.0.capacity() >= 10);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn script_buf_reserve_exact() {
|
||||
let mut script = ScriptBuf::new();
|
||||
script.reserve_exact(10);
|
||||
assert!(script.0.capacity() >= 10);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue