#[cfg(test)]
mod conversion {
use to_binary::BinaryString;
#[test]
fn from_hex() {
let bin = BinaryString::from_hex("48656C6C6F").unwrap();
assert_eq!(bin.0, "0100100001100101011011000110110001101111");
}
#[test]
#[should_panic]
fn from_hex_4_bits() {
let _bin = BinaryString::from_hex("48656C6C6FD").unwrap();
}
#[test]
fn from_string() {
let bin = BinaryString::from(String::from("Test"));
assert_eq!(bin.0, "01010100011001010111001101110100");
}
#[test]
fn from_string_japanese() {
let bin = BinaryString::from(String::from("私はガ"));
assert_eq!(
bin.0,
"111001111010011110000001111000111000000110101111111000111000001010101100"
)
}
#[test]
fn from_vector() {
let mut vector: Vec<u8> = Vec::new();
vector.push(45u8);
vector.push(36u8);
vector.push(117u8);
let bin = BinaryString::from(vector);
assert_eq!(bin.0, "001011010010010001110101")
}
#[test]
fn from_str() {
let bin = BinaryString::from("Hello");
assert_eq!(bin.0, "0100100001100101011011000110110001101111")
}
}
#[cfg(test)]
mod advanced_tests {
#[allow(unused_imports)]
use to_binary::{BinaryString,BinaryError};
#[test]
fn single_byte_test_with_spaces() {
let byte: u8 = 111u8;
let bin_string = BinaryString::from(byte);
let spaces = bin_string.add_spaces().unwrap();
let removed_spaces = spaces.remove_spaces();
assert_eq!(bin_string, spaces);
assert_eq!(bin_string,removed_spaces);
assert_eq!(spaces,removed_spaces);
}
}