Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 47 additions & 1 deletion library/core/tests/ops.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use core::ops::{Bound, Range, RangeFrom, RangeFull, RangeInclusive, RangeTo};
use core::ops::{Bound, Range, RangeFrom, RangeFull, RangeInclusive, RangeTo, RangeToInclusive};

// Test the Range structs and syntax.

Expand Down Expand Up @@ -59,6 +59,12 @@ fn test_range_inclusive() {
assert_eq!(r.next(), None);
}

#[test]
fn test_range_to_inclusive() {
// Not much to test.
let _ = RangeToInclusive { end: 42 };
}

#[test]
fn test_range_is_empty() {
assert!(!(0.0..10.0).is_empty());
Expand Down Expand Up @@ -151,3 +157,43 @@ fn test_range_syntax_in_return_statement() {
}
// Not much to test.
}

#[test]
fn range_structural_match() {
// test that all range types can be structurally matched upon

const RANGE: Range<usize> = 0..1000;
match RANGE {
RANGE => {}
_ => unreachable!(),
}

const RANGE_FROM: RangeFrom<usize> = 0..;
match RANGE_FROM {
RANGE_FROM => {}
_ => unreachable!(),
}

const RANGE_FULL: RangeFull = ..;
match RANGE_FULL {
RANGE_FULL => {}
}

const RANGE_INCLUSIVE: RangeInclusive<usize> = 0..=999;
match RANGE_INCLUSIVE {
RANGE_INCLUSIVE => {}
_ => unreachable!(),
}

const RANGE_TO: RangeTo<usize> = ..1000;
match RANGE_TO {
RANGE_TO => {}
_ => unreachable!(),
}

const RANGE_TO_INCLUSIVE: RangeToInclusive<usize> = ..=999;
match RANGE_TO_INCLUSIVE {
RANGE_TO_INCLUSIVE => {}
_ => unreachable!(),
}
}