mirror of
https://github.com/storytold/effectcraft.git
synced 2026-11-11 15:22:05 +00:00
address review: reversed run ranges take the scan
This commit is contained in:
@@ -628,10 +628,10 @@ fn is_hanging_open(c: char) -> bool {
|
||||
matches!(c, '"' | '\'' | '\u{2018}' | '\u{201c}' | '(' | '\u{ab}')
|
||||
}
|
||||
|
||||
/// Whether each run starts at or after the end of the one before it (the runs of a document):
|
||||
/// the precondition of [`run_at`]'s bisection.
|
||||
/// Whether no run is reversed and each starts at or after the end of the one before it (the runs
|
||||
/// of a document): the precondition of [`run_at`]'s bisection.
|
||||
fn runs_ordered(runs: &[(Range<usize>, TextStyle)]) -> bool {
|
||||
runs.windows(2).all(|w| w[0].0.end <= w[1].0.start)
|
||||
runs.iter().all(|(r, _)| r.start <= r.end) && runs.windows(2).all(|w| w[0].0.end <= w[1].0.start)
|
||||
}
|
||||
|
||||
/// Style runs with whether they are [`runs_ordered`].
|
||||
|
||||
@@ -522,5 +522,12 @@ fn run_lookup_by_bisection_matches_the_scan() {
|
||||
assert_eq!(run_at(&overlapping, false, b), scan(&overlapping, b), "{b}");
|
||||
}
|
||||
assert_eq!(run_at(&overlapping, false, 6), 0);
|
||||
// A reversed range (20..0) among others is not ordered either, and takes the scan.
|
||||
#[allow(clippy::reversed_empty_ranges)]
|
||||
let reversed: Vec<(Range<usize>, TextStyle)> = vec![(0..10, st(10.0)), (20..0, st(20.0)), (5..15, st(30.0)), (15..20, st(40.0))];
|
||||
assert!(!runs_ordered(&reversed));
|
||||
for b in 0..30 {
|
||||
assert_eq!(run_at(&reversed, runs_ordered(&reversed), b), scan(&reversed, b), "{b}");
|
||||
}
|
||||
assert_eq!(run_at(&[], true, 5), 0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user