use super::*;
#[test]
fn no_range_header_returns_unsatisfiable() {
match parse_range_header("bytes=", 1000) {
RangeOutcome::Unsatisfiable => {}
other => panic!("expected Unsatisfiable, got {other:?}"),
}
}
#[test]
fn invalid_format_returns_unsatisfiable() {
match parse_range_header("invalid", 1000) {
RangeOutcome::NoRange => {}
other => panic!("expected NoRange, got {other:?}"),
}
}
#[test]
fn simple_range_returns_satisfiable() {
match parse_range_header("bytes=0-99", 1000) {
RangeOutcome::Satisfiable(start, end) => {
assert_eq!(start, 0);
assert_eq!(end, 99);
}
other => panic!("expected Satisfiable(0, 99), got {other:?}"),
}
}
#[test]
fn open_ended_range_returns_satisfiable() {
match parse_range_header("bytes=100-", 1000) {
RangeOutcome::Satisfiable(start, end) => {
assert_eq!(start, 100);
assert_eq!(end, 999);
}
other => panic!("expected Satisfiable(100, 999), got {other:?}"),
}
}
#[test]
fn suffix_range_returns_satisfiable() {
match parse_range_header("bytes=-100", 1000) {
RangeOutcome::Satisfiable(start, end) => {
assert_eq!(start, 900);
assert_eq!(end, 999);
}
other => panic!("expected Satisfiable(900, 999), got {other:?}"),
}
}
#[test]
fn suffix_range_longer_than_file_returns_full_range() {
match parse_range_header("bytes=-2000", 1000) {
RangeOutcome::Satisfiable(start, end) => {
assert_eq!(start, 0);
assert_eq!(end, 999);
}
other => panic!("expected Satisfiable(0, 999), got {other:?}"),
}
}
#[test]
fn end_overshooting_file_clamps_correctly() {
match parse_range_header("bytes=0-2000", 1000) {
RangeOutcome::Satisfiable(start, end) => {
assert_eq!(start, 0);
assert_eq!(end, 999);
}
other => panic!("expected Satisfiable(0, 999), got {other:?}"),
}
}
#[test]
fn start_at_file_boundary_returns_unsatisfiable() {
match parse_range_header("bytes=1000-", 1000) {
RangeOutcome::Unsatisfiable => {}
other => panic!("expected Unsatisfiable, got {other:?}"),
}
}
#[test]
fn start_beyond_file_returns_unsatisfiable() {
match parse_range_header("bytes=2000-3000", 1000) {
RangeOutcome::Unsatisfiable => {}
other => panic!("expected Unsatisfiable, got {other:?}"),
}
}
#[test]
fn end_before_start_returns_unsatisfiable() {
match parse_range_header("bytes=100-50", 1000) {
RangeOutcome::Unsatisfiable => {}
other => panic!("expected Unsatisfiable, got {other:?}"),
}
}
#[test]
fn multi_range_returns_multi_range_ignored() {
match parse_range_header("bytes=0-99,200-299", 1000) {
RangeOutcome::MultiRangeIgnored => {}
other => panic!("expected MultiRangeIgnored, got {other:?}"),
}
}
#[test]
fn zero_suffix_length_returns_unsatisfiable() {
match parse_range_header("bytes=-0", 1000) {
RangeOutcome::Unsatisfiable => {}
other => panic!("expected Unsatisfiable, got {other:?}"),
}
}
#[test]
fn if_range_valid_with_matching_etag() {
assert!(if_range_valid("\"abc123\"", "\"abc123\""));
}
#[test]
fn if_range_valid_with_mismatched_etag() {
assert!(!if_range_valid("\"abc123\"", "\"def456\""));
}
#[test]
fn if_range_valid_with_whitespace() {
assert!(if_range_valid(" \"abc123\" ", "\"abc123\""));
}