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.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "1.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.5.0"
|
||||
|
@ -28,5 +34,6 @@ dependencies = [
|
|||
name = "vocnom"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"lazy_static",
|
||||
"nom",
|
||||
]
|
||||
|
|
|
@ -7,3 +7,6 @@ edition = "2021"
|
|||
|
||||
[dependencies]
|
||||
nom = "7"
|
||||
|
||||
[dev-dependencies]
|
||||
lazy_static = "1.4.0"
|
||||
|
|
|
@ -1,23 +1,44 @@
|
|||
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]
|
||||
fn adoor2_test() {
|
||||
let input = include_bytes!("../assets/ADOOR2.VOC");
|
||||
|
||||
match parse_voc(input) {
|
||||
Ok((_, voc)) => {
|
||||
// Version
|
||||
assert_eq!((voc.version.major, voc.version.minor), (1, 20));
|
||||
fn version_test() {
|
||||
assert_eq!((VOC.version.major, VOC.version.minor), (1, 20));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn checksum_test() {
|
||||
// Checksum
|
||||
assert_eq!(voc.checksum.valid, true);
|
||||
assert_eq!(voc.checksum.value, 0x111f);
|
||||
assert_eq!(VOC.checksum.valid, true);
|
||||
assert_eq!(VOC.checksum.value, 0x111f);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn num_blocks_test() {
|
||||
// Number of blocks
|
||||
assert_eq!(voc.blocks.len(), 2);
|
||||
assert_eq!(VOC.blocks.len(), 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn block_0_sound_data_new_test() {
|
||||
// Sound data new
|
||||
if let BlockType::SoundDataNew { sample_rate, bits, channels, codec, reserved, data} = &voc.blocks[1] {
|
||||
if let BlockType::SoundDataNew {
|
||||
sample_rate,
|
||||
bits,
|
||||
channels,
|
||||
codec,
|
||||
reserved,
|
||||
data,
|
||||
} = &VOC.blocks[0]
|
||||
{
|
||||
assert_eq!(sample_rate, &11025);
|
||||
assert_eq!(bits, &8);
|
||||
assert_eq!(channels, &1);
|
||||
|
@ -25,12 +46,10 @@ fn adoor2_test() {
|
|||
assert_eq!(reserved, &0);
|
||||
assert_eq!(data.len(), 21394);
|
||||
}
|
||||
|
||||
// Terminator
|
||||
assert_eq!(&voc.blocks[1], &BlockType::Terminator);
|
||||
}
|
||||
Err(err) => {
|
||||
println!("Error parsing VOC file: {:?}", err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[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]
|
||||
fn conga_test() {
|
||||
let input = include_bytes!("../assets/CONGA.VOC");
|
||||
|
||||
match parse_voc(input) {
|
||||
Ok((_, voc)) => {
|
||||
// Version
|
||||
assert_eq!((voc.version.major, voc.version.minor), (1, 10));
|
||||
fn version_test() {
|
||||
assert_eq!((VOC.version.major, VOC.version.minor), (1, 10));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn checksum_test() {
|
||||
// Checksum
|
||||
assert_eq!(voc.checksum.valid, true);
|
||||
assert_eq!(voc.checksum.value, 0x1129);
|
||||
assert_eq!(VOC.checksum.valid, true);
|
||||
assert_eq!(VOC.checksum.value, 0x1129);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn num_blocks_test() {
|
||||
// Number of blocks
|
||||
assert_eq!(voc.blocks.len(), 8);
|
||||
assert_eq!(VOC.blocks.len(), 8);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn block_0_repeat_start_test() {
|
||||
// Repeat start
|
||||
if let BlockType::RepeatStart { count } = &voc.blocks[0] {
|
||||
if let BlockType::RepeatStart { count } = &VOC.blocks[0] {
|
||||
assert_eq!(count, &1);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn block_1_extra_information_test() {
|
||||
// Extra information
|
||||
if let BlockType::ExtraInformation { sample_rate, channels, codec} = &voc.blocks[1] {
|
||||
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] {
|
||||
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_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]
|
||||
fn edenmus_test() {
|
||||
let input = include_bytes!("../assets/EDEN.MUS");
|
||||
|
||||
match parse_voc(input) {
|
||||
Ok((_, voc)) => {
|
||||
// Version
|
||||
assert_eq!((voc.version.major, voc.version.minor), (1, 10));
|
||||
fn version_test() {
|
||||
assert_eq!((VOC.version.major, VOC.version.minor), (1, 10));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn checksum_test() {
|
||||
// Checksum
|
||||
assert_eq!(voc.checksum.valid, true);
|
||||
assert_eq!(voc.checksum.value, 0x1129);
|
||||
assert_eq!(VOC.checksum.valid, true);
|
||||
assert_eq!(VOC.checksum.value, 0x1129);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn num_blocks_test() {
|
||||
// Number of blocks
|
||||
assert_eq!(voc.blocks.len(), 3);
|
||||
assert_eq!(VOC.blocks.len(), 3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn block_0_text_test() {
|
||||
// Text block
|
||||
if let BlockType::Text { data} = &voc.blocks[0] {
|
||||
if let BlockType::Text { data } = &VOC.blocks[0] {
|
||||
assert_eq!(data.len(), 151);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn block_1_sound_data_test() {
|
||||
// Sound data
|
||||
if let BlockType::SoundData { sample_rate, codec, data} = &voc.blocks[1] {
|
||||
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_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]
|
||||
fn guardian_test() {
|
||||
let input = include_bytes!("../assets/GUARDIAN.VOC");
|
||||
|
||||
match parse_voc(input) {
|
||||
Ok((_, voc)) => {
|
||||
// Version
|
||||
assert_eq!((voc.version.major, voc.version.minor), (1, 10));
|
||||
fn version_test() {
|
||||
assert_eq!((VOC.version.major, VOC.version.minor), (1, 10));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn checksum_test() {
|
||||
// Checksum
|
||||
assert_eq!(voc.checksum.valid, true);
|
||||
assert_eq!(voc.checksum.value, 0x1129);
|
||||
assert_eq!(VOC.checksum.valid, true);
|
||||
assert_eq!(VOC.checksum.value, 0x1129);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn num_blocks_test() {
|
||||
// Number of blocks
|
||||
assert_eq!(voc.blocks.len(), 5);
|
||||
assert_eq!(VOC.blocks.len(), 5);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn blocks_0_to_3_sound_data_test() {
|
||||
// Sound data
|
||||
for idx in 0..4 {
|
||||
if let BlockType::SoundData { sample_rate, codec, data } = &voc.blocks[idx] {
|
||||
if let BlockType::SoundData {
|
||||
sample_rate,
|
||||
codec,
|
||||
data,
|
||||
} = &VOC.blocks[idx]
|
||||
{
|
||||
assert_eq!(sample_rate, &16129);
|
||||
assert_eq!(codec, &Codec::Pcm8BitUnsigned);
|
||||
assert_eq!(data.len(), 202498);
|
||||
}
|
||||
}
|
||||
|
||||
// Terminator
|
||||
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