1
0
Fork 0
mirror of https://github.com/sile/hls_m3u8.git synced 2024-05-18 00:12:54 +00:00

added tests

This commit is contained in:
Luro02 2019-09-06 13:46:21 +02:00
parent cb27640867
commit fe032ee984
6 changed files with 195 additions and 0 deletions

View file

@ -43,3 +43,50 @@ impl FromStr for ByteRange {
})
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_display() {
let byte_range = ByteRange {
length: 0,
start: Some(5),
};
assert_eq!(byte_range.to_string(), "0@5".to_string());
let byte_range = ByteRange {
length: 99999,
start: Some(2),
};
assert_eq!(byte_range.to_string(), "99999@2".to_string());
let byte_range = ByteRange {
length: 99999,
start: None,
};
assert_eq!(byte_range.to_string(), "99999".to_string());
}
#[test]
fn test_parse() {
let byte_range = ByteRange {
length: 99999,
start: Some(2),
};
assert_eq!(byte_range, "99999@2".parse::<ByteRange>().unwrap());
let byte_range = ByteRange {
length: 99999,
start: Some(2),
};
assert_eq!(byte_range, "99999@2".parse::<ByteRange>().unwrap());
let byte_range = ByteRange {
length: 99999,
start: None,
};
assert_eq!(byte_range, "99999".parse::<ByteRange>().unwrap());
}
}

View file

@ -34,3 +34,29 @@ impl FromStr for ClosedCaptions {
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_display() {
let closed_captions = ClosedCaptions::None;
assert_eq!(closed_captions.to_string(), "NONE".to_string());
let closed_captions = ClosedCaptions::GroupId(QuotedString::new("value").unwrap());
assert_eq!(closed_captions.to_string(), "\"value\"".to_string());
}
#[test]
fn test_parse() {
let closed_captions = ClosedCaptions::None;
assert_eq!(closed_captions, "NONE".parse::<ClosedCaptions>().unwrap());
let closed_captions = ClosedCaptions::GroupId(QuotedString::new("value").unwrap());
assert_eq!(
closed_captions,
"\"value\"".parse::<ClosedCaptions>().unwrap()
);
}
}

View file

@ -68,3 +68,32 @@ impl FromStr for DecimalFloatingPoint {
Ok(DecimalFloatingPoint(n))
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
pub fn test_display() {
let decimal_floating_point = DecimalFloatingPoint::new(22.0).unwrap();
assert_eq!(decimal_floating_point.to_string(), "22".to_string());
let decimal_floating_point = DecimalFloatingPoint::new(4.1).unwrap();
assert_eq!(decimal_floating_point.to_string(), "4.1".to_string());
}
#[test]
pub fn test_parse() {
let decimal_floating_point = DecimalFloatingPoint::new(22.0).unwrap();
assert_eq!(
decimal_floating_point,
"22".parse::<DecimalFloatingPoint>().unwrap()
);
let decimal_floating_point = DecimalFloatingPoint::new(4.1).unwrap();
assert_eq!(
decimal_floating_point,
"4.1".parse::<DecimalFloatingPoint>().unwrap()
);
}
}

View file

@ -35,3 +35,44 @@ impl FromStr for DecimalResolution {
})
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_display() {
let decimal_resolution = DecimalResolution {
width: 1920,
height: 1080,
};
assert_eq!(decimal_resolution.to_string(), "1920x1080".to_string());
let decimal_resolution = DecimalResolution {
width: 1280,
height: 720,
};
assert_eq!(decimal_resolution.to_string(), "1280x720".to_string());
}
#[test]
fn test_parse() {
let decimal_resolution = DecimalResolution {
width: 1920,
height: 1080,
};
assert_eq!(
decimal_resolution,
"1920x1080".parse::<DecimalResolution>().unwrap()
);
let decimal_resolution = DecimalResolution {
width: 1280,
height: 720,
};
assert_eq!(
decimal_resolution,
"1280x720".parse::<DecimalResolution>().unwrap()
);
}
}

View file

@ -37,3 +37,32 @@ impl FromStr for EncryptionMethod {
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_display() {
let encryption_method = EncryptionMethod::Aes128;
assert_eq!(encryption_method.to_string(), "AES-128".to_string());
let encryption_method = EncryptionMethod::SampleAes;
assert_eq!(encryption_method.to_string(), "SAMPLE-AES".to_string());
}
#[test]
fn test_parse() {
let encryption_method = EncryptionMethod::Aes128;
assert_eq!(
encryption_method,
"AES-128".parse::<EncryptionMethod>().unwrap()
);
let encryption_method = EncryptionMethod::SampleAes;
assert_eq!(
encryption_method,
"SAMPLE-AES".parse::<EncryptionMethod>().unwrap()
);
}
}

View file

@ -33,3 +33,26 @@ impl FromStr for HdcpLevel {
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_display() {
let level = HdcpLevel::Type0;
assert_eq!(level.to_string(), "TYPE-0".to_string());
let level = HdcpLevel::None;
assert_eq!(level.to_string(), "NONE".to_string());
}
#[test]
fn test_parse() {
let level = HdcpLevel::Type0;
assert_eq!(level, "TYPE-0".parse::<HdcpLevel>().unwrap());
let level = HdcpLevel::None;
assert_eq!(level, "NONE".parse::<HdcpLevel>().unwrap());
}
}