mirror of
https://github.com/iluvcapra/bwavfile.git
synced 2026-01-02 09:50:44 +00:00
prettify code
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
|
||||
extern crate serde_json;
|
||||
use core::fmt::Debug;
|
||||
use serde_json::{Value, from_str};
|
||||
use serde_json::{from_str, Value};
|
||||
use std::fs::File;
|
||||
use std::io::Read;
|
||||
|
||||
@@ -13,43 +12,42 @@ use bwavfile::WaveReader;
|
||||
// as read by `WaveReader`.
|
||||
|
||||
// This is rickety but we're going with it
|
||||
fn assert_match_stream<T>(stream_key: &str,
|
||||
other: impl Fn(&mut WaveReader<File>) -> T)
|
||||
where T: PartialEq + Debug,
|
||||
T: Into<Value>
|
||||
{
|
||||
|
||||
fn assert_match_stream<T>(stream_key: &str, other: impl Fn(&mut WaveReader<File>) -> T)
|
||||
where
|
||||
T: PartialEq + Debug,
|
||||
T: Into<Value>,
|
||||
{
|
||||
let mut json_file = File::open("tests/ffprobe_media_tests.json").unwrap();
|
||||
let mut s = String::new();
|
||||
json_file.read_to_string(&mut s).unwrap();
|
||||
if let Value::Array(v) = from_str(&mut s).unwrap() { /* */
|
||||
if let Value::Array(v) = from_str(&mut s).unwrap() {
|
||||
/* */
|
||||
v.iter()
|
||||
.filter(|value| {
|
||||
!value["format"]["filename"].is_null()
|
||||
})
|
||||
.filter(|value| !value["format"]["filename"].is_null())
|
||||
.for_each(|value| {
|
||||
let filen : &str = value["format"]["filename"].as_str().unwrap();
|
||||
let json_value : &Value = &value["streams"][0][stream_key];
|
||||
let filen: &str = value["format"]["filename"].as_str().unwrap();
|
||||
let json_value: &Value = &value["streams"][0][stream_key];
|
||||
let mut wavfile = WaveReader::open_unbuffered(filen).unwrap();
|
||||
let wavfile_value: T = other(&mut wavfile);
|
||||
println!("asserting {} for {}",stream_key, filen);
|
||||
println!("asserting {} for {}", stream_key, filen);
|
||||
assert_eq!(Into::<Value>::into(wavfile_value), *json_value);
|
||||
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_frame_count() {
|
||||
assert_match_stream("duration_ts", |w| w.frame_length().unwrap() );
|
||||
fn test_frame_count() {
|
||||
assert_match_stream("duration_ts", |w| w.frame_length().unwrap());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_sample_rate() {
|
||||
assert_match_stream("sample_rate", |w| format!("{}", w.format().unwrap().sample_rate) );
|
||||
assert_match_stream("sample_rate", |w| {
|
||||
format!("{}", w.format().unwrap().sample_rate)
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_channel_count() {
|
||||
assert_match_stream("channels", |w| w.format().unwrap().channel_count );
|
||||
assert_match_stream("channels", |w| w.format().unwrap().channel_count);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user