Expand as_ref and as_mut tests

The tests for both `Script` and `ScriptBuf` `as_ref` and `as_mut` only
covered the `u8` impl.

Expand the tests to cover the `Self` impl as well.

The allow useless_asref is required to remove a clippy lint.  Removing
the "useless" as_ref also removes the test coverage of the as_ref or
as_mut impl.
This commit is contained in:
Jamil Lambert, PhD 2025-04-15 11:41:08 +01:00 committed by Jamil Lambert
parent afa51f7bfa
commit 8a096b77d5
No known key found for this signature in database
GPG Key ID: 7F574053F8F17A64
1 changed files with 18 additions and 0 deletions

View File

@ -632,30 +632,48 @@ mod tests {
let script_buf = ScriptBuf::from(vec![0x51, 0x52, 0x53]);
let script_ref: &[u8] = script_buf.as_ref();
assert_eq!(script_ref, &[0x51, 0x52, 0x53]);
let script_ref: &Script = script_buf.as_ref();
assert_eq!(script_ref.as_bytes(), &[0x51, 0x52, 0x53]);
}
#[test]
fn scriptbuf_as_mut() {
let mut script_buf = ScriptBuf::from(vec![0x51, 0x52, 0x53]);
let script_mut: &mut [u8] = script_buf.as_mut();
script_mut[0] = 0x50;
assert_eq!(script_mut, [0x50, 0x52, 0x53]);
let script_mut: &mut Script = script_buf.as_mut();
script_mut.as_mut_bytes()[1] = 0x51;
assert_eq!(script_buf.as_bytes(), &[0x50, 0x51, 0x53]);
}
#[test]
#[allow(clippy::useless_asref)]
fn script_as_ref() {
let script = Script::from_bytes(&[0x51, 0x52, 0x53]);
let script_ref: &[u8] = script.as_ref();
assert_eq!(script_ref, &[0x51, 0x52, 0x53]);
let script_ref: &Script = script.as_ref();
assert_eq!(script_ref.as_bytes(), &[0x51, 0x52, 0x53]);
}
#[test]
#[allow(clippy::useless_asref)]
fn script_as_mut() {
let bytes = &mut [0x51, 0x52, 0x53];
let script = Script::from_bytes_mut(bytes);
let script_mut: &mut [u8] = script.as_mut();
script_mut[0] = 0x50;
assert_eq!(script_mut, [0x50, 0x52, 0x53]);
let script_mut: &mut Script = script.as_mut();
script_mut.as_mut_bytes()[1] = 0x51;
assert_eq!(script.as_bytes(), &[0x50, 0x51, 0x53]);
}
#[test]