Split big tests into multiple tests.
Add lazy_static to dev-dependencies just for the tests.
This commit is contained in:
parent
3be176c3f4
commit
f90ba750c3
|
@ -2,6 +2,12 @@
|
||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
version = 3
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "lazy_static"
|
||||||
|
version = "1.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "memchr"
|
name = "memchr"
|
||||||
version = "2.5.0"
|
version = "2.5.0"
|
||||||
|
@ -28,5 +34,6 @@ dependencies = [
|
||||||
name = "vocnom"
|
name = "vocnom"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"lazy_static",
|
||||||
"nom",
|
"nom",
|
||||||
]
|
]
|
||||||
|
|
|
@ -6,4 +6,7 @@ edition = "2021"
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
nom = "7"
|
nom = "7"
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
lazy_static = "1.4.0"
|
||||||
|
|
|
@ -326,4 +326,4 @@ pub fn parse_voc(input: &[u8]) -> nom::IResult<&[u8], Voc> {
|
||||||
blocks,
|
blocks,
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,36 +1,55 @@
|
||||||
use vocnom::parser::{BlockType, Codec, parse_voc};
|
use lazy_static::lazy_static;
|
||||||
|
use vocnom::parser::{parse_voc, BlockType, Codec, Voc};
|
||||||
|
|
||||||
|
lazy_static! {
|
||||||
|
static ref VOC: Voc = {
|
||||||
|
let input = include_bytes!("../assets/ADOOR2.VOC");
|
||||||
|
let (_, voc) = parse_voc(input).unwrap();
|
||||||
|
voc
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn adoor2_test() {
|
fn version_test() {
|
||||||
let input = include_bytes!("../assets/ADOOR2.VOC");
|
assert_eq!((VOC.version.major, VOC.version.minor), (1, 20));
|
||||||
|
}
|
||||||
|
|
||||||
match parse_voc(input) {
|
#[test]
|
||||||
Ok((_, voc)) => {
|
fn checksum_test() {
|
||||||
// Version
|
// Checksum
|
||||||
assert_eq!((voc.version.major, voc.version.minor), (1, 20));
|
assert_eq!(VOC.checksum.valid, true);
|
||||||
|
assert_eq!(VOC.checksum.value, 0x111f);
|
||||||
|
}
|
||||||
|
|
||||||
// Checksum
|
#[test]
|
||||||
assert_eq!(voc.checksum.valid, true);
|
fn num_blocks_test() {
|
||||||
assert_eq!(voc.checksum.value, 0x111f);
|
// Number of blocks
|
||||||
|
assert_eq!(VOC.blocks.len(), 2);
|
||||||
|
}
|
||||||
|
|
||||||
// Number of blocks
|
#[test]
|
||||||
assert_eq!(voc.blocks.len(), 2);
|
fn block_0_sound_data_new_test() {
|
||||||
|
// Sound data new
|
||||||
// Sound data new
|
if let BlockType::SoundDataNew {
|
||||||
if let BlockType::SoundDataNew { sample_rate, bits, channels, codec, reserved, data} = &voc.blocks[1] {
|
sample_rate,
|
||||||
assert_eq!(sample_rate, &11025);
|
bits,
|
||||||
assert_eq!(bits, &8);
|
channels,
|
||||||
assert_eq!(channels, &1);
|
codec,
|
||||||
assert_eq!(codec, &Codec::Pcm8BitUnsigned);
|
reserved,
|
||||||
assert_eq!(reserved, &0);
|
data,
|
||||||
assert_eq!(data.len(), 21394);
|
} = &VOC.blocks[0]
|
||||||
}
|
{
|
||||||
|
assert_eq!(sample_rate, &11025);
|
||||||
// Terminator
|
assert_eq!(bits, &8);
|
||||||
assert_eq!(&voc.blocks[1], &BlockType::Terminator);
|
assert_eq!(channels, &1);
|
||||||
}
|
assert_eq!(codec, &Codec::Pcm8BitUnsigned);
|
||||||
Err(err) => {
|
assert_eq!(reserved, &0);
|
||||||
println!("Error parsing VOC file: {:?}", err);
|
assert_eq!(data.len(), 21394);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn block_1_terminator_test() {
|
||||||
|
// Repeat end
|
||||||
|
assert_eq!(&VOC.blocks[1], &BlockType::Terminator);
|
||||||
|
}
|
||||||
|
|
|
@ -1,51 +1,81 @@
|
||||||
use vocnom::parser::{BlockType, Codec, parse_voc};
|
use lazy_static::lazy_static;
|
||||||
|
use vocnom::parser::{parse_voc, BlockType, Codec, Voc};
|
||||||
|
|
||||||
|
lazy_static! {
|
||||||
|
static ref VOC: Voc = {
|
||||||
|
let input = include_bytes!("../assets/CONGA.VOC");
|
||||||
|
let (_, voc) = parse_voc(input).unwrap();
|
||||||
|
voc
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn conga_test() {
|
fn version_test() {
|
||||||
let input = include_bytes!("../assets/CONGA.VOC");
|
assert_eq!((VOC.version.major, VOC.version.minor), (1, 10));
|
||||||
|
}
|
||||||
|
|
||||||
match parse_voc(input) {
|
#[test]
|
||||||
Ok((_, voc)) => {
|
fn checksum_test() {
|
||||||
// Version
|
// Checksum
|
||||||
assert_eq!((voc.version.major, voc.version.minor), (1, 10));
|
assert_eq!(VOC.checksum.valid, true);
|
||||||
|
assert_eq!(VOC.checksum.value, 0x1129);
|
||||||
|
}
|
||||||
|
|
||||||
// Checksum
|
#[test]
|
||||||
assert_eq!(voc.checksum.valid, true);
|
fn num_blocks_test() {
|
||||||
assert_eq!(voc.checksum.value, 0x1129);
|
// Number of blocks
|
||||||
|
assert_eq!(VOC.blocks.len(), 8);
|
||||||
|
}
|
||||||
|
|
||||||
// Number of blocks
|
#[test]
|
||||||
assert_eq!(voc.blocks.len(), 8);
|
fn block_0_repeat_start_test() {
|
||||||
|
// Repeat start
|
||||||
// Repeat start
|
if let BlockType::RepeatStart { count } = &VOC.blocks[0] {
|
||||||
if let BlockType::RepeatStart { count } = &voc.blocks[0] {
|
assert_eq!(count, &1);
|
||||||
assert_eq!(count, &1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Extra information
|
|
||||||
if let BlockType::ExtraInformation { sample_rate, channels, codec} = &voc.blocks[1] {
|
|
||||||
assert_eq!(sample_rate, &11158);
|
|
||||||
assert_eq!(channels, &1);
|
|
||||||
assert_eq!(codec, &Codec::Pcm8BitUnsigned);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sound data
|
|
||||||
if let BlockType::SoundData { sample_rate, codec, data} = &voc.blocks[2] {
|
|
||||||
assert_eq!(sample_rate, &22222);
|
|
||||||
assert_eq!(codec, &Codec::Pcm8BitUnsigned);
|
|
||||||
assert_eq!(data.len(), 164912);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Repeat end
|
|
||||||
assert_eq!(&voc.blocks[3], &BlockType::RepeatEnd);
|
|
||||||
|
|
||||||
// Terminator
|
|
||||||
assert_eq!(&voc.blocks[4], &BlockType::Terminator);
|
|
||||||
assert_eq!(&voc.blocks[5], &BlockType::Terminator);
|
|
||||||
assert_eq!(&voc.blocks[6], &BlockType::Terminator);
|
|
||||||
assert_eq!(&voc.blocks[7], &BlockType::Terminator);
|
|
||||||
}
|
|
||||||
Err(err) => {
|
|
||||||
println!("Error parsing VOC file: {:?}", err);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn block_1_extra_information_test() {
|
||||||
|
// Extra information
|
||||||
|
if let BlockType::ExtraInformation {
|
||||||
|
sample_rate,
|
||||||
|
channels,
|
||||||
|
codec,
|
||||||
|
} = &VOC.blocks[1]
|
||||||
|
{
|
||||||
|
assert_eq!(sample_rate, &11158);
|
||||||
|
assert_eq!(channels, &1);
|
||||||
|
assert_eq!(codec, &Codec::Pcm8BitUnsigned);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn block_2_sound_data_test() {
|
||||||
|
// Sound data
|
||||||
|
if let BlockType::SoundData {
|
||||||
|
sample_rate,
|
||||||
|
codec,
|
||||||
|
data,
|
||||||
|
} = &VOC.blocks[2]
|
||||||
|
{
|
||||||
|
assert_eq!(sample_rate, &22222);
|
||||||
|
assert_eq!(codec, &Codec::Pcm8BitUnsigned);
|
||||||
|
assert_eq!(data.len(), 164912);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn block_3_repeat_end_test() {
|
||||||
|
// Repeat end
|
||||||
|
assert_eq!(&VOC.blocks[3], &BlockType::RepeatEnd);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn blocks_4_to_7_terminator_test() {
|
||||||
|
// Terminator
|
||||||
|
assert_eq!(&VOC.blocks[4], &BlockType::Terminator);
|
||||||
|
assert_eq!(&VOC.blocks[5], &BlockType::Terminator);
|
||||||
|
assert_eq!(&VOC.blocks[6], &BlockType::Terminator);
|
||||||
|
assert_eq!(&VOC.blocks[7], &BlockType::Terminator);
|
||||||
|
}
|
||||||
|
|
|
@ -1,38 +1,57 @@
|
||||||
use vocnom::parser::{BlockType, Codec, parse_voc};
|
use lazy_static::lazy_static;
|
||||||
|
use vocnom::parser::{parse_voc, BlockType, Codec, Voc};
|
||||||
|
|
||||||
|
lazy_static! {
|
||||||
|
static ref VOC: Voc = {
|
||||||
|
let input = include_bytes!("../assets/EDEN.MUS");
|
||||||
|
let (_, voc) = parse_voc(input).unwrap();
|
||||||
|
voc
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn edenmus_test() {
|
fn version_test() {
|
||||||
let input = include_bytes!("../assets/EDEN.MUS");
|
assert_eq!((VOC.version.major, VOC.version.minor), (1, 10));
|
||||||
|
}
|
||||||
|
|
||||||
match parse_voc(input) {
|
#[test]
|
||||||
Ok((_, voc)) => {
|
fn checksum_test() {
|
||||||
// Version
|
// Checksum
|
||||||
assert_eq!((voc.version.major, voc.version.minor), (1, 10));
|
assert_eq!(VOC.checksum.valid, true);
|
||||||
|
assert_eq!(VOC.checksum.value, 0x1129);
|
||||||
|
}
|
||||||
|
|
||||||
// Checksum
|
#[test]
|
||||||
assert_eq!(voc.checksum.valid, true);
|
fn num_blocks_test() {
|
||||||
assert_eq!(voc.checksum.value, 0x1129);
|
// Number of blocks
|
||||||
|
assert_eq!(VOC.blocks.len(), 3);
|
||||||
|
}
|
||||||
|
|
||||||
// Number of blocks
|
#[test]
|
||||||
assert_eq!(voc.blocks.len(), 3);
|
fn block_0_text_test() {
|
||||||
|
// Text block
|
||||||
// Text block
|
if let BlockType::Text { data } = &VOC.blocks[0] {
|
||||||
if let BlockType::Text { data} = &voc.blocks[0] {
|
assert_eq!(data.len(), 151);
|
||||||
assert_eq!(data.len(), 151);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sound data
|
|
||||||
if let BlockType::SoundData { sample_rate, codec, data} = &voc.blocks[1] {
|
|
||||||
assert_eq!(sample_rate, &11111);
|
|
||||||
assert_eq!(codec, &Codec::Pcm8BitUnsigned);
|
|
||||||
assert_eq!(data.len(), 809282);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Terminator
|
|
||||||
assert_eq!(&voc.blocks[2], &BlockType::Terminator);
|
|
||||||
}
|
|
||||||
Err(err) => {
|
|
||||||
println!("Error parsing VOC file: {:?}", err);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn block_1_sound_data_test() {
|
||||||
|
// Sound data
|
||||||
|
if let BlockType::SoundData {
|
||||||
|
sample_rate,
|
||||||
|
codec,
|
||||||
|
data,
|
||||||
|
} = &VOC.blocks[1]
|
||||||
|
{
|
||||||
|
assert_eq!(sample_rate, &11111);
|
||||||
|
assert_eq!(codec, &Codec::Pcm8BitUnsigned);
|
||||||
|
assert_eq!(data.len(), 809282);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn block_2_terminator_test() {
|
||||||
|
// Repeat end
|
||||||
|
assert_eq!(&VOC.blocks[2], &BlockType::Terminator);
|
||||||
|
}
|
||||||
|
|
|
@ -1,35 +1,51 @@
|
||||||
use vocnom::parser::{BlockType, Codec, parse_voc};
|
use lazy_static::lazy_static;
|
||||||
|
use vocnom::parser::{parse_voc, BlockType, Codec, Voc};
|
||||||
|
|
||||||
|
lazy_static! {
|
||||||
|
static ref VOC: Voc = {
|
||||||
|
let input = include_bytes!("../assets/GUARDIAN.VOC");
|
||||||
|
let (_, voc) = parse_voc(input).unwrap();
|
||||||
|
voc
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn guardian_test() {
|
fn version_test() {
|
||||||
let input = include_bytes!("../assets/GUARDIAN.VOC");
|
assert_eq!((VOC.version.major, VOC.version.minor), (1, 10));
|
||||||
|
}
|
||||||
|
|
||||||
match parse_voc(input) {
|
#[test]
|
||||||
Ok((_, voc)) => {
|
fn checksum_test() {
|
||||||
// Version
|
// Checksum
|
||||||
assert_eq!((voc.version.major, voc.version.minor), (1, 10));
|
assert_eq!(VOC.checksum.valid, true);
|
||||||
|
assert_eq!(VOC.checksum.value, 0x1129);
|
||||||
|
}
|
||||||
|
|
||||||
// Checksum
|
#[test]
|
||||||
assert_eq!(voc.checksum.valid, true);
|
fn num_blocks_test() {
|
||||||
assert_eq!(voc.checksum.value, 0x1129);
|
// Number of blocks
|
||||||
|
assert_eq!(VOC.blocks.len(), 5);
|
||||||
|
}
|
||||||
|
|
||||||
// Number of blocks
|
#[test]
|
||||||
assert_eq!(voc.blocks.len(), 5);
|
fn blocks_0_to_3_sound_data_test() {
|
||||||
|
// Sound data
|
||||||
// Sound data
|
for idx in 0..4 {
|
||||||
for idx in 0..4 {
|
if let BlockType::SoundData {
|
||||||
if let BlockType::SoundData { sample_rate, codec, data } = &voc.blocks[idx] {
|
sample_rate,
|
||||||
assert_eq!(sample_rate, &16129);
|
codec,
|
||||||
assert_eq!(codec, &Codec::Pcm8BitUnsigned);
|
data,
|
||||||
assert_eq!(data.len(), 202498);
|
} = &VOC.blocks[idx]
|
||||||
}
|
{
|
||||||
}
|
assert_eq!(sample_rate, &16129);
|
||||||
|
assert_eq!(codec, &Codec::Pcm8BitUnsigned);
|
||||||
// Terminator
|
assert_eq!(data.len(), 202498);
|
||||||
assert_eq!(&voc.blocks[4], &BlockType::Terminator);
|
|
||||||
}
|
|
||||||
Err(err) => {
|
|
||||||
println!("Error parsing VOC file: {:?}", err);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn block_4_terminator_test() {
|
||||||
|
// Repeat end
|
||||||
|
assert_eq!(&VOC.blocks[4], &BlockType::Terminator);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue