Skip to content

Commit

Permalink
Check for overlapping and simplify unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Turner committed Sep 20, 2016
1 parent 2ea3ab3 commit e4b1842
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions src/libsyntax/codemap.rs
Expand Up @@ -392,8 +392,8 @@ impl CodeMap {
return None;
}

// ensure these follow the expected order
if sp_lhs.lo <= sp_rhs.lo {
// ensure these follow the expected order and we don't overlap
if (sp_lhs.lo <= sp_rhs.lo) && (sp_lhs.hi <= sp_rhs.lo) {
Some(Span {
lo: cmp::min(sp_lhs.lo, sp_rhs.lo),
hi: cmp::max(sp_lhs.hi, sp_rhs.hi),
Expand Down Expand Up @@ -1146,12 +1146,7 @@ mod tests {
let span1 = span_from_selection(inputtext, selection1);
let span2 = span_from_selection(inputtext, selection2);

if let Some(_) = cm.merge_spans(span1, span2) {
assert!(false);
}
else {
assert!(true);
}
assert!(cm.merge_spans(span1, span2).is_none());
}

/// Returns the span corresponding to the `n`th occurrence of
Expand Down

0 comments on commit e4b1842

Please sign in to comment.