Skip to content

Commit 7b98be8

Browse files
committed
Improved tests.
1 parent 0320bc2 commit 7b98be8

File tree

5 files changed

+64
-2
lines changed

5 files changed

+64
-2
lines changed

src/semcheck/changes.rs

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ pub struct PathChange {
7777
additions: BTreeSet<Span>,
7878
/// The set of spans of removed exports of the item.
7979
removals: BTreeSet<Span>,
80-
// TODO: do we need an `output` member here as well?
8180
}
8281

8382
impl PathChange {
@@ -839,7 +838,54 @@ pub mod tests {
839838
set.max == max
840839
}
841840

842-
// TODO: a test for mixed change sets
841+
fn max_pchange_or_change(pchanges: Vec<PathChange_>, changes: Vec<Change_>) -> bool {
842+
let mut set = ChangeSet::default();
843+
844+
let mut interner = Interner::new();
845+
let name = interner.intern("test");
846+
847+
let max = pchanges
848+
.iter()
849+
.flat_map(|change| change.2.iter())
850+
.map(|&(c, _)| if c { TechnicallyBreaking } else { Breaking })
851+
.chain(changes
852+
.iter()
853+
.flat_map(|change| change.5.iter())
854+
.map(|&(ref type_, _)| type_.inner().to_category()))
855+
.max()
856+
.unwrap_or(Patch);
857+
858+
for &(ref did, ref span, ref spans) in &pchanges {
859+
let def_id = did.clone().inner();
860+
set.new_path_change(def_id, name, span.clone().inner());
861+
862+
for &(add, ref span) in spans {
863+
if add {
864+
set.add_path_addition(def_id, span.clone().inner());
865+
} else {
866+
set.add_path_removal(def_id, span.clone().inner());
867+
}
868+
}
869+
}
870+
871+
for &(ref o_def_id, ref n_def_id, ref o_span, ref n_span, out, ref sub) in &changes {
872+
let old_def_id = o_def_id.clone().inner();
873+
set.new_change(old_def_id,
874+
n_def_id.clone().inner(),
875+
name,
876+
o_span.clone().inner(),
877+
n_span.clone().inner(),
878+
out);
879+
880+
for &(ref type_, ref span_) in sub {
881+
set.add_change(type_.clone().inner(),
882+
old_def_id,
883+
span_.clone().map(|s| s.inner()));
884+
}
885+
}
886+
887+
set.max == max
888+
}
843889

844890
/// Difference in spans implies difference in `PathChange`s.
845891
fn pchange_span_neq(c1: PathChange_, c2: PathChange_) -> bool {

tests/cases/addition_path/new.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,7 @@ pub mod d {
1919
mod e {
2020

2121
}
22+
23+
mod f {
24+
pub use a::Abc;
25+
}

tests/cases/addition_path/old.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@ pub mod b {
99
pub mod c {
1010

1111
}
12+
13+
mod f {
14+
15+
}

tests/cases/removal_path/new.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@ pub mod b {
99
pub mod c {
1010

1111
}
12+
13+
mod d {
14+
15+
}

tests/cases/removal_path/old.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@ pub mod c {
1111
}
1212

1313
pub use self::a::Abc;
14+
15+
mod d {
16+
pub use a::Abc;
17+
}

0 commit comments

Comments
 (0)