]>
git.proxmox.com Git - rustc.git/blob - src/tools/compiletest/src/uidiff.rs
1 // Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 //! Code for checking whether the output of the compiler matches what is
14 pub fn diff_lines(actual
: &str, expected
: &str) -> Vec
<String
> {
15 // mega simplistic diff algorithm that just prints the things added/removed
16 zip_all(actual
.lines(), expected
.lines())
18 .filter_map(|(i
, (a
, e
))| {
20 (Some(a
), Some(e
)) => {
21 if lines_match(e
, a
) {
24 Some(format
!("{:3} - |{}|\n + |{}|\n", i
, e
, a
))
27 (Some(a
), None
) => Some(format
!("{:3} -\n + |{}|\n", i
, a
)),
28 (None
, Some(e
)) => Some(format
!("{:3} - |{}|\n +\n", i
, e
)),
29 (None
, None
) => panic
!("Cannot get here"),
35 fn lines_match(expected
: &str, mut actual
: &str) -> bool
{
36 for (i
, part
) in expected
.split("[..]").enumerate() {
37 match actual
.find(part
) {
42 actual
= &actual
[j
+ part
.len()..];
47 actual
.is_empty() || expected
.ends_with("[..]")
50 struct ZipAll
<I1
: Iterator
, I2
: Iterator
> {
55 impl<T
, I1
: Iterator
<Item
= T
>, I2
: Iterator
<Item
= T
>> Iterator
for ZipAll
<I1
, I2
> {
56 type Item
= (Option
<T
>, Option
<T
>);
57 fn next(&mut self) -> Option
<(Option
<T
>, Option
<T
>)> {
58 let first
= self.first
.next();
59 let second
= self.second
.next();
61 match (first
, second
) {
63 (a
, b
) => Some((a
, b
)),
68 fn zip_all
<T
, I1
: Iterator
<Item
= T
>, I2
: Iterator
<Item
= T
>>(a
: I1
, b
: I2
) -> ZipAll
<I1
, I2
> {