From 698f8c2f01ea549d77d7dc3338a12e04c11057b9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:02:58 +0200 Subject: Adding upstream version 1.64.0+dfsg1. Signed-off-by: Daniel Baumann --- vendor/indoc/.cargo-checksum.json | 1 + vendor/indoc/Cargo.toml | 45 +++ vendor/indoc/LICENSE-APACHE | 201 ++++++++++ vendor/indoc/LICENSE-MIT | 23 ++ vendor/indoc/README.md | 150 ++++++++ vendor/indoc/src/error.rs | 47 +++ vendor/indoc/src/expr.rs | 56 +++ vendor/indoc/src/lib.rs | 403 +++++++++++++++++++++ vendor/indoc/src/unindent.rs | 131 +++++++ vendor/indoc/tests/compiletest.rs | 7 + vendor/indoc/tests/test_formatdoc.rs | 117 ++++++ vendor/indoc/tests/test_indoc.rs | 166 +++++++++ vendor/indoc/tests/test_unindent.rs | 53 +++ vendor/indoc/tests/test_writedoc.rs | 57 +++ vendor/indoc/tests/ui/no-arguments.rs | 5 + vendor/indoc/tests/ui/no-arguments.stderr | 7 + vendor/indoc/tests/ui/non-lit.rs | 5 + vendor/indoc/tests/ui/non-lit.stderr | 5 + vendor/indoc/tests/ui/non-string.rs | 5 + vendor/indoc/tests/ui/non-string.stderr | 5 + vendor/indoc/tests/ui/printdoc-binary.rs | 5 + vendor/indoc/tests/ui/printdoc-binary.stderr | 5 + vendor/indoc/tests/ui/printdoc-extra-arg.rs | 5 + vendor/indoc/tests/ui/printdoc-extra-arg.stderr | 7 + vendor/indoc/tests/ui/printdoc-no-arg.rs | 5 + vendor/indoc/tests/ui/printdoc-no-arg.stderr | 5 + vendor/indoc/tests/ui/printdoc-no-display.rs | 7 + vendor/indoc/tests/ui/printdoc-no-display.stderr | 9 + vendor/indoc/tests/ui/printdoc-no-named-arg.rs | 5 + vendor/indoc/tests/ui/printdoc-no-named-arg.stderr | 5 + vendor/indoc/tests/ui/three-arguments.rs | 9 + vendor/indoc/tests/ui/three-arguments.stderr | 5 + vendor/indoc/tests/ui/two-arguments.rs | 9 + vendor/indoc/tests/ui/two-arguments.stderr | 5 + 34 files changed, 1575 insertions(+) create mode 100644 vendor/indoc/.cargo-checksum.json create mode 100644 vendor/indoc/Cargo.toml create mode 100644 vendor/indoc/LICENSE-APACHE create mode 100644 vendor/indoc/LICENSE-MIT create mode 100644 vendor/indoc/README.md create mode 100644 vendor/indoc/src/error.rs create mode 100644 vendor/indoc/src/expr.rs create mode 100644 vendor/indoc/src/lib.rs create mode 100644 vendor/indoc/src/unindent.rs create mode 100644 vendor/indoc/tests/compiletest.rs create mode 100644 vendor/indoc/tests/test_formatdoc.rs create mode 100644 vendor/indoc/tests/test_indoc.rs create mode 100644 vendor/indoc/tests/test_unindent.rs create mode 100644 vendor/indoc/tests/test_writedoc.rs create mode 100644 vendor/indoc/tests/ui/no-arguments.rs create mode 100644 vendor/indoc/tests/ui/no-arguments.stderr create mode 100644 vendor/indoc/tests/ui/non-lit.rs create mode 100644 vendor/indoc/tests/ui/non-lit.stderr create mode 100644 vendor/indoc/tests/ui/non-string.rs create mode 100644 vendor/indoc/tests/ui/non-string.stderr create mode 100644 vendor/indoc/tests/ui/printdoc-binary.rs create mode 100644 vendor/indoc/tests/ui/printdoc-binary.stderr create mode 100644 vendor/indoc/tests/ui/printdoc-extra-arg.rs create mode 100644 vendor/indoc/tests/ui/printdoc-extra-arg.stderr create mode 100644 vendor/indoc/tests/ui/printdoc-no-arg.rs create mode 100644 vendor/indoc/tests/ui/printdoc-no-arg.stderr create mode 100644 vendor/indoc/tests/ui/printdoc-no-display.rs create mode 100644 vendor/indoc/tests/ui/printdoc-no-display.stderr create mode 100644 vendor/indoc/tests/ui/printdoc-no-named-arg.rs create mode 100644 vendor/indoc/tests/ui/printdoc-no-named-arg.stderr create mode 100644 vendor/indoc/tests/ui/three-arguments.rs create mode 100644 vendor/indoc/tests/ui/three-arguments.stderr create mode 100644 vendor/indoc/tests/ui/two-arguments.rs create mode 100644 vendor/indoc/tests/ui/two-arguments.stderr (limited to 'vendor/indoc') diff --git a/vendor/indoc/.cargo-checksum.json b/vendor/indoc/.cargo-checksum.json new file mode 100644 index 000000000..f3c4743ec --- /dev/null +++ b/vendor/indoc/.cargo-checksum.json @@ -0,0 +1 @@ +{"files":{"Cargo.toml":"45896f2b2b88b9c1920df3cbd7367a9d5e4edc8279dd481de461cc59b728dd12","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"23f18e03dc49df91622fe2a76176497404e46ced8a715d9d2b67a7446571cca3","README.md":"54b410081f121f119ec7e736aedd68428c658498725ee1694c17e574b85badc6","src/error.rs":"be08d9d48b4cb9984b5141b12f21c31bd7293942c18b3ce25754723930cf54f5","src/expr.rs":"4f3e64f1c890a64f441e5a08820fe73d5d1949f6e3e921f3e4a116ef5d4c6dc8","src/lib.rs":"6bdbdb97b5f456882add99cea911d5184f3b0f858b8f9155f7d929d4a562443b","src/unindent.rs":"b36eef3c011b4ee1166a04ad9f97d0e20bde45ae19cc8ccc89a7f5a29e8f6474","tests/compiletest.rs":"022a8e400ef813d7ea1875b944549cee5125f6a995dc33e93b48cba3e1b57bd1","tests/test_formatdoc.rs":"8b341b13758b6d55cdaedad16049369d9bd907fb1fbccb3a236e6024401b47fd","tests/test_indoc.rs":"154cc7b07b93e3790b4663eea853cd87652db6962bb53238861dd9a3f4739084","tests/test_unindent.rs":"57ce28df0e6055b661097cb4dca3efa949e15535aa28d1bc8da6932d4cc1ed15","tests/test_writedoc.rs":"f9cf8de4549866d0478e23625585b2bf7afd2c7a6e2253f30678fbd22a81b375","tests/ui/no-arguments.rs":"d544b1a510efbef42a1fb7b7b40009da2d9be815a55ef76dd2362c8c7754734e","tests/ui/no-arguments.stderr":"50adb9ca3a1b1661ef7dbd9e9a74804353d18c294d2a28498f50ef91676f13d6","tests/ui/non-lit.rs":"3e7d7b4b5e141b5eb4c76d64b47f7a5f60325091a8e4d8cc2d97b7d590dd2857","tests/ui/non-lit.stderr":"f7ea54b55db14f756254e013150a3a45d3045cef4419e8a512cfd70ec29b858e","tests/ui/non-string.rs":"0b56f281761edaee1c7341c9ba231371c86752456179d84777c62f03f52ce173","tests/ui/non-string.stderr":"6a65eb94f57ef6733da6a1d855194708e124dd8dac424d3eebde6e79b966f9ad","tests/ui/printdoc-binary.rs":"0122fd6b783cb9c25c8aede8f0cc69c1c3ffcef656bf7d9ee476e8e0ff49e59f","tests/ui/printdoc-binary.stderr":"4b745df236fbca6ac1f314e6b1c26c069fc4d108edad84a8a69b7dcc2e6ca4ea","tests/ui/printdoc-extra-arg.rs":"fa31182019534b5b258f8335799c8ba53a7715c1d9e6fc9d25fbc0952d28bd7a","tests/ui/printdoc-extra-arg.stderr":"aebd5360f0a1b4e4faba9defc91d186a992248c00808e198ad31ae2110ab86ed","tests/ui/printdoc-no-arg.rs":"087d8e5295f7809abf596a076743401f6ba019fd5b3b2e290bfd6551b4bdcdf3","tests/ui/printdoc-no-arg.stderr":"a5e5d79415ef3fc357403c38b486acbb6ba3e5e565c358265694902afd476b9d","tests/ui/printdoc-no-display.rs":"afeafb1f41a6f7aa68bd5da14c2057e54f2756c1726098ac8be9ab0517a85879","tests/ui/printdoc-no-display.stderr":"355ab2e2e1da77d4ca8364379f0c015007ddd0a03326108db830259a517a8928","tests/ui/printdoc-no-named-arg.rs":"beeb8447ab95a0e0a21aec78872be79ad1b2a8fe1be4a276fe191f47f3b8082b","tests/ui/printdoc-no-named-arg.stderr":"c5e2f35a4c960e0ae86c2c3481645da90bf86b8f8ae8b6f8c8954d8c9917a44d","tests/ui/three-arguments.rs":"47b74a9918de87bad00cdd94dc7091a499a586edcfbc05035ef79ce0d52dbe27","tests/ui/three-arguments.stderr":"f3649c03bf13c18b863f0ee0986154c4530601138c574e30cf05f7916eb85c39","tests/ui/two-arguments.rs":"1607e7c149cc0ed5e3fb5984ac1d39d8dff0bd8325911518b02d05daa95b06b0","tests/ui/two-arguments.stderr":"a446346d0cb74e791174b22eed874130387d21038cfdb809b80eb068b4f24b92"},"package":"05a0bd019339e5d968b37855180087b7b9d512c5046fbd244cf8c95687927d6e"} \ No newline at end of file diff --git a/vendor/indoc/Cargo.toml b/vendor/indoc/Cargo.toml new file mode 100644 index 000000000..eb4d941e7 --- /dev/null +++ b/vendor/indoc/Cargo.toml @@ -0,0 +1,45 @@ +# 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" +rust-version = "1.42" +name = "indoc" +version = "1.0.6" +authors = ["David Tolnay "] +description = "Indented document literals" +documentation = "https://docs.rs/indoc" +readme = "README.md" +keywords = [ + "heredoc", + "nowdoc", + "multiline", + "string", + "literal", +] +license = "MIT OR Apache-2.0" +repository = "https://github.com/dtolnay/indoc" + +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] + +[lib] +proc-macro = true + +[dev-dependencies.rustversion] +version = "1.0" + +[dev-dependencies.trybuild] +version = "1.0.49" +features = ["diff"] + +[dev-dependencies.unindent] +version = "0.1.9" diff --git a/vendor/indoc/LICENSE-APACHE b/vendor/indoc/LICENSE-APACHE new file mode 100644 index 000000000..16fe87b06 --- /dev/null +++ b/vendor/indoc/LICENSE-APACHE @@ -0,0 +1,201 @@ + 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. diff --git a/vendor/indoc/LICENSE-MIT b/vendor/indoc/LICENSE-MIT new file mode 100644 index 000000000..31aa79387 --- /dev/null +++ b/vendor/indoc/LICENSE-MIT @@ -0,0 +1,23 @@ +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. diff --git a/vendor/indoc/README.md b/vendor/indoc/README.md new file mode 100644 index 000000000..795d5ab86 --- /dev/null +++ b/vendor/indoc/README.md @@ -0,0 +1,150 @@ +Indented Documents (indoc) +========================== + +[github](https://github.com/dtolnay/indoc) +[crates.io](https://crates.io/crates/indoc) +[docs.rs](https://docs.rs/indoc) +[build status](https://github.com/dtolnay/indoc/actions?query=branch%3Amaster) + +This crate provides a procedural macro for indented string literals. The +`indoc!()` macro takes a multiline string literal and un-indents it at compile +time so the leftmost non-space character is in the first column. + +```toml +[dependencies] +indoc = "1.0" +``` + +*Compiler requirement: rustc 1.45 or greater.* + +
+ +## Using indoc + +```rust +use indoc::indoc; + +fn main() { + let testing = indoc! {" + def hello(): + print('Hello, world!') + + hello() + "}; + let expected = "def hello():\n print('Hello, world!')\n\nhello()\n"; + assert_eq!(testing, expected); +} +``` + +Indoc also works with raw string literals: + +```rust +use indoc::indoc; + +fn main() { + let testing = indoc! {r#" + def hello(): + print("Hello, world!") + + hello() + "#}; + let expected = "def hello():\n print(\"Hello, world!\")\n\nhello()\n"; + assert_eq!(testing, expected); +} +``` + +And byte string literals: + +```rust +use indoc::indoc; + +fn main() { + let testing = indoc! {b" + def hello(): + print('Hello, world!') + + hello() + "}; + let expected = b"def hello():\n print('Hello, world!')\n\nhello()\n"; + assert_eq!(testing[..], expected[..]); +} +``` + +
+ +## Formatting macros + +The indoc crate exports four additional macros to substitute conveniently for +the standard library's formatting macros: + +- `formatdoc!($fmt, ...)` — equivalent to `format!(indoc!($fmt), ...)` +- `printdoc!($fmt, ...)` — equivalent to `print!(indoc!($fmt), ...)` +- `eprintdoc!($fmt, ...)` — equivalent to `eprint!(indoc!($fmt), ...)` +- `writedoc!($dest, $fmt, ...)` — equivalent to `write!($dest, indoc!($fmt), ...)` + +```rust +use indoc::printdoc; + +fn main() { + printdoc! {" + GET {url} + Accept: {mime} + ", + url = "http://localhost:8080", + mime = "application/json", + } +} +``` + +
+ +## Explanation + +The following rules characterize the behavior of the `indoc!()` macro: + +1. Count the leading spaces of each line, ignoring the first line and any lines + that are empty or contain spaces only. +2. Take the minimum. +3. If the first line is empty i.e. the string begins with a newline, remove the + first line. +4. Remove the computed number of spaces from the beginning of each line. + +
+ +## Unindent + +Indoc's indentation logic is available in the `unindent` crate. This may be +useful for processing strings that are not statically known at compile time. + +The crate exposes two functions: + +- `unindent(&str) -> String` +- `unindent_bytes(&[u8]) -> Vec` + +```rust +use unindent::unindent; + +fn main() { + let indented = " + line one + line two"; + assert_eq!("line one\nline two", unindent(indented)); +} +``` + +
+ +#### License + + +Licensed under either of Apache License, Version +2.0 or MIT license at your option. + + +
+ + +Unless you explicitly state otherwise, any contribution intentionally submitted +for inclusion in this crate by you, as defined in the Apache-2.0 license, shall +be dual licensed as above, without any additional terms or conditions. + diff --git a/vendor/indoc/src/error.rs b/vendor/indoc/src/error.rs new file mode 100644 index 000000000..7c5badb25 --- /dev/null +++ b/vendor/indoc/src/error.rs @@ -0,0 +1,47 @@ +use proc_macro::{Delimiter, Group, Ident, Literal, Punct, Spacing, Span, TokenStream, TokenTree}; +use std::iter::FromIterator; + +pub type Result = std::result::Result; + +pub struct Error { + begin: Span, + end: Span, + msg: String, +} + +impl Error { + pub fn new(span: Span, msg: &str) -> Self { + Self::new2(span, span, msg) + } + + pub fn new2(begin: Span, end: Span, msg: &str) -> Self { + Error { + begin, + end, + msg: msg.to_owned(), + } + } + + pub fn to_compile_error(&self) -> TokenStream { + // compile_error! { $msg } + TokenStream::from_iter(vec![ + TokenTree::Ident(Ident::new("compile_error", self.begin)), + TokenTree::Punct({ + let mut punct = Punct::new('!', Spacing::Alone); + punct.set_span(self.begin); + punct + }), + TokenTree::Group({ + let mut group = Group::new(Delimiter::Brace, { + TokenStream::from_iter(vec![TokenTree::Literal({ + let mut string = Literal::string(&self.msg); + string.set_span(self.end); + string + })]) + }); + group.set_span(self.end); + group + }), + ]) + } +} diff --git a/vendor/indoc/src/expr.rs b/vendor/indoc/src/expr.rs new file mode 100644 index 000000000..e802e2015 --- /dev/null +++ b/vendor/indoc/src/expr.rs @@ -0,0 +1,56 @@ +use crate::error::{Error, Result}; +use proc_macro::token_stream::IntoIter as TokenIter; +use proc_macro::{Spacing, Span, TokenStream, TokenTree}; +use std::iter; + +pub struct Expr(TokenStream); + +pub fn parse(input: &mut TokenIter) -> Result { + #[derive(PartialEq)] + enum Lookbehind { + JointColon, + DoubleColon, + Other, + } + + let mut expr = TokenStream::new(); + let mut lookbehind = Lookbehind::Other; + let mut angle_bracket_depth = 0; + + loop { + match input.next() { + Some(TokenTree::Punct(punct)) => { + let ch = punct.as_char(); + let spacing = punct.spacing(); + expr.extend(iter::once(TokenTree::Punct(punct))); + lookbehind = match ch { + ',' if angle_bracket_depth == 0 => return Ok(Expr(expr)), + ':' if lookbehind == Lookbehind::JointColon => Lookbehind::DoubleColon, + ':' if spacing == Spacing::Joint => Lookbehind::JointColon, + '<' if lookbehind == Lookbehind::DoubleColon => { + angle_bracket_depth += 1; + Lookbehind::Other + } + '>' if angle_bracket_depth > 0 => { + angle_bracket_depth -= 1; + Lookbehind::Other + } + _ => Lookbehind::Other, + }; + } + Some(token) => expr.extend(iter::once(token)), + None => { + return Err(Error::new( + Span::call_site(), + "unexpected end of macro input", + )) + } + } + } +} + +impl Expr { + pub fn into_tokens(self) -> TokenStream { + self.0 + } +} diff --git a/vendor/indoc/src/lib.rs b/vendor/indoc/src/lib.rs new file mode 100644 index 000000000..9c200adc7 --- /dev/null +++ b/vendor/indoc/src/lib.rs @@ -0,0 +1,403 @@ +//! [![github]](https://github.com/dtolnay/indoc) [![crates-io]](https://crates.io/crates/indoc) [![docs-rs]](https://docs.rs/indoc) +//! +//! [github]: https://img.shields.io/badge/github-8da0cb?style=for-the-badge&labelColor=555555&logo=github +//! [crates-io]: https://img.shields.io/badge/crates.io-fc8d62?style=for-the-badge&labelColor=555555&logo=rust +//! [docs-rs]: https://img.shields.io/badge/docs.rs-66c2a5?style=for-the-badge&labelColor=555555&logoColor=white&logo=data:image/svg+xml;base64,PHN2ZyByb2xlPSJpbWciIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgdmlld0JveD0iMCAwIDUxMiA1MTIiPjxwYXRoIGZpbGw9IiNmNWY1ZjUiIGQ9Ik00ODguNiAyNTAuMkwzOTIgMjE0VjEwNS41YzAtMTUtOS4zLTI4LjQtMjMuNC0zMy43bC0xMDAtMzcuNWMtOC4xLTMuMS0xNy4xLTMuMS0yNS4zIDBsLTEwMCAzNy41Yy0xNC4xIDUuMy0yMy40IDE4LjctMjMuNCAzMy43VjIxNGwtOTYuNiAzNi4yQzkuMyAyNTUuNSAwIDI2OC45IDAgMjgzLjlWMzk0YzAgMTMuNiA3LjcgMjYuMSAxOS45IDMyLjJsMTAwIDUwYzEwLjEgNS4xIDIyLjEgNS4xIDMyLjIgMGwxMDMuOS01MiAxMDMuOSA1MmMxMC4xIDUuMSAyMi4xIDUuMSAzMi4yIDBsMTAwLTUwYzEyLjItNi4xIDE5LjktMTguNiAxOS45LTMyLjJWMjgzLjljMC0xNS05LjMtMjguNC0yMy40LTMzLjd6TTM1OCAyMTQuOGwtODUgMzEuOXYtNjguMmw4NS0zN3Y3My4zek0xNTQgMTA0LjFsMTAyLTM4LjIgMTAyIDM4LjJ2LjZsLTEwMiA0MS40LTEwMi00MS40di0uNnptODQgMjkxLjFsLTg1IDQyLjV2LTc5LjFsODUtMzguOHY3NS40em0wLTExMmwtMTAyIDQxLjQtMTAyLTQxLjR2LS42bDEwMi0zOC4yIDEwMiAzOC4ydi42em0yNDAgMTEybC04NSA0Mi41di03OS4xbDg1LTM4Ljh2NzUuNHptMC0xMTJsLTEwMiA0MS40LTEwMi00MS40di0uNmwxMDItMzguMiAxMDIgMzguMnYuNnoiPjwvcGF0aD48L3N2Zz4K +//! +//!
+//! +//! This crate provides a procedural macro for indented string literals. The +//! `indoc!()` macro takes a multiline string literal and un-indents it at +//! compile time so the leftmost non-space character is in the first column. +//! +//! ```toml +//! [dependencies] +//! indoc = "1.0" +//! ``` +//! +//!
+//! +//! # Using indoc +//! +//! ``` +//! use indoc::indoc; +//! +//! fn main() { +//! let testing = indoc! {" +//! def hello(): +//! print('Hello, world!') +//! +//! hello() +//! "}; +//! let expected = "def hello():\n print('Hello, world!')\n\nhello()\n"; +//! assert_eq!(testing, expected); +//! } +//! ``` +//! +//! Indoc also works with raw string literals: +//! +//! ``` +//! use indoc::indoc; +//! +//! fn main() { +//! let testing = indoc! {r#" +//! def hello(): +//! print("Hello, world!") +//! +//! hello() +//! "#}; +//! let expected = "def hello():\n print(\"Hello, world!\")\n\nhello()\n"; +//! assert_eq!(testing, expected); +//! } +//! ``` +//! +//! And byte string literals: +//! +//! ``` +//! use indoc::indoc; +//! +//! fn main() { +//! let testing = indoc! {b" +//! def hello(): +//! print('Hello, world!') +//! +//! hello() +//! "}; +//! let expected = b"def hello():\n print('Hello, world!')\n\nhello()\n"; +//! assert_eq!(testing[..], expected[..]); +//! } +//! ``` +//! +//!

+//! +//! # Formatting macros +//! +//! The indoc crate exports four additional macros to substitute conveniently +//! for the standard library's formatting macros: +//! +//! - `formatdoc!($fmt, ...)` — equivalent to `format!(indoc!($fmt), ...)` +//! - `printdoc!($fmt, ...)` — equivalent to `print!(indoc!($fmt), ...)` +//! - `eprintdoc!($fmt, ...)` — equivalent to `eprint!(indoc!($fmt), ...)` +//! - `writedoc!($dest, $fmt, ...)` — equivalent to `write!($dest, indoc!($fmt), ...)` +//! +//! ``` +//! use indoc::printdoc; +//! +//! fn main() { +//! printdoc! {" +//! GET {url} +//! Accept: {mime} +//! ", +//! url = "http://localhost:8080", +//! mime = "application/json", +//! } +//! } +//! ``` +//! +//!

+//! +//! # Explanation +//! +//! The following rules characterize the behavior of the `indoc!()` macro: +//! +//! 1. Count the leading spaces of each line, ignoring the first line and any +//! lines that are empty or contain spaces only. +//! 2. Take the minimum. +//! 3. If the first line is empty i.e. the string begins with a newline, remove +//! the first line. +//! 4. Remove the computed number of spaces from the beginning of each line. + +#![allow( + clippy::module_name_repetitions, + clippy::needless_doctest_main, + clippy::needless_pass_by_value, + clippy::trivially_copy_pass_by_ref, + clippy::type_complexity +)] + +mod error; +mod expr; +mod unindent; + +use crate::error::{Error, Result}; +use crate::expr::Expr; +use crate::unindent::unindent; +use proc_macro::token_stream::IntoIter as TokenIter; +use proc_macro::{Delimiter, Group, Ident, Literal, Punct, Spacing, Span, TokenStream, TokenTree}; +use std::iter::{self, FromIterator}; +use std::str::FromStr; + +#[derive(Copy, Clone, PartialEq)] +enum Macro { + Indoc, + Format, + Print, + Eprint, + Write, +} + +/// Unindent and produce `&'static str`. +/// +/// # Example +/// +/// ``` +/// # use indoc::indoc; +/// # +/// // The type of `program` is &'static str +/// let program = indoc! {" +/// def hello(): +/// print('Hello, world!') +/// +/// hello() +/// "}; +/// print!("{}", program); +/// ``` +/// +/// ```text +/// def hello(): +/// print('Hello, world!') +/// +/// hello() +/// ``` +#[proc_macro] +pub fn indoc(input: TokenStream) -> TokenStream { + expand(input, Macro::Indoc) +} + +/// Unindent and call `format!`. +/// +/// Argument syntax is the same as for [`std::format!`]. +/// +/// # Example +/// +/// ``` +/// # use indoc::formatdoc; +/// # +/// let request = formatdoc! {" +/// GET {url} +/// Accept: {mime} +/// ", +/// url = "http://localhost:8080", +/// mime = "application/json", +/// }; +/// println!("{}", request); +/// ``` +/// +/// ```text +/// GET http://localhost:8080 +/// Accept: application/json +/// ``` +#[proc_macro] +pub fn formatdoc(input: TokenStream) -> TokenStream { + expand(input, Macro::Format) +} + +/// Unindent and call `print!`. +/// +/// Argument syntax is the same as for [`std::print!`]. +/// +/// # Example +/// +/// ``` +/// # use indoc::printdoc; +/// # +/// printdoc! {" +/// GET {url} +/// Accept: {mime} +/// ", +/// url = "http://localhost:8080", +/// mime = "application/json", +/// } +/// ``` +/// +/// ```text +/// GET http://localhost:8080 +/// Accept: application/json +/// ``` +#[proc_macro] +pub fn printdoc(input: TokenStream) -> TokenStream { + expand(input, Macro::Print) +} + +/// Unindent and call `eprint!`. +/// +/// Argument syntax is the same as for [`std::eprint!`]. +/// +/// # Example +/// +/// ``` +/// # use indoc::eprintdoc; +/// # +/// eprintdoc! {" +/// GET {url} +/// Accept: {mime} +/// ", +/// url = "http://localhost:8080", +/// mime = "application/json", +/// } +/// ``` +/// +/// ```text +/// GET http://localhost:8080 +/// Accept: application/json +/// ``` +#[proc_macro] +pub fn eprintdoc(input: TokenStream) -> TokenStream { + expand(input, Macro::Eprint) +} + +/// Unindent and call `write!`. +/// +/// Argument syntax is the same as for [`std::write!`]. +/// +/// # Example +/// +/// ``` +/// # use indoc::writedoc; +/// # use std::io::Write; +/// # +/// let _ = writedoc!( +/// std::io::stdout(), +/// " +/// GET {url} +/// Accept: {mime} +/// ", +/// url = "http://localhost:8080", +/// mime = "application/json", +/// ); +/// ``` +/// +/// ```text +/// GET http://localhost:8080 +/// Accept: application/json +/// ``` +#[proc_macro] +pub fn writedoc(input: TokenStream) -> TokenStream { + expand(input, Macro::Write) +} + +fn expand(input: TokenStream, mode: Macro) -> TokenStream { + match try_expand(input, mode) { + Ok(tokens) => tokens, + Err(err) => err.to_compile_error(), + } +} + +fn try_expand(input: TokenStream, mode: Macro) -> Result { + let mut input = input.into_iter(); + + let prefix = if mode == Macro::Write { + Some(expr::parse(&mut input)?) + } else { + None + }; + + let first = input.next().ok_or_else(|| { + Error::new( + Span::call_site(), + "unexpected end of macro invocation, expected format string", + ) + })?; + + let unindented_lit = lit_indoc(first, mode)?; + + let macro_name = match mode { + Macro::Indoc => { + require_empty_or_trailing_comma(&mut input)?; + return Ok(TokenStream::from(TokenTree::Literal(unindented_lit))); + } + Macro::Format => "format", + Macro::Print => "print", + Macro::Eprint => "eprint", + Macro::Write => "write", + }; + + // #macro_name! { #unindented_lit #args } + Ok(TokenStream::from_iter(vec![ + TokenTree::Ident(Ident::new(macro_name, Span::call_site())), + TokenTree::Punct(Punct::new('!', Spacing::Alone)), + TokenTree::Group(Group::new( + Delimiter::Brace, + prefix + .map_or_else(TokenStream::new, Expr::into_tokens) + .into_iter() + .chain(iter::once(TokenTree::Literal(unindented_lit))) + .chain(input) + .collect(), + )), + ])) +} + +fn lit_indoc(token: TokenTree, mode: Macro) -> Result { + let span = token.span(); + let mut single_token = Some(token); + + while let Some(TokenTree::Group(group)) = single_token { + single_token = if group.delimiter() == Delimiter::None { + let mut token_iter = group.stream().into_iter(); + token_iter.next().xor(token_iter.next()) + } else { + None + }; + } + + let single_token = + single_token.ok_or_else(|| Error::new(span, "argument must be a single string literal"))?; + + let repr = single_token.to_string(); + let is_string = repr.starts_with('"') || repr.starts_with('r'); + let is_byte_string = repr.starts_with("b\"") || repr.starts_with("br"); + + if !is_string && !is_byte_string { + return Err(Error::new(span, "argument must be a single string literal")); + } + + if is_byte_string && mode != Macro::Indoc { + return Err(Error::new( + span, + "byte strings are not supported in formatting macros", + )); + } + + let begin = repr.find('"').unwrap() + 1; + let end = repr.rfind('"').unwrap(); + let repr = format!( + "{open}{content}{close}", + open = &repr[..begin], + content = unindent(&repr[begin..end]), + close = &repr[end..], + ); + + match TokenStream::from_str(&repr) + .unwrap() + .into_iter() + .next() + .unwrap() + { + TokenTree::Literal(mut lit) => { + lit.set_span(span); + Ok(lit) + } + _ => unreachable!(), + } +} + +fn require_empty_or_trailing_comma(input: &mut TokenIter) -> Result<()> { + let first = match input.next() { + Some(TokenTree::Punct(punct)) if punct.as_char() == ',' => match input.next() { + Some(second) => second, + None => return Ok(()), + }, + Some(first) => first, + None => return Ok(()), + }; + let last = input.last(); + + let begin_span = first.span(); + let end_span = last.as_ref().map_or(begin_span, TokenTree::span); + let msg = format!( + "unexpected {token} in macro invocation; indoc argument must be a single string literal", + token = if last.is_some() { "tokens" } else { "token" } + ); + Err(Error::new2(begin_span, end_span, &msg)) +} diff --git a/vendor/indoc/src/unindent.rs b/vendor/indoc/src/unindent.rs new file mode 100644 index 000000000..11d19d222 --- /dev/null +++ b/vendor/indoc/src/unindent.rs @@ -0,0 +1,131 @@ +use std::iter::Peekable; +use std::slice::Split; + +pub fn unindent(s: &str) -> String { + let bytes = s.as_bytes(); + let unindented = unindent_bytes(bytes); + String::from_utf8(unindented).unwrap() +} + +// Compute the maximal number of spaces that can be removed from every line, and +// remove them. +pub fn unindent_bytes(s: &[u8]) -> Vec { + // Document may start either on the same line as opening quote or + // on the next line + let ignore_first_line = s.starts_with(b"\n") || s.starts_with(b"\r\n"); + + // Largest number of spaces that can be removed from every + // non-whitespace-only line after the first + let spaces = s + .lines() + .skip(1) + .filter_map(count_spaces) + .min() + .unwrap_or(0); + + let mut result = Vec::with_capacity(s.len()); + for (i, line) in s.lines().enumerate() { + if i > 1 || (i == 1 && !ignore_first_line) { + result.push(b'\n'); + } + if i == 0 { + // Do not un-indent anything on same line as opening quote + result.extend_from_slice(line); + } else if line.len() > spaces { + // Whitespace-only lines may have fewer than the number of spaces + // being removed + result.extend_from_slice(&line[spaces..]); + } + } + result +} + +pub trait Unindent { + type Output; + + fn unindent(&self) -> Self::Output; +} + +impl Unindent for str { + type Output = String; + + fn unindent(&self) -> Self::Output { + unindent(self) + } +} + +impl Unindent for String { + type Output = String; + + fn unindent(&self) -> Self::Output { + unindent(self) + } +} + +impl Unindent for [u8] { + type Output = Vec; + + fn unindent(&self) -> Self::Output { + unindent_bytes(self) + } +} + +impl<'a, T: ?Sized + Unindent> Unindent for &'a T { + type Output = T::Output; + + fn unindent(&self) -> Self::Output { + (**self).unindent() + } +} + +// Number of leading spaces in the line, or None if the line is entirely spaces. +fn count_spaces(line: &[u8]) -> Option { + for (i, ch) in line.iter().enumerate() { + if *ch != b' ' && *ch != b'\t' { + return Some(i); + } + } + None +} + +// Based on core::str::StrExt. +trait BytesExt { + fn lines(&self) -> Lines; +} + +impl BytesExt for [u8] { + fn lines(&self) -> Lines { + fn is_newline(b: &u8) -> bool { + *b == b'\n' + } + let bytestring = if self.starts_with(b"\r\n") { + &self[1..] + } else { + self + }; + Lines { + split: bytestring.split(is_newline as fn(&u8) -> bool).peekable(), + } + } +} + +struct Lines<'a> { + split: Peekable bool>>, +} + +impl<'a> Iterator for Lines<'a> { + type Item = &'a [u8]; + + fn next(&mut self) -> Option { + match self.split.next() { + None => None, + Some(fragment) => { + if fragment.is_empty() && self.split.peek().is_none() { + None + } else { + Some(fragment) + } + } + } + } +} diff --git a/vendor/indoc/tests/compiletest.rs b/vendor/indoc/tests/compiletest.rs new file mode 100644 index 000000000..7974a6249 --- /dev/null +++ b/vendor/indoc/tests/compiletest.rs @@ -0,0 +1,7 @@ +#[rustversion::attr(not(nightly), ignore)] +#[cfg_attr(miri, ignore)] +#[test] +fn ui() { + let t = trybuild::TestCases::new(); + t.compile_fail("tests/ui/*.rs"); +} diff --git a/vendor/indoc/tests/test_formatdoc.rs b/vendor/indoc/tests/test_formatdoc.rs new file mode 100644 index 000000000..5e4779504 --- /dev/null +++ b/vendor/indoc/tests/test_formatdoc.rs @@ -0,0 +1,117 @@ +use indoc::formatdoc; + +#[test] +fn carriage_return() { + // Every line in the string ends with \r\n + let indoc = formatdoc! {" + {} + + \\{} + {}", + 'a', 'b', 'c' + }; + let expected = "a\n\n \\b\nc"; + assert_eq!(indoc, expected); +} + +#[test] +fn empty_string() { + let indoc = formatdoc! {""}; + let expected = ""; + assert_eq!(indoc, expected); +} + +#[test] +fn joined_first_line() { + let indoc = formatdoc! {"\ + {}", 'a' + }; + let expected = "a"; + assert_eq!(indoc, expected); +} + +#[test] +fn joined_lines() { + let indoc = formatdoc! {" + {}\ + {} + {}\ + {} + {}", + 'a', 'b', 'c', 'd', 'e' + }; + let expected = "ab\ncd\ne"; + assert_eq!(indoc, expected); +} + +#[test] +fn no_leading_newline() { + let indoc = formatdoc! {"{} + {} + {}", 'a', 'b', 'c'}; + let expected = "a\nb\nc"; + assert_eq!(indoc, expected); +} + +#[test] +fn one_line() { + let indoc = formatdoc! {"a"}; + let expected = "a"; + assert_eq!(indoc, expected); +} + +#[test] +fn raw_string() { + let indoc = formatdoc! {r#" + {:?} + + \\{} + {}"#, + "a", 'b', 'c' + }; + let expected = "\"a\"\n\n \\\\b\nc"; + assert_eq!(indoc, expected); +} + +#[test] +fn string() { + let indoc = formatdoc! {" + {} + + \\{} + {}", + 'a', 'b', 'c' + }; + let expected = "a\n\n \\b\nc"; + assert_eq!(indoc, expected); +} + +#[test] +fn string_trailing_newline() { + let indoc = formatdoc! {" + {} + + \\{} + {} + ", + 'a', 'b', 'c' + }; + let expected = "a\n\n \\b\nc\n"; + assert_eq!(indoc, expected); +} + +#[test] +fn trailing_whitespace() { + let indoc = formatdoc! {" + {} {below} + + {} {below} + + {} {below} + + end", + 2, 0, -2, below = "below" + }; + let expected = "2 below\n \n0 below\n\n-2 below\n\nend"; + assert_eq!(indoc, expected); +} diff --git a/vendor/indoc/tests/test_indoc.rs b/vendor/indoc/tests/test_indoc.rs new file mode 100644 index 000000000..e0ead11b6 --- /dev/null +++ b/vendor/indoc/tests/test_indoc.rs @@ -0,0 +1,166 @@ +use indoc::indoc; + +#[test] +fn byte_string() { + let indoc = indoc! {b" + a + + \\b + c" + }; + let expected = b"a\n\n \\b\nc"; + assert_eq!(indoc, expected); +} + +#[test] +fn carriage_return() { + // Every line in the string ends with \r\n + let indoc = indoc! {" + a + + \\b + c" + }; + let expected = "a\n\n \\b\nc"; + assert_eq!(indoc, expected); +} + +#[test] +fn trailing_comma() { + let indoc = indoc! { + " + test + ", + }; + let expected = "test\n"; + assert_eq!(indoc, expected); +} + +#[test] +fn empty_string() { + let indoc = indoc! {""}; + let expected = ""; + assert_eq!(indoc, expected); +} + +#[test] +fn joined_first_line() { + let indoc = indoc! {"\ + a" + }; + let expected = "a"; + assert_eq!(indoc, expected); +} + +#[test] +fn joined_lines() { + let indoc = indoc! {" + a\ + b + c\ + d + e" + }; + let expected = "ab\ncd\ne"; + assert_eq!(indoc, expected); +} + +#[test] +fn no_leading_newline() { + let indoc = indoc! {"a + b + c"}; + let expected = "a\nb\nc"; + assert_eq!(indoc, expected); +} + +#[test] +fn one_line() { + let indoc = indoc! {"a"}; + let expected = "a"; + assert_eq!(indoc, expected); +} + +#[test] +fn raw_byte_string() { + let indoc = indoc! {br#" + "a" + + \\b + c"# + }; + let expected = b"\"a\"\n\n \\\\b\nc"; + assert_eq!(indoc, expected); +} + +#[test] +fn raw_string() { + let indoc = indoc! {r#" + "a" + + \\b + c"# + }; + let expected = "\"a\"\n\n \\\\b\nc"; + assert_eq!(indoc, expected); +} + +#[test] +fn string() { + let indoc = indoc! {" + a + + \\b + c" + }; + let expected = "a\n\n \\b\nc"; + assert_eq!(indoc, expected); +} + +#[test] +fn string_trailing_newline() { + let indoc = indoc! {" + a + + \\b + c + "}; + let expected = "a\n\n \\b\nc\n"; + assert_eq!(indoc, expected); +} + +#[test] +fn trailing_whitespace() { + let indoc = indoc! {" + 2 below + + 0 below + + -2 below + + end" + }; + let expected = "2 below\n \n0 below\n\n-2 below\n\nend"; + assert_eq!(indoc, expected); +} + +#[test] +fn indoc_as_format_string() { + let s = format!(indoc! {"{}"}, true); + assert_eq!(s, "true"); +} + +#[test] +fn test_metavariable() { + macro_rules! indoc_wrapper { + ($e:expr) => { + indoc!($e) + }; + } + + let indoc = indoc_wrapper! {" + macros, how do they work + "}; + let expected = "macros, how do they work\n"; + assert_eq!(indoc, expected); +} diff --git a/vendor/indoc/tests/test_unindent.rs b/vendor/indoc/tests/test_unindent.rs new file mode 100644 index 000000000..798907c5e --- /dev/null +++ b/vendor/indoc/tests/test_unindent.rs @@ -0,0 +1,53 @@ +#![allow(clippy::shadow_unrelated)] + +use unindent::{unindent, unindent_bytes, Unindent}; + +#[test] +fn fn_unindent_str() { + let s = " + line one + line two"; + assert_eq!(unindent(s), "line one\nline two"); + + let s = "\n\t\t\tline one\n\t\t\tline two"; + assert_eq!(unindent(s), "line one\nline two"); +} + +#[test] +fn fn_unindent_bytes() { + let b = b" + line one + line two"; + assert_eq!(unindent_bytes(b), b"line one\nline two"); + + let b = b"\n\t\t\tline one\n\t\t\tline two"; + assert_eq!(unindent_bytes(b), b"line one\nline two"); +} + +#[test] +fn trait_unindent_str() { + let s = " + line one + line two"; + assert_eq!(s.unindent(), "line one\nline two"); + + let s = "\n\t\t\tline one\n\t\t\tline two"; + assert_eq!(s.unindent(), "line one\nline two"); +} + +#[test] +fn trait_unindent_bytes() { + let b = b" + line one + line two"; + assert_eq!(b.unindent(), b"line one\nline two"); + + let b = b"\n\t\t\tline one\n\t\t\tline two"; + assert_eq!(b.unindent(), b"line one\nline two"); +} + +#[test] +fn carriage_returns() { + let s = "\r\n\tline one\r\n\tline two"; + assert_eq!(unindent(s), "line one\r\nline two"); +} diff --git a/vendor/indoc/tests/test_writedoc.rs b/vendor/indoc/tests/test_writedoc.rs new file mode 100644 index 000000000..8d1946892 --- /dev/null +++ b/vendor/indoc/tests/test_writedoc.rs @@ -0,0 +1,57 @@ +#![allow(clippy::if_same_then_else)] + +use indoc::writedoc; +use std::fmt::Write as _; + +#[test] +fn test_write_to_string() { + let mut s = String::new(); + writedoc!( + s, + " + one + two + ", + ) + .unwrap(); + + let expected = "one\ntwo\n"; + assert_eq!(s, expected); +} + +#[test] +fn test_format_args() { + let mut s = String::new(); + writedoc!( + s, + " + {} + {} + ", + 0, + 0, + ) + .unwrap(); + + let expected = "0\n0\n"; + assert_eq!(s, expected); +} + +#[test] +fn test_angle_bracket_parsing() { + const ZERO: usize = 0; + + struct Pair(A, B); + impl Pair<(), ()> { + const ONE: usize = 1; + } + + let mut s = String::new(); + let _ = writedoc! { + if ZERO < Pair::<(), ()>::ONE { &mut s } else { &mut s }, + "writedoc", + }; + + let expected = "writedoc"; + assert_eq!(s, expected); +} diff --git a/vendor/indoc/tests/ui/no-arguments.rs b/vendor/indoc/tests/ui/no-arguments.rs new file mode 100644 index 000000000..ea394d8f2 --- /dev/null +++ b/vendor/indoc/tests/ui/no-arguments.rs @@ -0,0 +1,5 @@ +use indoc::indoc; + +fn main() { + indoc!(); +} diff --git a/vendor/indoc/tests/ui/no-arguments.stderr b/vendor/indoc/tests/ui/no-arguments.stderr new file mode 100644 index 000000000..110e44106 --- /dev/null +++ b/vendor/indoc/tests/ui/no-arguments.stderr @@ -0,0 +1,7 @@ +error: unexpected end of macro invocation, expected format string + --> tests/ui/no-arguments.rs:4:5 + | +4 | indoc!(); + | ^^^^^^^^ + | + = note: this error originates in the macro `indoc` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/vendor/indoc/tests/ui/non-lit.rs b/vendor/indoc/tests/ui/non-lit.rs new file mode 100644 index 000000000..d51072d88 --- /dev/null +++ b/vendor/indoc/tests/ui/non-lit.rs @@ -0,0 +1,5 @@ +use indoc::indoc; + +fn main() { + indoc!(fail); +} diff --git a/vendor/indoc/tests/ui/non-lit.stderr b/vendor/indoc/tests/ui/non-lit.stderr new file mode 100644 index 000000000..ba1b7466c --- /dev/null +++ b/vendor/indoc/tests/ui/non-lit.stderr @@ -0,0 +1,5 @@ +error: argument must be a single string literal + --> tests/ui/non-lit.rs:4:12 + | +4 | indoc!(fail); + | ^^^^ diff --git a/vendor/indoc/tests/ui/non-string.rs b/vendor/indoc/tests/ui/non-string.rs new file mode 100644 index 000000000..174ea95a8 --- /dev/null +++ b/vendor/indoc/tests/ui/non-string.rs @@ -0,0 +1,5 @@ +use indoc::indoc; + +fn main() { + indoc!(64); +} diff --git a/vendor/indoc/tests/ui/non-string.stderr b/vendor/indoc/tests/ui/non-string.stderr new file mode 100644 index 000000000..4c1d4279c --- /dev/null +++ b/vendor/indoc/tests/ui/non-string.stderr @@ -0,0 +1,5 @@ +error: argument must be a single string literal + --> tests/ui/non-string.rs:4:12 + | +4 | indoc!(64); + | ^^ diff --git a/vendor/indoc/tests/ui/printdoc-binary.rs b/vendor/indoc/tests/ui/printdoc-binary.rs new file mode 100644 index 000000000..24e500e66 --- /dev/null +++ b/vendor/indoc/tests/ui/printdoc-binary.rs @@ -0,0 +1,5 @@ +use indoc::printdoc; + +fn main() { + printdoc!(b""); +} diff --git a/vendor/indoc/tests/ui/printdoc-binary.stderr b/vendor/indoc/tests/ui/printdoc-binary.stderr new file mode 100644 index 000000000..a1fb07862 --- /dev/null +++ b/vendor/indoc/tests/ui/printdoc-binary.stderr @@ -0,0 +1,5 @@ +error: byte strings are not supported in formatting macros + --> tests/ui/printdoc-binary.rs:4:15 + | +4 | printdoc!(b""); + | ^^^ diff --git a/vendor/indoc/tests/ui/printdoc-extra-arg.rs b/vendor/indoc/tests/ui/printdoc-extra-arg.rs new file mode 100644 index 000000000..661e3a0b6 --- /dev/null +++ b/vendor/indoc/tests/ui/printdoc-extra-arg.rs @@ -0,0 +1,5 @@ +use indoc::printdoc; + +fn main() { + printdoc!("", 0); +} diff --git a/vendor/indoc/tests/ui/printdoc-extra-arg.stderr b/vendor/indoc/tests/ui/printdoc-extra-arg.stderr new file mode 100644 index 000000000..94aaabe92 --- /dev/null +++ b/vendor/indoc/tests/ui/printdoc-extra-arg.stderr @@ -0,0 +1,7 @@ +error: argument never used + --> tests/ui/printdoc-extra-arg.rs:4:19 + | +4 | printdoc!("", 0); + | -- ^ argument never used + | | + | formatting specifier missing diff --git a/vendor/indoc/tests/ui/printdoc-no-arg.rs b/vendor/indoc/tests/ui/printdoc-no-arg.rs new file mode 100644 index 000000000..90ea148a1 --- /dev/null +++ b/vendor/indoc/tests/ui/printdoc-no-arg.rs @@ -0,0 +1,5 @@ +use indoc::printdoc; + +fn main() { + printdoc!("{}"); +} diff --git a/vendor/indoc/tests/ui/printdoc-no-arg.stderr b/vendor/indoc/tests/ui/printdoc-no-arg.stderr new file mode 100644 index 000000000..19d0ea543 --- /dev/null +++ b/vendor/indoc/tests/ui/printdoc-no-arg.stderr @@ -0,0 +1,5 @@ +error: 1 positional argument in format string, but no arguments were given + --> tests/ui/printdoc-no-arg.rs:4:16 + | +4 | printdoc!("{}"); + | ^^ diff --git a/vendor/indoc/tests/ui/printdoc-no-display.rs b/vendor/indoc/tests/ui/printdoc-no-display.rs new file mode 100644 index 000000000..22c3ebc0e --- /dev/null +++ b/vendor/indoc/tests/ui/printdoc-no-display.rs @@ -0,0 +1,7 @@ +use indoc::printdoc; + +struct NoDisplay; + +fn main() { + printdoc!("{}", NoDisplay); +} diff --git a/vendor/indoc/tests/ui/printdoc-no-display.stderr b/vendor/indoc/tests/ui/printdoc-no-display.stderr new file mode 100644 index 000000000..1e0fee569 --- /dev/null +++ b/vendor/indoc/tests/ui/printdoc-no-display.stderr @@ -0,0 +1,9 @@ +error[E0277]: `NoDisplay` doesn't implement `std::fmt::Display` + --> tests/ui/printdoc-no-display.rs:6:21 + | +6 | printdoc!("{}", NoDisplay); + | ^^^^^^^^^ `NoDisplay` cannot be formatted with the default formatter + | + = help: the trait `std::fmt::Display` is not implemented for `NoDisplay` + = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead + = note: this error originates in the macro `$crate::format_args` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/vendor/indoc/tests/ui/printdoc-no-named-arg.rs b/vendor/indoc/tests/ui/printdoc-no-named-arg.rs new file mode 100644 index 000000000..e4d5d9799 --- /dev/null +++ b/vendor/indoc/tests/ui/printdoc-no-named-arg.rs @@ -0,0 +1,5 @@ +use indoc::printdoc; + +fn main() { + printdoc!("{named}"); +} diff --git a/vendor/indoc/tests/ui/printdoc-no-named-arg.stderr b/vendor/indoc/tests/ui/printdoc-no-named-arg.stderr new file mode 100644 index 000000000..bed418d92 --- /dev/null +++ b/vendor/indoc/tests/ui/printdoc-no-named-arg.stderr @@ -0,0 +1,5 @@ +error[E0425]: cannot find value `named` in this scope + --> tests/ui/printdoc-no-named-arg.rs:4:17 + | +4 | printdoc!("{named}"); + | ^^^^^ not found in this scope diff --git a/vendor/indoc/tests/ui/three-arguments.rs b/vendor/indoc/tests/ui/three-arguments.rs new file mode 100644 index 000000000..7bd11e2d2 --- /dev/null +++ b/vendor/indoc/tests/ui/three-arguments.rs @@ -0,0 +1,9 @@ +use indoc::indoc; + +fn main() { + indoc!(" + a + b + c + " 64 128); +} diff --git a/vendor/indoc/tests/ui/three-arguments.stderr b/vendor/indoc/tests/ui/three-arguments.stderr new file mode 100644 index 000000000..d3e8dbe65 --- /dev/null +++ b/vendor/indoc/tests/ui/three-arguments.stderr @@ -0,0 +1,5 @@ +error: unexpected tokens in macro invocation; indoc argument must be a single string literal + --> tests/ui/three-arguments.rs:8:11 + | +8 | " 64 128); + | ^^^^^^ diff --git a/vendor/indoc/tests/ui/two-arguments.rs b/vendor/indoc/tests/ui/two-arguments.rs new file mode 100644 index 000000000..f979fed42 --- /dev/null +++ b/vendor/indoc/tests/ui/two-arguments.rs @@ -0,0 +1,9 @@ +use indoc::indoc; + +fn main() { + indoc!(" + a + b + c + " 64); +} diff --git a/vendor/indoc/tests/ui/two-arguments.stderr b/vendor/indoc/tests/ui/two-arguments.stderr new file mode 100644 index 000000000..eccdecfca --- /dev/null +++ b/vendor/indoc/tests/ui/two-arguments.stderr @@ -0,0 +1,5 @@ +error: unexpected token in macro invocation; indoc argument must be a single string literal + --> tests/ui/two-arguments.rs:8:11 + | +8 | " 64); + | ^^ -- cgit v1.2.3