Vendor things
This commit is contained in:
parent
5deceec006
commit
977e3c17e5
19434 changed files with 10682014 additions and 0 deletions
1
third-party/vendor/pretty_assertions/.cargo-checksum.json
vendored
Normal file
1
third-party/vendor/pretty_assertions/.cargo-checksum.json
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
{"files":{"Cargo.lock":"82b613042345772f677258d6530e942a4ff34e7d31fe96bb504dab7d37441e3a","Cargo.toml":"cb01544b9fe71b7d344e566d73bc4332ab2c39bf6dca43d354b4b6372c4a6546","LICENSE-APACHE":"c6596eb7be8581c18be736c846fb9173b69eccf6ef94c5135893ec56bd92ba08","LICENSE-MIT":"8c9612877aacfa1b42f5e80b679e6c3c93a7ba2bb99dfaf6e87e200dca4b4e6c","README.md":"56382a8b5347e3be95c26c97806291aebf5cc321090b19b2ac7d680461d4add1","examples/pretty_assertion.png":"a9a43d098b548cd222056e8f7391cc071ccd07372e9c44d10e254c0a683c7562","examples/pretty_assertion.rs":"41d0527d286baebe09149e33a9359c3e30c7fbfddd41995db4facdee291fcd2c","examples/pretty_assertion_v0_6_1.png":"c07a7a8cd56ebeb840ae8095c024957ddac8a1d011288acf7928f79d85b39e3a","examples/standard_assertion.png":"be6f676deb51d06bcb33f36d194c82228d5585d91f58af590d9040012e38a0a8","examples/standard_assertion.rs":"70180f493795da15c82c0002c26249ef2a1b9fa81f6d0c9a8e0bf4e09121e041","src/lib.rs":"6cd82626ccbd1401ed660f92eedac20efae01e9f5c7a9a5ce3203b6d20465d28","src/printer.rs":"3ea14e1542a47c9909bc06a7b413262a6d86dfd22ca15b220d6f6ea48ad35c8e","tests/macros.rs":"cadb699c6d1bab26bb7ba044b1094fdc8a1f4f670d70dc38b7defea1a4dd41fb"},"package":"af7cee1a6c8a5b9208b3cb1061f10c0cb689087b3d8ce85fb9d2dd7a29b6ba66"}
|
||||
23
third-party/vendor/pretty_assertions/Cargo.lock
generated
vendored
Normal file
23
third-party/vendor/pretty_assertions/Cargo.lock
generated
vendored
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "diff"
|
||||
version = "0.1.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8"
|
||||
|
||||
[[package]]
|
||||
name = "pretty_assertions"
|
||||
version = "1.4.0"
|
||||
dependencies = [
|
||||
"diff",
|
||||
"yansi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "yansi"
|
||||
version = "0.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec"
|
||||
44
third-party/vendor/pretty_assertions/Cargo.toml
vendored
Normal file
44
third-party/vendor/pretty_assertions/Cargo.toml
vendored
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
|
||||
#
|
||||
# When uploading crates to the registry Cargo will automatically
|
||||
# "normalize" Cargo.toml files for maximal compatibility
|
||||
# with all versions of Cargo and also rewrite `path` dependencies
|
||||
# to registry (e.g., crates.io) dependencies.
|
||||
#
|
||||
# If you are reading this file be aware that the original Cargo.toml
|
||||
# will likely look very different (and much more reasonable).
|
||||
# See Cargo.toml.orig for the original contents.
|
||||
|
||||
[package]
|
||||
edition = "2018"
|
||||
name = "pretty_assertions"
|
||||
version = "1.4.0"
|
||||
authors = [
|
||||
"Colin Kiegel <kiegel@gmx.de>",
|
||||
"Florent Fayolle <florent.fayolle69@gmail.com>",
|
||||
"Tom Milligan <code@tommilligan.net>",
|
||||
]
|
||||
description = "Overwrite `assert_eq!` and `assert_ne!` with drop-in replacements, adding colorful diffs."
|
||||
documentation = "https://docs.rs/pretty_assertions"
|
||||
readme = "README.md"
|
||||
keywords = [
|
||||
"assert",
|
||||
"diff",
|
||||
"pretty",
|
||||
"color",
|
||||
]
|
||||
categories = ["development-tools"]
|
||||
license = "MIT OR Apache-2.0"
|
||||
repository = "https://github.com/rust-pretty-assertions/rust-pretty-assertions"
|
||||
|
||||
[dependencies.diff]
|
||||
version = "0.1.12"
|
||||
|
||||
[dependencies.yansi]
|
||||
version = "0.5"
|
||||
|
||||
[features]
|
||||
alloc = []
|
||||
default = ["std"]
|
||||
std = []
|
||||
unstable = []
|
||||
202
third-party/vendor/pretty_assertions/LICENSE-APACHE
vendored
Normal file
202
third-party/vendor/pretty_assertions/LICENSE-APACHE
vendored
Normal file
|
|
@ -0,0 +1,202 @@
|
|||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "{}"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright {yyyy} {name of copyright owner}
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
21
third-party/vendor/pretty_assertions/LICENSE-MIT
vendored
Normal file
21
third-party/vendor/pretty_assertions/LICENSE-MIT
vendored
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016 rust-derive-builder contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
115
third-party/vendor/pretty_assertions/README.md
vendored
Normal file
115
third-party/vendor/pretty_assertions/README.md
vendored
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
# Pretty Assertions
|
||||
|
||||
[](https://crates.io/crates/pretty-assertions)
|
||||
[](https://docs.rs/pretty_assertions)
|
||||
[](https://crates.io/crates/pretty-assertions)
|
||||
[](https://crates.io/crates/pretty-assertions)
|
||||
|
||||
Overwrite `assert_eq!` with a drop-in replacement, adding a colorful diff.
|
||||
|
||||
## Usage
|
||||
|
||||
When writing tests in Rust, you'll probably use `assert_eq!(a, b)` _a lot_.
|
||||
|
||||
If such a test fails, it will present all the details of `a` and `b`.
|
||||
But you have to spot the differences yourself, which is not always straightforward,
|
||||
like here:
|
||||
|
||||

|
||||
|
||||
Wouldn't that task be _much_ easier with a colorful diff?
|
||||
|
||||

|
||||
|
||||
Yep — and you only need **one line of code** to make it happen:
|
||||
|
||||
```rust,ignore
|
||||
use pretty_assertions::{assert_eq, assert_ne};
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>Show the example behind the screenshots above.</summary>
|
||||
|
||||
```rust,ignore
|
||||
// 1. add the `pretty_assertions` dependency to `Cargo.toml`.
|
||||
// 2. insert this line at the top of each module, as needed
|
||||
use pretty_assertions::{assert_eq, assert_ne};
|
||||
|
||||
fn main() {
|
||||
#[derive(Debug, PartialEq)]
|
||||
struct Foo {
|
||||
lorem: &'static str,
|
||||
ipsum: u32,
|
||||
dolor: Result<String, String>,
|
||||
}
|
||||
|
||||
let x = Some(Foo { lorem: "Hello World!", ipsum: 42, dolor: Ok("hey".to_string())});
|
||||
let y = Some(Foo { lorem: "Hello Wrold!", ipsum: 42, dolor: Ok("hey ho!".to_string())});
|
||||
|
||||
assert_eq!(x, y);
|
||||
}
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
## Semantic Versioning
|
||||
|
||||
The exact output of assertions is **not guaranteed** to be consistent over time, and may change between minor versions.
|
||||
The output of this crate is designed to be read by a human. It is not suitable for exact comparison, for example in snapshot testing.
|
||||
|
||||
This crate adheres to semantic versioning for publically exported crate items, **except** the `private` module, which may change between any version.
|
||||
|
||||
## Tip
|
||||
|
||||
Specify it as [`[dev-dependencies]`](http://doc.crates.io/specifying-dependencies.html#development-dependencies)
|
||||
and it will only be used for compiling tests, examples, and benchmarks.
|
||||
This way the compile time of `cargo build` won't be affected!
|
||||
|
||||
Also add `#[cfg(test)]` to your `use` statements, like this:
|
||||
|
||||
```rust,ignore
|
||||
#[cfg(test)]
|
||||
use pretty_assertions::{assert_eq, assert_ne};
|
||||
```
|
||||
|
||||
## Notes
|
||||
|
||||
- Since `Rust 2018` edition, you need to declare
|
||||
`use pretty_assertions::{assert_eq, assert_ne};` per module.
|
||||
Before you would write `#[macro_use] extern crate pretty_assertions;`.
|
||||
- The replacement is only effective in your own crate, not in other libraries
|
||||
you include.
|
||||
- `assert_ne` is also switched to multi-line presentation, but does _not_ show
|
||||
a diff.
|
||||
- Under Windows, the terminal state is modified to properly handle VT100
|
||||
escape sequences, which may break display for certain use cases.
|
||||
- The minimum supported rust version (MSRV) is 1.35.0
|
||||
|
||||
### `no_std` support
|
||||
|
||||
For `no_std` support, disable the `std` feature and enable the `alloc` feature:
|
||||
|
||||
```toml
|
||||
# Cargo.toml
|
||||
pretty_assertions = { version= "...", default-features = false, features = ["alloc"] }
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
Licensed under either of
|
||||
|
||||
- Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or <http://www.apache.org/licenses/LICENSE-2.0>)
|
||||
- MIT license ([LICENSE-MIT](LICENSE-MIT) or <http://opensource.org/licenses/MIT>)
|
||||
|
||||
at your option.
|
||||
|
||||
### Contribution
|
||||
|
||||
Unless you explicitly state otherwise, any contribution intentionally
|
||||
submitted for inclusion in the work by you, as defined in the Apache-2.0
|
||||
license, shall be dual licensed as above, without any additional terms or
|
||||
conditions.
|
||||
|
||||
## Development
|
||||
|
||||
- Cut a new release by creating a GitHub release with tag. Crate will be built and uploaded to crates.io by GHA.
|
||||
BIN
third-party/vendor/pretty_assertions/examples/pretty_assertion.png
vendored
Normal file
BIN
third-party/vendor/pretty_assertions/examples/pretty_assertion.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 21 KiB |
3
third-party/vendor/pretty_assertions/examples/pretty_assertion.rs
vendored
Normal file
3
third-party/vendor/pretty_assertions/examples/pretty_assertion.rs
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
use pretty_assertions::assert_eq;
|
||||
|
||||
include!("standard_assertion.rs");
|
||||
BIN
third-party/vendor/pretty_assertions/examples/pretty_assertion_v0_6_1.png
vendored
Normal file
BIN
third-party/vendor/pretty_assertions/examples/pretty_assertion_v0_6_1.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 21 KiB |
BIN
third-party/vendor/pretty_assertions/examples/standard_assertion.png
vendored
Normal file
BIN
third-party/vendor/pretty_assertions/examples/standard_assertion.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 21 KiB |
26
third-party/vendor/pretty_assertions/examples/standard_assertion.rs
vendored
Normal file
26
third-party/vendor/pretty_assertions/examples/standard_assertion.rs
vendored
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
#[derive(Debug, PartialEq)]
|
||||
struct Foo {
|
||||
lorem: &'static str,
|
||||
ipsum: u32,
|
||||
dolor: Result<String, String>,
|
||||
}
|
||||
|
||||
fn compare() {
|
||||
let x = Some(Foo {
|
||||
lorem: "Hello World!",
|
||||
ipsum: 42,
|
||||
dolor: Ok("hey".to_string()),
|
||||
});
|
||||
let y = Some(Foo {
|
||||
lorem: "Hello Wrold!",
|
||||
ipsum: 42,
|
||||
dolor: Ok("hey ho!".to_string()),
|
||||
});
|
||||
|
||||
assert_eq!(x, y);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let result = std::panic::catch_unwind(compare);
|
||||
assert!(result.is_err(), "example did not panic");
|
||||
}
|
||||
458
third-party/vendor/pretty_assertions/src/lib.rs
vendored
Normal file
458
third-party/vendor/pretty_assertions/src/lib.rs
vendored
Normal file
|
|
@ -0,0 +1,458 @@
|
|||
//! # Pretty Assertions
|
||||
//!
|
||||
//! When writing tests in Rust, you'll probably use `assert_eq!(a, b)` _a lot_.
|
||||
//!
|
||||
//! If such a test fails, it will present all the details of `a` and `b`.
|
||||
//! But you have to spot the differences yourself, which is not always straightforward,
|
||||
//! like here:
|
||||
//!
|
||||
//! 
|
||||
//!
|
||||
//! Wouldn't that task be _much_ easier with a colorful diff?
|
||||
//!
|
||||
//! 
|
||||
//!
|
||||
//! Yep — and you only need **one line of code** to make it happen:
|
||||
//!
|
||||
//! ```rust
|
||||
//! use pretty_assertions::{assert_eq, assert_ne};
|
||||
//! ```
|
||||
//!
|
||||
//! <details>
|
||||
//! <summary>Show the example behind the screenshots above.</summary>
|
||||
//!
|
||||
//! ```rust,should_panic
|
||||
//! // 1. add the `pretty_assertions` dependency to `Cargo.toml`.
|
||||
//! // 2. insert this line at the top of each module, as needed
|
||||
//! use pretty_assertions::{assert_eq, assert_ne};
|
||||
//!
|
||||
//! #[derive(Debug, PartialEq)]
|
||||
//! struct Foo {
|
||||
//! lorem: &'static str,
|
||||
//! ipsum: u32,
|
||||
//! dolor: Result<String, String>,
|
||||
//! }
|
||||
//!
|
||||
//! let x = Some(Foo { lorem: "Hello World!", ipsum: 42, dolor: Ok("hey".to_string())});
|
||||
//! let y = Some(Foo { lorem: "Hello Wrold!", ipsum: 42, dolor: Ok("hey ho!".to_string())});
|
||||
//!
|
||||
//! assert_eq!(x, y);
|
||||
//! ```
|
||||
//! </details>
|
||||
//!
|
||||
//! ## Tip
|
||||
//!
|
||||
//! Specify it as [`[dev-dependencies]`](http://doc.crates.io/specifying-dependencies.html#development-dependencies)
|
||||
//! and it will only be used for compiling tests, examples, and benchmarks.
|
||||
//! This way the compile time of `cargo build` won't be affected!
|
||||
//!
|
||||
//! Also add `#[cfg(test)]` to your `use` statements, like this:
|
||||
//!
|
||||
//! ```rust
|
||||
//! #[cfg(test)]
|
||||
//! use pretty_assertions::{assert_eq, assert_ne};
|
||||
//! ```
|
||||
//!
|
||||
//! ## Note
|
||||
//!
|
||||
//! * Since `Rust 2018` edition, you need to declare
|
||||
//! `use pretty_assertions::{assert_eq, assert_ne};` per module.
|
||||
//! Before you would write `#[macro_use] extern crate pretty_assertions;`.
|
||||
//! * The replacement is only effective in your own crate, not in other libraries
|
||||
//! you include.
|
||||
//! * `assert_ne` is also switched to multi-line presentation, but does _not_ show
|
||||
//! a diff.
|
||||
//!
|
||||
//! ## Features
|
||||
//!
|
||||
//! Features provided by the crate are:
|
||||
//!
|
||||
//! - `std`: Use the Rust standard library. Enabled by default.
|
||||
//! Exactly one of `std` and `alloc` is required.
|
||||
//! - `alloc`: Use the `alloc` crate.
|
||||
//! Exactly one of `std` and `alloc` is required.
|
||||
//! - `unstable`: opt-in to unstable features that may not follow Semantic Versioning.
|
||||
//! The implementation behind this feature is subject to change without warning between patch versions.
|
||||
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
#![deny(clippy::all, missing_docs, unsafe_code)]
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
#[macro_use]
|
||||
extern crate alloc;
|
||||
use core::fmt::{self, Debug, Display};
|
||||
|
||||
mod printer;
|
||||
|
||||
/// A comparison of two values.
|
||||
///
|
||||
/// Where both values implement `Debug`, the comparison can be displayed as a pretty diff.
|
||||
///
|
||||
/// ```
|
||||
/// use pretty_assertions::Comparison;
|
||||
///
|
||||
/// print!("{}", Comparison::new(&123, &134));
|
||||
/// ```
|
||||
///
|
||||
/// The values may have different types, although in practice they are usually the same.
|
||||
pub struct Comparison<'a, TLeft, TRight>
|
||||
where
|
||||
TLeft: ?Sized,
|
||||
TRight: ?Sized,
|
||||
{
|
||||
left: &'a TLeft,
|
||||
right: &'a TRight,
|
||||
}
|
||||
|
||||
impl<'a, TLeft, TRight> Comparison<'a, TLeft, TRight>
|
||||
where
|
||||
TLeft: ?Sized,
|
||||
TRight: ?Sized,
|
||||
{
|
||||
/// Store two values to be compared in future.
|
||||
///
|
||||
/// Expensive diffing is deferred until calling `Debug::fmt`.
|
||||
pub fn new(left: &'a TLeft, right: &'a TRight) -> Comparison<'a, TLeft, TRight> {
|
||||
Comparison { left, right }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, TLeft, TRight> Display for Comparison<'a, TLeft, TRight>
|
||||
where
|
||||
TLeft: Debug + ?Sized,
|
||||
TRight: Debug + ?Sized,
|
||||
{
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
// To diff arbitary types, render them as debug strings
|
||||
let left_debug = format!("{:#?}", self.left);
|
||||
let right_debug = format!("{:#?}", self.right);
|
||||
// And then diff the debug output
|
||||
printer::write_header(f)?;
|
||||
printer::write_lines(f, &left_debug, &right_debug)
|
||||
}
|
||||
}
|
||||
|
||||
/// A comparison of two strings.
|
||||
///
|
||||
/// In contrast to [`Comparison`], which uses the [`core::fmt::Debug`] representation,
|
||||
/// `StrComparison` uses the string values directly, resulting in multi-line output for multiline strings.
|
||||
///
|
||||
/// ```
|
||||
/// use pretty_assertions::StrComparison;
|
||||
///
|
||||
/// print!("{}", StrComparison::new("foo\nbar", "foo\nbaz"));
|
||||
/// ```
|
||||
///
|
||||
/// ## Value type bounds
|
||||
///
|
||||
/// Any value that can be referenced as a [`str`] via [`AsRef`] may be used:
|
||||
///
|
||||
/// ```
|
||||
/// use pretty_assertions::StrComparison;
|
||||
///
|
||||
/// #[derive(PartialEq)]
|
||||
/// struct MyString(String);
|
||||
///
|
||||
/// impl AsRef<str> for MyString {
|
||||
/// fn as_ref(&self) -> &str {
|
||||
/// &self.0
|
||||
/// }
|
||||
/// }
|
||||
///
|
||||
/// print!(
|
||||
/// "{}",
|
||||
/// StrComparison::new(
|
||||
/// &MyString("foo\nbar".to_owned()),
|
||||
/// &MyString("foo\nbaz".to_owned()),
|
||||
/// ),
|
||||
/// );
|
||||
/// ```
|
||||
///
|
||||
/// The values may have different types, although in practice they are usually the same.
|
||||
pub struct StrComparison<'a, TLeft, TRight>
|
||||
where
|
||||
TLeft: ?Sized,
|
||||
TRight: ?Sized,
|
||||
{
|
||||
left: &'a TLeft,
|
||||
right: &'a TRight,
|
||||
}
|
||||
|
||||
impl<'a, TLeft, TRight> StrComparison<'a, TLeft, TRight>
|
||||
where
|
||||
TLeft: AsRef<str> + ?Sized,
|
||||
TRight: AsRef<str> + ?Sized,
|
||||
{
|
||||
/// Store two values to be compared in future.
|
||||
///
|
||||
/// Expensive diffing is deferred until calling `Debug::fmt`.
|
||||
pub fn new(left: &'a TLeft, right: &'a TRight) -> StrComparison<'a, TLeft, TRight> {
|
||||
StrComparison { left, right }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, TLeft, TRight> Display for StrComparison<'a, TLeft, TRight>
|
||||
where
|
||||
TLeft: AsRef<str> + ?Sized,
|
||||
TRight: AsRef<str> + ?Sized,
|
||||
{
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
printer::write_header(f)?;
|
||||
printer::write_lines(f, self.left.as_ref(), self.right.as_ref())
|
||||
}
|
||||
}
|
||||
|
||||
/// Asserts that two expressions are equal to each other (using [`PartialEq`]).
|
||||
///
|
||||
/// On panic, this macro will print a diff derived from [`Debug`] representation of
|
||||
/// each value.
|
||||
///
|
||||
/// This is a drop in replacement for [`core::assert_eq!`].
|
||||
/// You can provide a custom panic message if desired.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use pretty_assertions::assert_eq;
|
||||
///
|
||||
/// let a = 3;
|
||||
/// let b = 1 + 2;
|
||||
/// assert_eq!(a, b);
|
||||
///
|
||||
/// assert_eq!(a, b, "we are testing addition with {} and {}", a, b);
|
||||
/// ```
|
||||
#[macro_export]
|
||||
macro_rules! assert_eq {
|
||||
($left:expr, $right:expr$(,)?) => ({
|
||||
$crate::assert_eq!(@ $left, $right, "", "");
|
||||
});
|
||||
($left:expr, $right:expr, $($arg:tt)*) => ({
|
||||
$crate::assert_eq!(@ $left, $right, ": ", $($arg)+);
|
||||
});
|
||||
(@ $left:expr, $right:expr, $maybe_colon:expr, $($arg:tt)*) => ({
|
||||
match (&($left), &($right)) {
|
||||
(left_val, right_val) => {
|
||||
if !(*left_val == *right_val) {
|
||||
use $crate::private::CreateComparison;
|
||||
::core::panic!("assertion failed: `(left == right)`{}{}\
|
||||
\n\
|
||||
\n{}\
|
||||
\n",
|
||||
$maybe_colon,
|
||||
format_args!($($arg)*),
|
||||
(left_val, right_val).create_comparison()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// Asserts that two expressions are equal to each other (using [`PartialEq`]).
|
||||
///
|
||||
/// On panic, this macro will print a diff derived from each value's [`str`] representation.
|
||||
/// See [`StrComparison`] for further details.
|
||||
///
|
||||
/// This is a drop in replacement for [`core::assert_eq!`].
|
||||
/// You can provide a custom panic message if desired.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use pretty_assertions::assert_str_eq;
|
||||
///
|
||||
/// let a = "foo\nbar";
|
||||
/// let b = ["foo", "bar"].join("\n");
|
||||
/// assert_str_eq!(a, b);
|
||||
///
|
||||
/// assert_str_eq!(a, b, "we are testing concatenation with {} and {}", a, b);
|
||||
/// ```
|
||||
#[macro_export]
|
||||
macro_rules! assert_str_eq {
|
||||
($left:expr, $right:expr$(,)?) => ({
|
||||
$crate::assert_str_eq!(@ $left, $right, "", "");
|
||||
});
|
||||
($left:expr, $right:expr, $($arg:tt)*) => ({
|
||||
$crate::assert_str_eq!(@ $left, $right, ": ", $($arg)+);
|
||||
});
|
||||
(@ $left:expr, $right:expr, $maybe_colon:expr, $($arg:tt)*) => ({
|
||||
match (&($left), &($right)) {
|
||||
(left_val, right_val) => {
|
||||
if !(*left_val == *right_val) {
|
||||
::core::panic!("assertion failed: `(left == right)`{}{}\
|
||||
\n\
|
||||
\n{}\
|
||||
\n",
|
||||
$maybe_colon,
|
||||
format_args!($($arg)*),
|
||||
$crate::StrComparison::new(left_val, right_val)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// Asserts that two expressions are not equal to each other (using [`PartialEq`]).
|
||||
///
|
||||
/// On panic, this macro will print the values of the expressions with their
|
||||
/// [`Debug`] representations.
|
||||
///
|
||||
/// This is a drop in replacement for [`core::assert_ne!`].
|
||||
/// You can provide a custom panic message if desired.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use pretty_assertions::assert_ne;
|
||||
///
|
||||
/// let a = 3;
|
||||
/// let b = 2;
|
||||
/// assert_ne!(a, b);
|
||||
///
|
||||
/// assert_ne!(a, b, "we are testing that the values are not equal");
|
||||
/// ```
|
||||
#[macro_export]
|
||||
macro_rules! assert_ne {
|
||||
($left:expr, $right:expr$(,)?) => ({
|
||||
$crate::assert_ne!(@ $left, $right, "", "");
|
||||
});
|
||||
($left:expr, $right:expr, $($arg:tt)+) => ({
|
||||
$crate::assert_ne!(@ $left, $right, ": ", $($arg)+);
|
||||
});
|
||||
(@ $left:expr, $right:expr, $maybe_colon:expr, $($arg:tt)+) => ({
|
||||
match (&($left), &($right)) {
|
||||
(left_val, right_val) => {
|
||||
if *left_val == *right_val {
|
||||
::core::panic!("assertion failed: `(left != right)`{}{}\
|
||||
\n\
|
||||
\nBoth sides:\
|
||||
\n{:#?}\
|
||||
\n\
|
||||
\n",
|
||||
$maybe_colon,
|
||||
format_args!($($arg)+),
|
||||
left_val
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// Asserts that a value matches a pattern.
|
||||
///
|
||||
/// On panic, this macro will print a diff derived from [`Debug`] representation of
|
||||
/// the value, and a string representation of the pattern.
|
||||
///
|
||||
/// This is a drop in replacement for [`core::assert_matches::assert_matches!`].
|
||||
/// You can provide a custom panic message if desired.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use pretty_assertions::assert_matches;
|
||||
///
|
||||
/// let a = Some(3);
|
||||
/// assert_matches!(a, Some(_));
|
||||
///
|
||||
/// assert_matches!(a, Some(value) if value > 2, "we are testing {:?} with a pattern", a);
|
||||
/// ```
|
||||
///
|
||||
/// # Features
|
||||
///
|
||||
/// Requires the `unstable` feature to be enabled.
|
||||
///
|
||||
/// **Please note:** implementation under the `unstable` feature may be changed between
|
||||
/// patch versions without warning.
|
||||
#[cfg(feature = "unstable")]
|
||||
#[macro_export]
|
||||
macro_rules! assert_matches {
|
||||
($left:expr, $( $pattern:pat )|+ $( if $guard: expr )? $(,)?) => ({
|
||||
match $left {
|
||||
$( $pattern )|+ $( if $guard )? => {}
|
||||
ref left_val => {
|
||||
$crate::assert_matches!(
|
||||
@
|
||||
left_val,
|
||||
::core::stringify!($($pattern)|+ $(if $guard)?),
|
||||
"",
|
||||
""
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
($left:expr, $( $pattern:pat )|+ $( if $guard: expr )?, $($arg:tt)+) => ({
|
||||
match $left {
|
||||
$( $pattern )|+ $( if $guard )? => {}
|
||||
ref left_val => {
|
||||
$crate::assert_matches!(
|
||||
@
|
||||
left_val,
|
||||
::core::stringify!($($pattern)|+ $(if $guard)?),
|
||||
": ",
|
||||
$($arg)+
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
(@ $left:expr, $right:expr, $maybe_colon:expr, $($arg:tt)*) => ({
|
||||
match (&($left), &($right)) {
|
||||
(left_val, right_val) => {
|
||||
// Use the Display implementation to display the pattern,
|
||||
// as using Debug would add another layer of quotes to the output.
|
||||
struct Pattern<'a>(&'a str);
|
||||
impl ::core::fmt::Debug for Pattern<'_> {
|
||||
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
|
||||
::core::fmt::Display::fmt(self.0, f)
|
||||
}
|
||||
}
|
||||
|
||||
::core::panic!("assertion failed: `(left matches right)`{}{}\
|
||||
\n\
|
||||
\n{}\
|
||||
\n",
|
||||
$maybe_colon,
|
||||
format_args!($($arg)*),
|
||||
$crate::Comparison::new(left_val, &Pattern(right_val))
|
||||
)
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Not public API. Used by the expansion of this crate's assert macros.
|
||||
#[doc(hidden)]
|
||||
pub mod private {
|
||||
#[cfg(feature = "alloc")]
|
||||
use alloc::string::String;
|
||||
|
||||
pub trait CompareAsStrByDefault: AsRef<str> {}
|
||||
impl CompareAsStrByDefault for str {}
|
||||
impl CompareAsStrByDefault for String {}
|
||||
impl<T: CompareAsStrByDefault + ?Sized> CompareAsStrByDefault for &T {}
|
||||
|
||||
pub trait CreateComparison {
|
||||
type Comparison;
|
||||
fn create_comparison(self) -> Self::Comparison;
|
||||
}
|
||||
|
||||
impl<'a, T, U> CreateComparison for &'a (T, U) {
|
||||
type Comparison = crate::Comparison<'a, T, U>;
|
||||
fn create_comparison(self) -> Self::Comparison {
|
||||
crate::Comparison::new(&self.0, &self.1)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T, U> CreateComparison for (&'a T, &'a U)
|
||||
where
|
||||
T: CompareAsStrByDefault + ?Sized,
|
||||
U: CompareAsStrByDefault + ?Sized,
|
||||
{
|
||||
type Comparison = crate::StrComparison<'a, T, U>;
|
||||
fn create_comparison(self) -> Self::Comparison {
|
||||
crate::StrComparison::new(self.0, self.1)
|
||||
}
|
||||
}
|
||||
}
|
||||
600
third-party/vendor/pretty_assertions/src/printer.rs
vendored
Normal file
600
third-party/vendor/pretty_assertions/src/printer.rs
vendored
Normal file
|
|
@ -0,0 +1,600 @@
|
|||
#[cfg(feature = "alloc")]
|
||||
use alloc::format;
|
||||
use core::fmt;
|
||||
use yansi::{
|
||||
Color::{Fixed, Green, Red, Unset},
|
||||
Style,
|
||||
};
|
||||
|
||||
macro_rules! paint {
|
||||
($f:expr, $colour:expr, $fmt:expr, $($args:tt)*) => (
|
||||
write!($f, "{}", $colour.paint(format!($fmt, $($args)*)))
|
||||
)
|
||||
}
|
||||
|
||||
const SIGN_RIGHT: char = '>'; // + > →
|
||||
const SIGN_LEFT: char = '<'; // - < ←
|
||||
|
||||
/// Present the diff output for two mutliline strings in a pretty, colorised manner.
|
||||
pub(crate) fn write_header(f: &mut fmt::Formatter) -> fmt::Result {
|
||||
writeln!(
|
||||
f,
|
||||
"{} {} / {} :",
|
||||
Style::new(Unset).bold().paint("Diff"),
|
||||
Red.paint(format!("{} left", SIGN_LEFT)),
|
||||
Green.paint(format!("right {}", SIGN_RIGHT))
|
||||
)
|
||||
}
|
||||
|
||||
/// Delay formatting this deleted chunk until later.
|
||||
///
|
||||
/// It can be formatted as a whole chunk by calling `flush`, or the inner value
|
||||
/// obtained with `take` for further processing (such as an inline diff).
|
||||
#[derive(Default)]
|
||||
struct LatentDeletion<'a> {
|
||||
// The most recent deleted line we've seen
|
||||
value: Option<&'a str>,
|
||||
// The number of deleted lines we've seen, including the current value
|
||||
count: usize,
|
||||
}
|
||||
|
||||
impl<'a> LatentDeletion<'a> {
|
||||
/// Set the chunk value.
|
||||
fn set(&mut self, value: &'a str) {
|
||||
self.value = Some(value);
|
||||
self.count += 1;
|
||||
}
|
||||
|
||||
/// Take the underlying chunk value, if it's suitable for inline diffing.
|
||||
///
|
||||
/// If there is no value or we've seen more than one line, return `None`.
|
||||
fn take(&mut self) -> Option<&'a str> {
|
||||
if self.count == 1 {
|
||||
self.value.take()
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
/// If a value is set, print it as a whole chunk, using the given formatter.
|
||||
///
|
||||
/// If a value is not set, reset the count to zero (as we've called `flush` twice,
|
||||
/// without seeing another deletion. Therefore the line in the middle was something else).
|
||||
fn flush<TWrite: fmt::Write>(&mut self, f: &mut TWrite) -> fmt::Result {
|
||||
if let Some(value) = self.value {
|
||||
paint!(f, Red, "{}{}", SIGN_LEFT, value)?;
|
||||
writeln!(f)?;
|
||||
self.value = None;
|
||||
} else {
|
||||
self.count = 0;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
// Adapted from:
|
||||
// https://github.com/johannhof/difference.rs/blob/c5749ad7d82aa3d480c15cb61af9f6baa08f116f/examples/github-style.rs
|
||||
// Credits johannhof (MIT License)
|
||||
|
||||
/// Present the diff output for two mutliline strings in a pretty, colorised manner.
|
||||
pub(crate) fn write_lines<TWrite: fmt::Write>(
|
||||
f: &mut TWrite,
|
||||
left: &str,
|
||||
right: &str,
|
||||
) -> fmt::Result {
|
||||
let diff = ::diff::lines(left, right);
|
||||
|
||||
let mut changes = diff.into_iter().peekable();
|
||||
let mut previous_deletion = LatentDeletion::default();
|
||||
|
||||
while let Some(change) = changes.next() {
|
||||
match (change, changes.peek()) {
|
||||
// If the text is unchanged, just print it plain
|
||||
(::diff::Result::Both(value, _), _) => {
|
||||
previous_deletion.flush(f)?;
|
||||
writeln!(f, " {}", value)?;
|
||||
}
|
||||
// Defer any deletions to next loop
|
||||
(::diff::Result::Left(deleted), _) => {
|
||||
previous_deletion.flush(f)?;
|
||||
previous_deletion.set(deleted);
|
||||
}
|
||||
// If we're being followed by more insertions, don't inline diff
|
||||
(::diff::Result::Right(inserted), Some(::diff::Result::Right(_))) => {
|
||||
previous_deletion.flush(f)?;
|
||||
paint!(f, Green, "{}{}", SIGN_RIGHT, inserted)?;
|
||||
writeln!(f)?;
|
||||
}
|
||||
// Otherwise, check if we need to inline diff with the previous line (if it was a deletion)
|
||||
(::diff::Result::Right(inserted), _) => {
|
||||
if let Some(deleted) = previous_deletion.take() {
|
||||
write_inline_diff(f, deleted, inserted)?;
|
||||
} else {
|
||||
previous_deletion.flush(f)?;
|
||||
paint!(f, Green, "{}{}", SIGN_RIGHT, inserted)?;
|
||||
writeln!(f)?;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
previous_deletion.flush(f)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Group character styling for an inline diff, to prevent wrapping each single
|
||||
/// character in terminal styling codes.
|
||||
///
|
||||
/// Styles are applied automatically each time a new style is given in `write_with_style`.
|
||||
struct InlineWriter<'a, Writer> {
|
||||
f: &'a mut Writer,
|
||||
style: Style,
|
||||
}
|
||||
|
||||
impl<'a, Writer> InlineWriter<'a, Writer>
|
||||
where
|
||||
Writer: fmt::Write,
|
||||
{
|
||||
fn new(f: &'a mut Writer) -> Self {
|
||||
InlineWriter {
|
||||
f,
|
||||
style: Style::new(Unset),
|
||||
}
|
||||
}
|
||||
|
||||
/// Push a new character into the buffer, specifying the style it should be written in.
|
||||
fn write_with_style(&mut self, c: &char, style: Style) -> fmt::Result {
|
||||
// If the style is the same as previously, just write character
|
||||
if style == self.style {
|
||||
write!(self.f, "{}", c)?;
|
||||
} else {
|
||||
// Close out previous style
|
||||
self.style.fmt_suffix(self.f)?;
|
||||
|
||||
// Store new style and start writing it
|
||||
style.fmt_prefix(self.f)?;
|
||||
write!(self.f, "{}", c)?;
|
||||
self.style = style;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Finish any existing style and reset to default state.
|
||||
fn finish(&mut self) -> fmt::Result {
|
||||
// Close out previous style
|
||||
self.style.fmt_suffix(self.f)?;
|
||||
writeln!(self.f)?;
|
||||
self.style = Style::new(Unset);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// Format a single line to show an inline diff of the two strings given.
|
||||
///
|
||||
/// The given strings should not have a trailing newline.
|
||||
///
|
||||
/// The output of this function will be two lines, each with a trailing newline.
|
||||
fn write_inline_diff<TWrite: fmt::Write>(f: &mut TWrite, left: &str, right: &str) -> fmt::Result {
|
||||
let diff = ::diff::chars(left, right);
|
||||
let mut writer = InlineWriter::new(f);
|
||||
|
||||
// Print the left string on one line, with differences highlighted
|
||||
let light = Style::new(Red);
|
||||
let heavy = Style::new(Red).bg(Fixed(52)).bold();
|
||||
writer.write_with_style(&SIGN_LEFT, light)?;
|
||||
for change in diff.iter() {
|
||||
match change {
|
||||
::diff::Result::Both(value, _) => writer.write_with_style(value, light)?,
|
||||
::diff::Result::Left(value) => writer.write_with_style(value, heavy)?,
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
writer.finish()?;
|
||||
|
||||
// Print the right string on one line, with differences highlighted
|
||||
let light = Style::new(Green);
|
||||
let heavy = Style::new(Green).bg(Fixed(22)).bold();
|
||||
writer.write_with_style(&SIGN_RIGHT, light)?;
|
||||
for change in diff.iter() {
|
||||
match change {
|
||||
::diff::Result::Both(value, _) => writer.write_with_style(value, light)?,
|
||||
::diff::Result::Right(value) => writer.write_with_style(value, heavy)?,
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
writer.finish()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
use alloc::string::String;
|
||||
|
||||
// ANSI terminal codes used in our outputs.
|
||||
//
|
||||
// Interpolate these into test strings to make expected values easier to read.
|
||||
const RED_LIGHT: &str = "\u{1b}[31m";
|
||||
const GREEN_LIGHT: &str = "\u{1b}[32m";
|
||||
const RED_HEAVY: &str = "\u{1b}[1;48;5;52;31m";
|
||||
const GREEN_HEAVY: &str = "\u{1b}[1;48;5;22;32m";
|
||||
const RESET: &str = "\u{1b}[0m";
|
||||
|
||||
/// Given that both of our diff printing functions have the same
|
||||
/// type signature, we can reuse the same test code for them.
|
||||
///
|
||||
/// This could probably be nicer with traits!
|
||||
fn check_printer<TPrint>(printer: TPrint, left: &str, right: &str, expected: &str)
|
||||
where
|
||||
TPrint: Fn(&mut String, &str, &str) -> fmt::Result,
|
||||
{
|
||||
let mut actual = String::new();
|
||||
printer(&mut actual, left, right).expect("printer function failed");
|
||||
|
||||
// Cannot use IO without stdlib
|
||||
#[cfg(feature = "std")]
|
||||
println!(
|
||||
"## left ##\n\
|
||||
{}\n\
|
||||
## right ##\n\
|
||||
{}\n\
|
||||
## actual diff ##\n\
|
||||
{}\n\
|
||||
## expected diff ##\n\
|
||||
{}",
|
||||
left, right, actual, expected
|
||||
);
|
||||
assert_eq!(actual, expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn write_inline_diff_empty() {
|
||||
let left = "";
|
||||
let right = "";
|
||||
let expected = format!(
|
||||
"{red_light}<{reset}\n\
|
||||
{green_light}>{reset}\n",
|
||||
red_light = RED_LIGHT,
|
||||
green_light = GREEN_LIGHT,
|
||||
reset = RESET,
|
||||
);
|
||||
|
||||
check_printer(write_inline_diff, left, right, &expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn write_inline_diff_added() {
|
||||
let left = "";
|
||||
let right = "polymerase";
|
||||
let expected = format!(
|
||||
"{red_light}<{reset}\n\
|
||||
{green_light}>{reset}{green_heavy}polymerase{reset}\n",
|
||||
red_light = RED_LIGHT,
|
||||
green_light = GREEN_LIGHT,
|
||||
green_heavy = GREEN_HEAVY,
|
||||
reset = RESET,
|
||||
);
|
||||
|
||||
check_printer(write_inline_diff, left, right, &expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn write_inline_diff_removed() {
|
||||
let left = "polyacrylamide";
|
||||
let right = "";
|
||||
let expected = format!(
|
||||
"{red_light}<{reset}{red_heavy}polyacrylamide{reset}\n\
|
||||
{green_light}>{reset}\n",
|
||||
red_light = RED_LIGHT,
|
||||
green_light = GREEN_LIGHT,
|
||||
red_heavy = RED_HEAVY,
|
||||
reset = RESET,
|
||||
);
|
||||
|
||||
check_printer(write_inline_diff, left, right, &expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn write_inline_diff_changed() {
|
||||
let left = "polymerase";
|
||||
let right = "polyacrylamide";
|
||||
let expected = format!(
|
||||
"{red_light}<poly{reset}{red_heavy}me{reset}{red_light}ra{reset}{red_heavy}s{reset}{red_light}e{reset}\n\
|
||||
{green_light}>poly{reset}{green_heavy}ac{reset}{green_light}r{reset}{green_heavy}yl{reset}{green_light}a{reset}{green_heavy}mid{reset}{green_light}e{reset}\n",
|
||||
red_light = RED_LIGHT,
|
||||
green_light = GREEN_LIGHT,
|
||||
red_heavy = RED_HEAVY,
|
||||
green_heavy = GREEN_HEAVY,
|
||||
reset = RESET,
|
||||
);
|
||||
|
||||
check_printer(write_inline_diff, left, right, &expected);
|
||||
}
|
||||
|
||||
/// If one of our strings is empty, it should not be shown at all in the output.
|
||||
#[test]
|
||||
fn write_lines_empty_string() {
|
||||
let left = "";
|
||||
let right = "content";
|
||||
let expected = format!(
|
||||
"{green_light}>content{reset}\n",
|
||||
green_light = GREEN_LIGHT,
|
||||
reset = RESET,
|
||||
);
|
||||
|
||||
check_printer(write_lines, left, right, &expected);
|
||||
}
|
||||
|
||||
/// Realistic multiline struct diffing case.
|
||||
#[test]
|
||||
fn write_lines_struct() {
|
||||
let left = r#"Some(
|
||||
Foo {
|
||||
lorem: "Hello World!",
|
||||
ipsum: 42,
|
||||
dolor: Ok(
|
||||
"hey",
|
||||
),
|
||||
},
|
||||
)"#;
|
||||
let right = r#"Some(
|
||||
Foo {
|
||||
lorem: "Hello Wrold!",
|
||||
ipsum: 42,
|
||||
dolor: Ok(
|
||||
"hey ho!",
|
||||
),
|
||||
},
|
||||
)"#;
|
||||
let expected = format!(
|
||||
r#" Some(
|
||||
Foo {{
|
||||
{red_light}< lorem: "Hello W{reset}{red_heavy}o{reset}{red_light}rld!",{reset}
|
||||
{green_light}> lorem: "Hello Wr{reset}{green_heavy}o{reset}{green_light}ld!",{reset}
|
||||
ipsum: 42,
|
||||
dolor: Ok(
|
||||
{red_light}< "hey",{reset}
|
||||
{green_light}> "hey{reset}{green_heavy} ho!{reset}{green_light}",{reset}
|
||||
),
|
||||
}},
|
||||
)
|
||||
"#,
|
||||
red_light = RED_LIGHT,
|
||||
red_heavy = RED_HEAVY,
|
||||
green_light = GREEN_LIGHT,
|
||||
green_heavy = GREEN_HEAVY,
|
||||
reset = RESET,
|
||||
);
|
||||
|
||||
check_printer(write_lines, left, right, &expected);
|
||||
}
|
||||
|
||||
/// Relistic multiple line chunks
|
||||
///
|
||||
/// We can't support realistic line diffing in large blocks
|
||||
/// (also, it's unclear how usefult this is)
|
||||
///
|
||||
/// So if we have more than one line in a single removal chunk, disable inline diffing.
|
||||
#[test]
|
||||
fn write_lines_multiline_block() {
|
||||
let left = r#"Proboscis
|
||||
Cabbage"#;
|
||||
let right = r#"Probed
|
||||
Caravaggio"#;
|
||||
let expected = format!(
|
||||
r#"{red_light}<Proboscis{reset}
|
||||
{red_light}<Cabbage{reset}
|
||||
{green_light}>Probed{reset}
|
||||
{green_light}>Caravaggio{reset}
|
||||
"#,
|
||||
red_light = RED_LIGHT,
|
||||
green_light = GREEN_LIGHT,
|
||||
reset = RESET,
|
||||
);
|
||||
|
||||
check_printer(write_lines, left, right, &expected);
|
||||
}
|
||||
|
||||
/// Single deletion line, multiple insertions - no inline diffing.
|
||||
#[test]
|
||||
fn write_lines_multiline_insert() {
|
||||
let left = r#"Cabbage"#;
|
||||
let right = r#"Probed
|
||||
Caravaggio"#;
|
||||
let expected = format!(
|
||||
r#"{red_light}<Cabbage{reset}
|
||||
{green_light}>Probed{reset}
|
||||
{green_light}>Caravaggio{reset}
|
||||
"#,
|
||||
red_light = RED_LIGHT,
|
||||
green_light = GREEN_LIGHT,
|
||||
reset = RESET,
|
||||
);
|
||||
|
||||
check_printer(write_lines, left, right, &expected);
|
||||
}
|
||||
|
||||
/// Multiple deletion, single insertion - no inline diffing.
|
||||
#[test]
|
||||
fn write_lines_multiline_delete() {
|
||||
let left = r#"Proboscis
|
||||
Cabbage"#;
|
||||
let right = r#"Probed"#;
|
||||
let expected = format!(
|
||||
r#"{red_light}<Proboscis{reset}
|
||||
{red_light}<Cabbage{reset}
|
||||
{green_light}>Probed{reset}
|
||||
"#,
|
||||
red_light = RED_LIGHT,
|
||||
green_light = GREEN_LIGHT,
|
||||
reset = RESET,
|
||||
);
|
||||
|
||||
check_printer(write_lines, left, right, &expected);
|
||||
}
|
||||
|
||||
/// Regression test for multiline highlighting issue
|
||||
#[test]
|
||||
fn write_lines_issue12() {
|
||||
let left = r#"[
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
128,
|
||||
10,
|
||||
191,
|
||||
5,
|
||||
64,
|
||||
]"#;
|
||||
let right = r#"[
|
||||
84,
|
||||
248,
|
||||
45,
|
||||
64,
|
||||
]"#;
|
||||
let expected = format!(
|
||||
r#" [
|
||||
{red_light}< 0,{reset}
|
||||
{red_light}< 0,{reset}
|
||||
{red_light}< 0,{reset}
|
||||
{red_light}< 128,{reset}
|
||||
{red_light}< 10,{reset}
|
||||
{red_light}< 191,{reset}
|
||||
{red_light}< 5,{reset}
|
||||
{green_light}> 84,{reset}
|
||||
{green_light}> 248,{reset}
|
||||
{green_light}> 45,{reset}
|
||||
64,
|
||||
]
|
||||
"#,
|
||||
red_light = RED_LIGHT,
|
||||
green_light = GREEN_LIGHT,
|
||||
reset = RESET,
|
||||
);
|
||||
|
||||
check_printer(write_lines, left, right, &expected);
|
||||
}
|
||||
|
||||
mod write_lines_edge_newlines {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn both_trailing() {
|
||||
let left = "fan\n";
|
||||
let right = "mug\n";
|
||||
// Note the additional space at the bottom is caused by a trailing newline
|
||||
// adding an additional line with zero content to both sides of the diff
|
||||
let expected = format!(
|
||||
r#"{red_light}<{reset}{red_heavy}fan{reset}
|
||||
{green_light}>{reset}{green_heavy}mug{reset}
|
||||
|
||||
"#,
|
||||
red_light = RED_LIGHT,
|
||||
red_heavy = RED_HEAVY,
|
||||
green_light = GREEN_LIGHT,
|
||||
green_heavy = GREEN_HEAVY,
|
||||
reset = RESET,
|
||||
);
|
||||
|
||||
check_printer(write_lines, left, right, &expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn both_leading() {
|
||||
let left = "\nfan";
|
||||
let right = "\nmug";
|
||||
// Note the additional space at the top is caused by a leading newline
|
||||
// adding an additional line with zero content to both sides of the diff
|
||||
let expected = format!(
|
||||
r#"
|
||||
{red_light}<{reset}{red_heavy}fan{reset}
|
||||
{green_light}>{reset}{green_heavy}mug{reset}
|
||||
"#,
|
||||
red_light = RED_LIGHT,
|
||||
red_heavy = RED_HEAVY,
|
||||
green_light = GREEN_LIGHT,
|
||||
green_heavy = GREEN_HEAVY,
|
||||
reset = RESET,
|
||||
);
|
||||
|
||||
check_printer(write_lines, left, right, &expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn leading_added() {
|
||||
let left = "fan";
|
||||
let right = "\nmug";
|
||||
let expected = format!(
|
||||
r#"{red_light}<fan{reset}
|
||||
{green_light}>{reset}
|
||||
{green_light}>mug{reset}
|
||||
"#,
|
||||
red_light = RED_LIGHT,
|
||||
green_light = GREEN_LIGHT,
|
||||
reset = RESET,
|
||||
);
|
||||
|
||||
check_printer(write_lines, left, right, &expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn leading_deleted() {
|
||||
let left = "\nfan";
|
||||
let right = "mug";
|
||||
let expected = format!(
|
||||
r#"{red_light}<{reset}
|
||||
{red_light}<fan{reset}
|
||||
{green_light}>mug{reset}
|
||||
"#,
|
||||
red_light = RED_LIGHT,
|
||||
green_light = GREEN_LIGHT,
|
||||
reset = RESET,
|
||||
);
|
||||
|
||||
check_printer(write_lines, left, right, &expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn trailing_added() {
|
||||
let left = "fan";
|
||||
let right = "mug\n";
|
||||
let expected = format!(
|
||||
r#"{red_light}<fan{reset}
|
||||
{green_light}>mug{reset}
|
||||
{green_light}>{reset}
|
||||
"#,
|
||||
red_light = RED_LIGHT,
|
||||
green_light = GREEN_LIGHT,
|
||||
reset = RESET,
|
||||
);
|
||||
|
||||
check_printer(write_lines, left, right, &expected);
|
||||
}
|
||||
|
||||
/// Regression test for double abort
|
||||
///
|
||||
/// See: https://github.com/rust-pretty-assertions/rust-pretty-assertions/issues/96
|
||||
#[test]
|
||||
fn trailing_deleted() {
|
||||
// The below inputs caused an abort via double panic
|
||||
// we panicked at 'insertion followed by deletion'
|
||||
let left = "fan\n";
|
||||
let right = "mug";
|
||||
let expected = format!(
|
||||
r#"{red_light}<{reset}{red_heavy}fan{reset}
|
||||
{green_light}>{reset}{green_heavy}mug{reset}
|
||||
{red_light}<{reset}
|
||||
"#,
|
||||
red_light = RED_LIGHT,
|
||||
red_heavy = RED_HEAVY,
|
||||
green_light = GREEN_LIGHT,
|
||||
green_heavy = GREEN_HEAVY,
|
||||
reset = RESET,
|
||||
);
|
||||
|
||||
check_printer(write_lines, left, right, &expected);
|
||||
}
|
||||
}
|
||||
}
|
||||
392
third-party/vendor/pretty_assertions/tests/macros.rs
vendored
Normal file
392
third-party/vendor/pretty_assertions/tests/macros.rs
vendored
Normal file
|
|
@ -0,0 +1,392 @@
|
|||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
#![no_implicit_prelude]
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
extern crate alloc;
|
||||
|
||||
#[allow(clippy::eq_op)]
|
||||
mod assert_str_eq {
|
||||
use ::core::{cmp::PartialEq, convert::AsRef};
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
use ::alloc::string::{String, ToString};
|
||||
#[cfg(feature = "std")]
|
||||
use ::std::string::{String, ToString};
|
||||
|
||||
#[test]
|
||||
fn passes_str() {
|
||||
let a = "some value";
|
||||
::pretty_assertions::assert_str_eq!(a, a);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn passes_string() {
|
||||
let a: String = "some value".to_string();
|
||||
::pretty_assertions::assert_str_eq!(a, a);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn passes_comparable_types() {
|
||||
let s0: &'static str = "foo";
|
||||
let s1: String = "foo".to_string();
|
||||
::pretty_assertions::assert_str_eq!(s0, s1);
|
||||
}
|
||||
|
||||
#[derive(PartialEq)]
|
||||
struct MyString(String);
|
||||
|
||||
impl AsRef<str> for MyString {
|
||||
fn as_ref(&self) -> &str {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq<String> for MyString {
|
||||
fn eq(&self, other: &String) -> bool {
|
||||
&self.0 == other
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn passes_as_ref_types() {
|
||||
let s0 = MyString("foo".to_string());
|
||||
let s1 = "foo".to_string();
|
||||
::pretty_assertions::assert_str_eq!(s0, s1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = r#"assertion failed: `(left == right)`
|
||||
|
||||
[1mDiff[0m [31m< left[0m / [32mright >[0m :
|
||||
foo
|
||||
[31m<ba[0m[1;48;5;52;31mr[0m
|
||||
[32m>ba[0m[1;48;5;22;32mz[0m
|
||||
|
||||
"#)]
|
||||
fn fails_as_ref_types() {
|
||||
let s0 = MyString("foo\nbar".to_string());
|
||||
let s1 = "foo\nbaz".to_string();
|
||||
::pretty_assertions::assert_str_eq!(s0, s1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = r#"assertion failed: `(left == right)`
|
||||
|
||||
[1mDiff[0m [31m< left[0m / [32mright >[0m :
|
||||
foo
|
||||
[31m<ba[0m[1;48;5;52;31mr[0m
|
||||
[32m>ba[0m[1;48;5;22;32mz[0m
|
||||
|
||||
"#)]
|
||||
fn fails_foo() {
|
||||
::pretty_assertions::assert_str_eq!("foo\nbar", "foo\nbaz");
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::eq_op)]
|
||||
mod assert_eq {
|
||||
#[cfg(feature = "alloc")]
|
||||
use ::alloc::string::{String, ToString};
|
||||
#[cfg(feature = "std")]
|
||||
use ::std::string::{String, ToString};
|
||||
|
||||
#[test]
|
||||
fn passes() {
|
||||
let a = "some value";
|
||||
::pretty_assertions::assert_eq!(a, a);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn passes_unsized() {
|
||||
let a: &[u8] = b"e";
|
||||
::pretty_assertions::assert_eq!(*a, *a);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn passes_comparable_types() {
|
||||
let s0: &'static str = "foo";
|
||||
let s1: String = "foo".to_string();
|
||||
::pretty_assertions::assert_eq!(s0, s1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = r#"assertion failed: `(left == right)`
|
||||
|
||||
[1mDiff[0m [31m< left[0m / [32mright >[0m :
|
||||
[31m<[0m[1;48;5;52;31m666[0m
|
||||
[32m>[0m[1;48;5;22;32m999[0m
|
||||
|
||||
"#)]
|
||||
fn fails() {
|
||||
::pretty_assertions::assert_eq!(666, 999);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = r#"assertion failed: `(left == right)`
|
||||
|
||||
[1mDiff[0m [31m< left[0m / [32mright >[0m :
|
||||
[31m<[0m[1;48;5;52;31m666[0m
|
||||
[32m>[0m[1;48;5;22;32m999[0m
|
||||
|
||||
"#)]
|
||||
fn fails_trailing_comma() {
|
||||
::pretty_assertions::assert_eq!(666, 999,);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = r#"assertion failed: `(left == right)`
|
||||
|
||||
[1mDiff[0m [31m< left[0m / [32mright >[0m :
|
||||
[
|
||||
101,
|
||||
[32m> 101,[0m
|
||||
]
|
||||
|
||||
"#)]
|
||||
fn fails_unsized() {
|
||||
let a: &[u8] = b"e";
|
||||
let b: &[u8] = b"ee";
|
||||
::pretty_assertions::assert_eq!(*a, *b);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(
|
||||
expected = r#"assertion failed: `(left == right)`: custom panic message
|
||||
|
||||
[1mDiff[0m [31m< left[0m / [32mright >[0m :
|
||||
[31m<[0m[1;48;5;52;31m666[0m
|
||||
[32m>[0m[1;48;5;22;32m999[0m
|
||||
|
||||
"#
|
||||
)]
|
||||
fn fails_custom() {
|
||||
::pretty_assertions::assert_eq!(666, 999, "custom panic message");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(
|
||||
expected = r#"assertion failed: `(left == right)`: custom panic message
|
||||
|
||||
[1mDiff[0m [31m< left[0m / [32mright >[0m :
|
||||
[31m<[0m[1;48;5;52;31m666[0m
|
||||
[32m>[0m[1;48;5;22;32m999[0m
|
||||
|
||||
"#
|
||||
)]
|
||||
fn fails_custom_trailing_comma() {
|
||||
::pretty_assertions::assert_eq!(666, 999, "custom panic message",);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = r#"assertion failed: `(left == right)`
|
||||
|
||||
[1mDiff[0m [31m< left[0m / [32mright >[0m :
|
||||
foo
|
||||
[31m<ba[0m[1;48;5;52;31mr[0m
|
||||
[32m>ba[0m[1;48;5;22;32mz[0m
|
||||
|
||||
"#)]
|
||||
fn fails_str() {
|
||||
::pretty_assertions::assert_eq!("foo\nbar", "foo\nbaz");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = r#"assertion failed: `(left == right)`
|
||||
|
||||
[1mDiff[0m [31m< left[0m / [32mright >[0m :
|
||||
foo
|
||||
[31m<ba[0m[1;48;5;52;31mr[0m
|
||||
[32m>ba[0m[1;48;5;22;32mz[0m
|
||||
|
||||
"#)]
|
||||
fn fails_string() {
|
||||
::pretty_assertions::assert_eq!("foo\nbar".to_string(), "foo\nbaz".to_string());
|
||||
}
|
||||
}
|
||||
|
||||
mod assert_ne {
|
||||
#[cfg(feature = "alloc")]
|
||||
use ::alloc::string::{String, ToString};
|
||||
#[cfg(feature = "std")]
|
||||
use ::std::string::{String, ToString};
|
||||
|
||||
#[test]
|
||||
fn passes() {
|
||||
let a = "a";
|
||||
let b = "b";
|
||||
::pretty_assertions::assert_ne!(a, b);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn passes_unsized() {
|
||||
let a: &[u8] = b"e";
|
||||
let b: &[u8] = b"ee";
|
||||
::pretty_assertions::assert_ne!(*a, *b);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn passes_comparable_types() {
|
||||
let s0: &'static str = "foo";
|
||||
let s1: String = "bar".to_string();
|
||||
::pretty_assertions::assert_ne!(s0, s1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = r#"assertion failed: `(left != right)`
|
||||
|
||||
Both sides:
|
||||
666
|
||||
"#)]
|
||||
fn fails() {
|
||||
::pretty_assertions::assert_ne!(666, 666);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = r#"assertion failed: `(left != right)`
|
||||
|
||||
Both sides:
|
||||
666
|
||||
"#)]
|
||||
fn fails_trailing_comma() {
|
||||
::pretty_assertions::assert_ne!(666, 666,);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = r#"assertion failed: `(left != right)`
|
||||
|
||||
Both sides:
|
||||
[
|
||||
101,
|
||||
]
|
||||
|
||||
"#)]
|
||||
fn fails_unsized() {
|
||||
let a: &[u8] = b"e";
|
||||
::pretty_assertions::assert_ne!(*a, *a);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(
|
||||
expected = r#"assertion failed: `(left != right)`: custom panic message
|
||||
|
||||
Both sides:
|
||||
666
|
||||
"#
|
||||
)]
|
||||
fn fails_custom() {
|
||||
::pretty_assertions::assert_ne!(666, 666, "custom panic message");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(
|
||||
expected = r#"assertion failed: `(left != right)`: custom panic message
|
||||
|
||||
Both sides:
|
||||
666
|
||||
"#
|
||||
)]
|
||||
fn fails_custom_trailing_comma() {
|
||||
::pretty_assertions::assert_ne!(666, 666, "custom panic message",);
|
||||
}
|
||||
|
||||
// If the values are equal but their debug outputs are not
|
||||
// show a specific warning
|
||||
|
||||
// Regression tests
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn assert_ne_non_empty_return() {
|
||||
fn not_zero(x: u32) -> u32 {
|
||||
::pretty_assertions::assert_ne!(x, 0);
|
||||
x
|
||||
}
|
||||
not_zero(0);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "unstable")]
|
||||
mod assert_matches {
|
||||
use ::core::option::Option::{None, Some};
|
||||
|
||||
#[test]
|
||||
fn passes() {
|
||||
let a = Some("some value");
|
||||
::pretty_assertions::assert_matches!(a, Some(_));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn passes_unsized() {
|
||||
let a: &[u8] = b"e";
|
||||
::pretty_assertions::assert_matches!(*a, _);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = r#"assertion failed: `(left matches right)`
|
||||
|
||||
[1mDiff[0m [31m< left[0m / [32mright >[0m :
|
||||
[31m<[0m[1;48;5;52;31mN[0m[31mo[0m[1;48;5;52;31mn[0m[31me[0m
|
||||
[32m>[0m[1;48;5;22;32mS[0m[32mo[0m[1;48;5;22;32mm[0m[32me[0m[1;48;5;22;32m(_)[0m
|
||||
|
||||
"#)]
|
||||
fn fails() {
|
||||
::pretty_assertions::assert_matches!(None::<usize>, Some(_));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = r#"assertion failed: `(left matches right)`
|
||||
|
||||
[1mDiff[0m [31m< left[0m / [32mright >[0m :
|
||||
[31m<Some([0m
|
||||
[31m< 3,[0m
|
||||
[31m<)[0m
|
||||
[32m>Some(3) if 0 > 0[0m
|
||||
|
||||
"#)]
|
||||
fn fails_guard() {
|
||||
::pretty_assertions::assert_matches!(Some(3), Some(3) if 0 > 0,);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = r#"assertion failed: `(left matches right)`
|
||||
|
||||
[1mDiff[0m [31m< left[0m / [32mright >[0m :
|
||||
[31m<[[0m
|
||||
[31m< 101,[0m
|
||||
[31m<][0m
|
||||
[32m>ref b if b == b"ee"[0m
|
||||
|
||||
"#)]
|
||||
fn fails_unsized() {
|
||||
let a: &[u8] = b"e";
|
||||
::pretty_assertions::assert_matches!(*a, ref b if b == b"ee");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(
|
||||
expected = r#"assertion failed: `(left matches right)`: custom panic message
|
||||
|
||||
[1mDiff[0m [31m< left[0m / [32mright >[0m :
|
||||
[31m<[0m[1;48;5;52;31m666[0m
|
||||
[32m>[0m[1;48;5;22;32m999[0m
|
||||
|
||||
"#
|
||||
)]
|
||||
fn fails_custom() {
|
||||
::pretty_assertions::assert_matches!(666, 999, "custom panic message");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(
|
||||
expected = r#"assertion failed: `(left matches right)`: custom panic message
|
||||
|
||||
[1mDiff[0m [31m< left[0m / [32mright >[0m :
|
||||
[31m<[0m[1;48;5;52;31m666[0m
|
||||
[32m>[0m[1;48;5;22;32m999[0m
|
||||
|
||||
"#
|
||||
)]
|
||||
fn fails_custom_trailing_comma() {
|
||||
::pretty_assertions::assert_matches!(666, 999, "custom panic message",);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue