aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Vander Stoep <jeffv@google.com>2024-02-07 20:40:45 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2024-02-07 20:40:45 +0000
commit30f66a831933c8184b62fe22dec8194f5c103d71 (patch)
treef3a0f90985c584fac5318e01dfea8940b4a7d051
parent9c51e91db14f799148be8024aa6f5c30e56e8f5b (diff)
parenta73744146768cdd7c1cf8f997b1fb12341633377 (diff)
downloadtoml-main-16k.tar.gz
Upgrade toml to 0.8.10 am: a737441467HEADmastermain-16kmain
Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/toml/+/2953870 Change-Id: I8002ee5d4e302661c4f81134a68b3bac3b939ffc Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--.cargo_vcs_info.json2
-rw-r--r--Android.bp2
-rw-r--r--Cargo.lock58
-rw-r--r--Cargo.toml27
-rw-r--r--Cargo.toml.orig22
-rw-r--r--LICENSE-APACHE403
-rw-r--r--LICENSE-MIT38
-rw-r--r--METADATA22
-rw-r--r--src/fmt.rs32
-rw-r--r--src/macros.rs6
-rw-r--r--src/table.rs7
-rw-r--r--src/value.rs126
-rw-r--r--tests/decoder.rs5
-rw-r--r--tests/decoder_compliance.rs12
-rw-r--r--tests/encoder.rs5
-rw-r--r--tests/encoder_compliance.rs2
-rw-r--r--tests/testsuite/float.rs4
-rw-r--r--tests/testsuite/macros.rs15
-rw-r--r--tests/testsuite/pretty.rs12
-rw-r--r--tests/testsuite/serde.rs299
20 files changed, 745 insertions, 354 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json
index 9ceba26..b13342a 100644
--- a/.cargo_vcs_info.json
+++ b/.cargo_vcs_info.json
@@ -1,6 +1,6 @@
{
"git": {
- "sha1": "59ae12d8c1b3c79df6ae7a29d1841ae860cd7fb6"
+ "sha1": "7f3e276cfb664e7cd95e92a6634e53cd52a2bc71"
},
"path_in_vcs": "crates/toml"
} \ No newline at end of file
diff --git a/Android.bp b/Android.bp
index aedb04c..ac3d83b 100644
--- a/Android.bp
+++ b/Android.bp
@@ -5,7 +5,7 @@ rust_library_host {
name: "libtoml",
crate_name: "toml",
cargo_env_compat: true,
- cargo_pkg_version: "0.7.6",
+ cargo_pkg_version: "0.8.10",
srcs: ["src/lib.rs"],
edition: "2021",
features: [
diff --git a/Cargo.lock b/Cargo.lock
index 7bf0506..1cc97be 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -421,18 +421,18 @@ dependencies = [
[[package]]
name = "proc-macro2"
-version = "1.0.56"
+version = "1.0.67"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2b63bdb0cd06f1f4dedf69b254734f9b45af66e4a031e42a7480257d9898b435"
+checksum = "3d433d9f1a3e8c1263d9456598b16fec66f4acc9a74dacffd35c7bb09b3a1328"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
-version = "1.0.26"
+version = "1.0.33"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc"
+checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae"
dependencies = [
"proc-macro2",
]
@@ -470,9 +470,9 @@ dependencies = [
[[package]]
name = "ryu"
-version = "1.0.11"
+version = "1.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09"
+checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741"
[[package]]
name = "same-file"
@@ -485,22 +485,22 @@ dependencies = [
[[package]]
name = "serde"
-version = "1.0.160"
+version = "1.0.193"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "bb2f3770c8bce3bcda7e149193a069a0f4365bda1fa5cd88e03bca26afc1216c"
+checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
-version = "1.0.160"
+version = "1.0.193"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "291a097c63d8497e00160b166a967a4a79c64f3facdd01cbd7502231688d77df"
+checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.15",
+ "syn 2.0.41",
]
[[package]]
@@ -516,9 +516,9 @@ dependencies = [
[[package]]
name = "serde_spanned"
-version = "0.6.3"
+version = "0.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "96426c9936fd7a0124915f9185ea1d20aa9445cc9821142f0a73bc9207a2e186"
+checksum = "eb3622f419d1296904700073ea6cc23ad690adbd66f13ea683df73298736f0c1"
dependencies = [
"serde",
]
@@ -570,9 +570,9 @@ dependencies = [
[[package]]
name = "syn"
-version = "2.0.15"
+version = "2.0.41"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a34fcf3e8b60f57e6a14301a2e916d323af98b0ea63c599441eec8558660c822"
+checksum = "44c8b28c477cc3bf0e7966561e3460130e1255f7a1cf71931075f1c5e7a7e269"
dependencies = [
"proc-macro2",
"quote",
@@ -608,13 +608,14 @@ dependencies = [
[[package]]
name = "toml"
-version = "0.7.6"
+version = "0.8.10"
dependencies = [
"indexmap",
"serde",
"serde_json",
"serde_spanned",
"snapbox",
+ "toml-test-data",
"toml-test-harness",
"toml_datetime",
"toml_edit",
@@ -622,29 +623,30 @@ dependencies = [
[[package]]
name = "toml-test"
-version = "0.3.4"
+version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "37351256790aa1dbd6d60f4ff08e55e7f372e292f3e9040d6e077463d9a779c3"
+checksum = "1ec3892835fb31e181a87e1758275a64b0d7c6c9e9618aeb61a647bd487314c0"
dependencies = [
"chrono",
+ "ryu",
"serde",
"serde_json",
]
[[package]]
name = "toml-test-data"
-version = "1.3.0"
+version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "93f351b6d6005ee802b0d4a53ca1cdf05636f441df4d299e62cba57f1da52646"
+checksum = "c6b5bad99e813ce8c67d1d67c9b9f37c8451933f45eae0ab2b3583975f1cc15d"
dependencies = [
"include_dir",
]
[[package]]
name = "toml-test-harness"
-version = "0.4.3"
+version = "0.4.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0e00fda5710922fe6b3005bf6a5050c303d6f9625249c37b7386e8818f4af675"
+checksum = "1be4b8d761dee51b4694e9f1d622a1d7f9c135a8b8265459e16d09ac5b16a05d"
dependencies = [
"ignore",
"libtest-mimic",
@@ -654,18 +656,18 @@ dependencies = [
[[package]]
name = "toml_datetime"
-version = "0.6.3"
+version = "0.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b"
+checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1"
dependencies = [
"serde",
]
[[package]]
name = "toml_edit"
-version = "0.19.12"
+version = "0.22.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c500344a19072298cd05a7224b3c0c629348b78692bf48466c5238656e315a78"
+checksum = "d8dc77def39ce6079c2d0c866cc20848f591b1898f153c9fe7c4f29e1154510b"
dependencies = [
"indexmap",
"serde",
@@ -883,9 +885,9 @@ checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a"
[[package]]
name = "winnow"
-version = "0.4.6"
+version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "61de7bac303dc551fe038e2b3cef0f571087a47571ea6e79a87692ac99b99699"
+checksum = "81fac9742fd1ad1bd9643b991319f72dd031016d44b77039a26977eb667141e7"
dependencies = [
"memchr",
]
diff --git a/Cargo.toml b/Cargo.toml
index 02f89eb..77f028d 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -11,9 +11,9 @@
[package]
edition = "2021"
-rust-version = "1.64.0"
+rust-version = "1.69"
name = "toml"
-version = "0.7.6"
+version = "0.8.10"
authors = ["Alex Crichton <alex@alexcrichton.com>"]
include = [
"build.rs",
@@ -47,6 +47,7 @@ license = "MIT OR Apache-2.0"
repository = "https://github.com/toml-rs/toml"
[package.metadata.docs.rs]
+all-features = true
rustdoc-args = [
"--cfg",
"docsrs",
@@ -124,17 +125,18 @@ optional = true
version = "1.0.145"
[dependencies.serde_spanned]
-version = "0.6.3"
+version = "0.6.5"
features = ["serde"]
[dependencies.toml_datetime]
-version = "0.6.3"
+version = "0.6.5"
features = ["serde"]
[dependencies.toml_edit]
-version = "0.19.12"
+version = "0.22.0"
features = ["serde"]
optional = true
+default-features = false
[dev-dependencies.serde]
version = "1.0.160"
@@ -146,14 +148,23 @@ version = "1.0.96"
[dev-dependencies.snapbox]
version = "0.4.11"
+[dev-dependencies.toml-test-data]
+version = "1.8.0"
+
[dev-dependencies.toml-test-harness]
-version = "0.4.3"
+version = "0.4.8"
[features]
default = [
"parse",
"display",
]
-display = ["dep:toml_edit"]
-parse = ["dep:toml_edit"]
+display = [
+ "dep:toml_edit",
+ "toml_edit?/display",
+]
+parse = [
+ "dep:toml_edit",
+ "toml_edit?/parse",
+]
preserve_order = ["indexmap"]
diff --git a/Cargo.toml.orig b/Cargo.toml.orig
index 424f035..73ef939 100644
--- a/Cargo.toml.orig
+++ b/Cargo.toml.orig
@@ -1,6 +1,6 @@
[package]
name = "toml"
-version = "0.7.6"
+version = "0.8.10"
keywords = ["encoding", "toml"]
categories = ["encoding", "parser-implementations", "parsing", "config"]
description = """
@@ -16,6 +16,10 @@ edition.workspace = true
rust-version.workspace = true
include.workspace = true
+[package.metadata.docs.rs]
+all-features = true
+rustdoc-args = ["--cfg", "docsrs"]
+
[package.metadata.release]
pre-release-replacements = [
{file="CHANGELOG.md", search="Unreleased", replace="{{version}}", min=1},
@@ -25,13 +29,10 @@ pre-release-replacements = [
{file="CHANGELOG.md", search="<!-- next-url -->", replace="<!-- next-url -->\n[Unreleased]: https://github.com/toml-rs/toml/compare/{{tag_name}}...HEAD", exactly=1},
]
-[package.metadata.docs.rs]
-rustdoc-args = ["--cfg", "docsrs"]
-
[features]
default = ["parse", "display"]
-parse = ["dep:toml_edit"]
-display = ["dep:toml_edit"]
+parse = ["dep:toml_edit", "toml_edit?/parse"]
+display = ["dep:toml_edit", "toml_edit?/display"]
# Use indexmap rather than BTreeMap as the map type of toml::Value.
# This allows data to be read into a Value and written back to a TOML string
@@ -41,14 +42,15 @@ preserve_order = ["indexmap"]
[dependencies]
serde = "1.0.145"
indexmap = { version = "2.0.0", optional = true }
-toml_edit = { version = "0.19.12", path = "../toml_edit", features = ["serde"], optional = true }
-toml_datetime = { version = "0.6.3", path = "../toml_datetime", features = ["serde"] }
-serde_spanned = { version = "0.6.3", path = "../serde_spanned", features = ["serde"] }
+toml_edit = { version = "0.22.0", path = "../toml_edit", default-features = false, features = ["serde"], optional = true }
+toml_datetime = { version = "0.6.5", path = "../toml_datetime", features = ["serde"] }
+serde_spanned = { version = "0.6.5", path = "../serde_spanned", features = ["serde"] }
[dev-dependencies]
serde = { version = "1.0.160", features = ["derive"] }
serde_json = "1.0.96"
-toml-test-harness = "0.4.3"
+toml-test-harness = "0.4.8"
+toml-test-data = "1.8.0"
snapbox = "0.4.11"
[[test]]
diff --git a/LICENSE-APACHE b/LICENSE-APACHE
index 16fe87b..8f71f43 100644
--- a/LICENSE-APACHE
+++ b/LICENSE-APACHE
@@ -1,201 +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.
+ 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/LICENSE-MIT b/LICENSE-MIT
index 39e0ed6..a2d0108 100644
--- a/LICENSE-MIT
+++ b/LICENSE-MIT
@@ -1,25 +1,19 @@
-Copyright (c) 2014 Alex Crichton
+Copyright (c) Individual 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:
+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 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.
+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/METADATA b/METADATA
index fad1206..89d0bf3 100644
--- a/METADATA
+++ b/METADATA
@@ -1,20 +1,24 @@
+# This project was upgraded with external_updater.
+# Usage: tools/external_updater/updater.sh update external/rust/crates/toml
+# For more info, check https://cs.android.com/android/platform/superproject/+/main:tools/external_updater/README.md
+
name: "toml"
description: "()"
third_party {
+ license_type: NOTICE
+ last_upgrade_date {
+ year: 2024
+ month: 2
+ day: 7
+ }
identifier {
type: "crates.io"
- value: "https://crates.io/crates/toml"
+ value: "https://static.crates.io/crates/toml/toml-0.8.10.crate"
+ version: "0.7.6"
}
identifier {
type: "Archive"
value: "https://static.crates.io/crates/toml/toml-0.7.6.crate"
- }
- version: "0.7.6"
- # Dual-licensed, using the least restrictive per go/thirdpartylicenses#same.
- license_type: NOTICE
- last_upgrade_date {
- year: 2023
- month: 8
- day: 23
+ version: "0.8.10"
}
}
diff --git a/src/fmt.rs b/src/fmt.rs
index 0e96bf0..281cb59 100644
--- a/src/fmt.rs
+++ b/src/fmt.rs
@@ -1,6 +1,7 @@
#[derive(Copy, Clone, Default)]
pub(crate) struct DocumentFormatter {
pub(crate) multiline_array: bool,
+ is_value: bool,
}
impl toml_edit::visit_mut::VisitMut for DocumentFormatter {
@@ -9,21 +10,26 @@ impl toml_edit::visit_mut::VisitMut for DocumentFormatter {
}
fn visit_item_mut(&mut self, node: &mut toml_edit::Item) {
- let other = std::mem::take(node);
- let other = match other.into_table().map(toml_edit::Item::Table) {
- Ok(i) => i,
- Err(i) => i,
- };
- let other = match other
- .into_array_of_tables()
- .map(toml_edit::Item::ArrayOfTables)
- {
- Ok(i) => i,
- Err(i) => i,
- };
- *node = other;
+ let is_parent_value = self.is_value;
+ if !is_parent_value {
+ let other = std::mem::take(node);
+ let other = match other.into_table().map(toml_edit::Item::Table) {
+ Ok(i) => i,
+ Err(i) => i,
+ };
+ let other = match other
+ .into_array_of_tables()
+ .map(toml_edit::Item::ArrayOfTables)
+ {
+ Ok(i) => i,
+ Err(i) => i,
+ };
+ self.is_value = other.is_value();
+ *node = other;
+ }
toml_edit::visit_mut::visit_item_mut(self, node);
+ self.is_value = is_parent_value;
}
fn visit_table_mut(&mut self, node: &mut toml_edit::Table) {
diff --git a/src/macros.rs b/src/macros.rs
index d86cc52..a295970 100644
--- a/src/macros.rs
+++ b/src/macros.rs
@@ -198,15 +198,15 @@ macro_rules! toml_internal {
}};
(@value (-nan)) => {
- $crate::Value::Float(-::std::f64::NAN)
+ $crate::Value::Float(::std::f64::NAN.copysign(-1.0))
};
(@value (nan)) => {
- $crate::Value::Float(::std::f64::NAN)
+ $crate::Value::Float(::std::f64::NAN.copysign(1.0))
};
(@value nan) => {
- $crate::Value::Float(::std::f64::NAN)
+ $crate::Value::Float(::std::f64::NAN.copysign(1.0))
};
(@value (-inf)) => {
diff --git a/src/table.rs b/src/table.rs
index a2d392b..ac70532 100644
--- a/src/table.rs
+++ b/src/table.rs
@@ -7,8 +7,11 @@ use crate::map::Map;
use crate::Value;
/// Type representing a TOML table, payload of the `Value::Table` variant.
-/// By default it is backed by a BTreeMap, enable the `preserve_order` feature
-/// to use a LinkedHashMap instead.
+///
+/// By default it entries are stored in
+/// [lexicographic order](https://doc.rust-lang.org/std/primitive.str.html#impl-Ord-for-str)
+/// of the keys. Enable the `preserve_order` feature to store entries in the order they appear in
+/// the source file.
pub type Table = Map<String, Value>;
impl Table {
diff --git a/src/value.rs b/src/value.rs
index 2785d9d..e6f832a 100644
--- a/src/value.rs
+++ b/src/value.rs
@@ -770,6 +770,13 @@ impl<'de> serde::de::VariantAccess<'de> for MapEnumDeserializer {
fn unit_variant(self) -> Result<(), Self::Error> {
use de::Error;
match self.value {
+ Value::Array(values) => {
+ if values.is_empty() {
+ Ok(())
+ } else {
+ Err(Error::custom("expected empty array"))
+ }
+ }
Value::Table(values) => {
if values.is_empty() {
Ok(())
@@ -797,8 +804,15 @@ impl<'de> serde::de::VariantAccess<'de> for MapEnumDeserializer {
{
use de::Error;
match self.value {
+ Value::Array(values) => {
+ if values.len() == len {
+ serde::de::Deserializer::deserialize_seq(values.into_deserializer(), visitor)
+ } else {
+ Err(Error::custom(format!("expected tuple with length {}", len)))
+ }
+ }
Value::Table(values) => {
- let tuple_values = values
+ let tuple_values: Result<Vec<_>, _> = values
.into_iter()
.enumerate()
.map(|(index, (key, value))| match key.parse::<usize>() {
@@ -808,17 +822,8 @@ impl<'de> serde::de::VariantAccess<'de> for MapEnumDeserializer {
index, key
))),
})
- // Fold all values into a `Vec`, or return the first error.
- .fold(Ok(Vec::with_capacity(len)), |result, value_result| {
- result.and_then(move |mut tuple_values| match value_result {
- Ok(value) => {
- tuple_values.push(value);
- Ok(tuple_values)
- }
- // `Result<de::Value, Self::Error>` to `Result<Vec<_>, Self::Error>`
- Err(e) => Err(e),
- })
- })?;
+ .collect();
+ let tuple_values = tuple_values?;
if tuple_values.len() == len {
serde::de::Deserializer::deserialize_seq(
@@ -870,10 +875,10 @@ impl ser::Serializer for ValueSerializer {
type SerializeSeq = ValueSerializeVec;
type SerializeTuple = ValueSerializeVec;
type SerializeTupleStruct = ValueSerializeVec;
- type SerializeTupleVariant = ValueSerializeVec;
+ type SerializeTupleVariant = ValueSerializeTupleVariant;
type SerializeMap = ValueSerializeMap;
type SerializeStruct = ValueSerializeMap;
- type SerializeStructVariant = ser::Impossible<Value, crate::ser::Error>;
+ type SerializeStructVariant = ValueSerializeStructVariant;
fn serialize_bool(self, value: bool) -> Result<Value, crate::ser::Error> {
Ok(Value::Boolean(value))
@@ -916,10 +921,14 @@ impl ser::Serializer for ValueSerializer {
}
fn serialize_f32(self, value: f32) -> Result<Value, crate::ser::Error> {
- self.serialize_f64(value.into())
+ self.serialize_f64(value as f64)
}
- fn serialize_f64(self, value: f64) -> Result<Value, crate::ser::Error> {
+ fn serialize_f64(self, mut value: f64) -> Result<Value, crate::ser::Error> {
+ // Discard sign of NaN. See ValueSerializer::serialize_f64.
+ if value.is_nan() {
+ value = value.copysign(1.0);
+ }
Ok(Value::Float(value))
}
@@ -1015,10 +1024,10 @@ impl ser::Serializer for ValueSerializer {
self,
_name: &'static str,
_variant_index: u32,
- _variant: &'static str,
+ variant: &'static str,
len: usize,
) -> Result<Self::SerializeTupleVariant, crate::ser::Error> {
- self.serialize_seq(Some(len))
+ Ok(ValueSerializeTupleVariant::tuple(variant, len))
}
fn serialize_map(self, _len: Option<usize>) -> Result<Self::SerializeMap, crate::ser::Error> {
@@ -1040,12 +1049,12 @@ impl ser::Serializer for ValueSerializer {
fn serialize_struct_variant(
self,
- name: &'static str,
+ _name: &'static str,
_variant_index: u32,
- _variant: &'static str,
- _len: usize,
+ variant: &'static str,
+ len: usize,
) -> Result<Self::SerializeStructVariant, crate::ser::Error> {
- Err(crate::ser::Error::unsupported_type(Some(name)))
+ Ok(ValueSerializeStructVariant::struct_(variant, len))
}
}
@@ -1453,3 +1462,76 @@ impl<'a, 'de> de::Visitor<'de> for DatetimeOrTable<'a> {
}
}
}
+
+type ValueSerializeTupleVariant = ValueSerializeVariant<ValueSerializeVec>;
+type ValueSerializeStructVariant = ValueSerializeVariant<ValueSerializeMap>;
+
+struct ValueSerializeVariant<T> {
+ variant: &'static str,
+ inner: T,
+}
+
+impl ValueSerializeVariant<ValueSerializeVec> {
+ pub(crate) fn tuple(variant: &'static str, len: usize) -> Self {
+ Self {
+ variant,
+ inner: ValueSerializeVec {
+ vec: Vec::with_capacity(len),
+ },
+ }
+ }
+}
+
+impl ValueSerializeVariant<ValueSerializeMap> {
+ pub(crate) fn struct_(variant: &'static str, len: usize) -> Self {
+ Self {
+ variant,
+ inner: ValueSerializeMap {
+ ser: SerializeMap {
+ map: Table::with_capacity(len),
+ next_key: None,
+ },
+ },
+ }
+ }
+}
+
+impl serde::ser::SerializeTupleVariant for ValueSerializeVariant<ValueSerializeVec> {
+ type Ok = crate::Value;
+ type Error = crate::ser::Error;
+
+ fn serialize_field<T: ?Sized>(&mut self, value: &T) -> Result<(), Self::Error>
+ where
+ T: serde::ser::Serialize,
+ {
+ serde::ser::SerializeSeq::serialize_element(&mut self.inner, value)
+ }
+
+ fn end(self) -> Result<Self::Ok, Self::Error> {
+ let inner = serde::ser::SerializeSeq::end(self.inner)?;
+ let mut table = Table::new();
+ table.insert(self.variant.to_owned(), inner);
+ Ok(Value::Table(table))
+ }
+}
+
+impl serde::ser::SerializeStructVariant for ValueSerializeVariant<ValueSerializeMap> {
+ type Ok = crate::Value;
+ type Error = crate::ser::Error;
+
+ #[inline]
+ fn serialize_field<T>(&mut self, key: &'static str, value: &T) -> Result<(), Self::Error>
+ where
+ T: serde::ser::Serialize + ?Sized,
+ {
+ serde::ser::SerializeStruct::serialize_field(&mut self.inner, key, value)
+ }
+
+ #[inline]
+ fn end(self) -> Result<Self::Ok, Self::Error> {
+ let inner = serde::ser::SerializeStruct::end(self.inner)?;
+ let mut table = Table::new();
+ table.insert(self.variant.to_owned(), inner);
+ Ok(Value::Table(table))
+ }
+}
diff --git a/tests/decoder.rs b/tests/decoder.rs
index fe6db3f..5af906f 100644
--- a/tests/decoder.rs
+++ b/tests/decoder.rs
@@ -11,9 +11,10 @@ impl toml_test_harness::Decoder for Decoder {
fn decode(&self, data: &[u8]) -> Result<toml_test_harness::Decoded, toml_test_harness::Error> {
let data = std::str::from_utf8(data).map_err(toml_test_harness::Error::new)?;
let document = data
- .parse::<toml::Value>()
+ .parse::<toml::Table>()
.map_err(toml_test_harness::Error::new)?;
- value_to_decoded(&document)
+ let value = toml::Value::Table(document);
+ value_to_decoded(&value)
}
}
diff --git a/tests/decoder_compliance.rs b/tests/decoder_compliance.rs
index 5d4fc2a..5828883 100644
--- a/tests/decoder_compliance.rs
+++ b/tests/decoder_compliance.rs
@@ -4,16 +4,8 @@ mod decoder;
fn main() {
let decoder = decoder::Decoder;
let mut harness = toml_test_harness::DecoderHarness::new(decoder);
- harness
- .ignore([
- "valid/spec/float-0.toml",
- // Unreleased
- "valid/string/escape-esc.toml",
- "valid/string/hex-escape.toml",
- "valid/datetime/no-seconds.toml",
- "valid/inline-table/newline.toml",
- ])
- .unwrap();
+ harness.version("1.0.0");
+ harness.ignore([]).unwrap();
harness.test();
}
diff --git a/tests/encoder.rs b/tests/encoder.rs
index eda6296..e76a74a 100644
--- a/tests/encoder.rs
+++ b/tests/encoder.rs
@@ -10,7 +10,10 @@ impl toml_test_harness::Encoder for Encoder {
fn encode(&self, data: toml_test_harness::Decoded) -> Result<String, toml_test_harness::Error> {
let value = from_decoded(&data)?;
- let s = toml::to_string(&value).map_err(toml_test_harness::Error::new)?;
+ let toml::Value::Table(document) = value else {
+ return Err(toml_test_harness::Error::new("no root table"));
+ };
+ let s = toml::to_string(&document).map_err(toml_test_harness::Error::new)?;
Ok(s)
}
}
diff --git a/tests/encoder_compliance.rs b/tests/encoder_compliance.rs
index 3807248..c593e59 100644
--- a/tests/encoder_compliance.rs
+++ b/tests/encoder_compliance.rs
@@ -6,7 +6,7 @@ fn main() {
let encoder = encoder::Encoder;
let decoder = decoder::Decoder;
let mut harness = toml_test_harness::EncoderHarness::new(encoder, decoder);
- harness.ignore(["valid/spec/float-0.toml"]).unwrap();
+ harness.version("1.0.0");
harness.test();
}
diff --git a/tests/testsuite/float.rs b/tests/testsuite/float.rs
index d008134..1d9ce1a 100644
--- a/tests/testsuite/float.rs
+++ b/tests/testsuite/float.rs
@@ -47,7 +47,7 @@ macro_rules! float_inf_tests {
assert!(inf.sf5.is_nan());
assert!(inf.sf5.is_sign_positive());
assert!(inf.sf6.is_nan());
- assert!(inf.sf6.is_sign_negative());
+ assert!(inf.sf6.is_sign_negative()); // NOTE: serializes to just `nan`
assert_eq!(inf.sf7, 0.0);
assert!(inf.sf7.is_sign_positive());
@@ -63,7 +63,7 @@ sf2 = inf
sf3 = -inf
sf4 = nan
sf5 = nan
-sf6 = -nan
+sf6 = nan
sf7 = 0.0
sf8 = -0.0
"
diff --git a/tests/testsuite/macros.rs b/tests/testsuite/macros.rs
index 5100705..e002cd9 100644
--- a/tests/testsuite/macros.rs
+++ b/tests/testsuite/macros.rs
@@ -198,9 +198,18 @@ fn test_nan() {
sf5 = +nan
sf6 = -nan
};
- assert!(actual["sf4"].as_float().unwrap().is_nan());
- assert!(actual["sf5"].as_float().unwrap().is_nan());
- assert!(actual["sf6"].as_float().unwrap().is_nan());
+
+ let sf4 = actual["sf4"].as_float().unwrap();
+ assert!(sf4.is_nan());
+ assert!(sf4.is_sign_positive());
+
+ let sf5 = actual["sf5"].as_float().unwrap();
+ assert!(sf5.is_nan());
+ assert!(sf5.is_sign_positive());
+
+ let sf6 = actual["sf6"].as_float().unwrap();
+ assert!(sf6.is_nan());
+ assert!(sf6.is_sign_negative());
}
#[test]
diff --git a/tests/testsuite/pretty.rs b/tests/testsuite/pretty.rs
index 3ae772b..369888f 100644
--- a/tests/testsuite/pretty.rs
+++ b/tests/testsuite/pretty.rs
@@ -47,7 +47,7 @@ fn pretty_std() {
assert_eq(toml, &result);
}
-const PRETTY_TRICKY: &str = r##"[example]
+const PRETTY_TRICKY: &str = r#"[example]
f = "\f"
glass = """
Nothing too unusual, except that I can eat glass in:
@@ -72,7 +72,7 @@ This has a ''' in it and \"\"\" cuz it's tricky yo
Also ' and \" because why not
this is the fourth line
"""
-"##;
+"#;
#[test]
fn pretty_tricky() {
@@ -85,7 +85,7 @@ fn pretty_tricky() {
assert_eq(toml, &result);
}
-const PRETTY_TABLE_ARRAY: &str = r##"[[array]]
+const PRETTY_TABLE_ARRAY: &str = r#"[[array]]
key = "foo"
[[array]]
@@ -96,7 +96,7 @@ doc = "this is a table"
[example]
single = "this is a single line string"
-"##;
+"#;
#[test]
fn pretty_table_array() {
@@ -109,7 +109,7 @@ fn pretty_table_array() {
assert_eq(toml, &result);
}
-const TABLE_ARRAY: &str = r##"[[array]]
+const TABLE_ARRAY: &str = r#"[[array]]
key = "foo"
[[array]]
@@ -120,7 +120,7 @@ doc = "this is a table"
[example]
single = "this is a single line string"
-"##;
+"#;
#[test]
fn table_array() {
diff --git a/tests/testsuite/serde.rs b/tests/testsuite/serde.rs
index 6e927f7..d7f8bc4 100644
--- a/tests/testsuite/serde.rs
+++ b/tests/testsuite/serde.rs
@@ -21,19 +21,26 @@ macro_rules! equivalent {
let toml = $toml;
let literal = $literal;
- // In/out of Value is equivalent
- println!("try_from");
- assert_eq!(t!(Table::try_from(literal.clone())), toml);
- println!("try_into");
- assert_eq!(literal, t!(toml.clone().try_into()));
-
// Through a string equivalent
println!("to_string");
- snapbox::assert_eq(t!(toml::to_string(&toml)), t!(toml::to_string(&literal)));
+ snapbox::assert_eq(t!(toml::to_string(&literal)), t!(toml::to_string(&toml)));
println!("literal, from_str(toml)");
assert_eq!(literal, t!(toml::from_str(&t!(toml::to_string(&toml)))));
- println!("toml, from_str(toml)");
- assert_eq!(toml, t!(toml::from_str(&t!(toml::to_string(&toml)))));
+ println!("toml, from_str(literal)");
+ assert_eq!(toml, t!(toml::from_str(&t!(toml::to_string(&literal)))));
+
+ // In/out of Value is equivalent
+ println!("Table::try_from(literal)");
+ assert_eq!(toml, t!(Table::try_from(literal.clone())));
+ println!("Value::try_from(literal)");
+ assert_eq!(
+ Value::Table(toml.clone()),
+ t!(Value::try_from(literal.clone()))
+ );
+ println!("toml.try_into()");
+ assert_eq!(literal, t!(toml.clone().try_into()));
+ println!("Value::Table(toml).try_into()");
+ assert_eq!(literal, t!(Value::Table(toml.clone()).try_into()));
}};
}
@@ -377,6 +384,106 @@ fn parse_enum_string() {
}
#[test]
+fn parse_tuple_variant() {
+ #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
+ struct Document {
+ inner: Vec<Enum>,
+ }
+
+ #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
+ enum Enum {
+ Int(i32, i32),
+ String(String, String),
+ }
+
+ let input = Document {
+ inner: vec![
+ Enum::Int(1, 1),
+ Enum::String("2".to_owned(), "2".to_owned()),
+ ],
+ };
+ let expected = "[[inner]]
+Int = [1, 1]
+
+[[inner]]
+String = [\"2\", \"2\"]
+";
+ let raw = toml::to_string(&input).unwrap();
+ snapbox::assert_eq(expected, raw);
+
+ equivalent! {
+ Document {
+ inner: vec![
+ Enum::Int(1, 1),
+ Enum::String("2".to_owned(), "2".to_owned()),
+ ],
+ },
+ map! {
+ inner: vec![
+ map! { Int: [1, 1] },
+ map! { String: ["2".to_owned(), "2".to_owned()] },
+ ]
+ },
+ }
+}
+
+#[test]
+fn parse_struct_variant() {
+ #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
+ struct Document {
+ inner: Vec<Enum>,
+ }
+
+ #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
+ enum Enum {
+ Int { first: i32, second: i32 },
+ String { first: String, second: String },
+ }
+
+ let input = Document {
+ inner: vec![
+ Enum::Int {
+ first: 1,
+ second: 1,
+ },
+ Enum::String {
+ first: "2".to_owned(),
+ second: "2".to_owned(),
+ },
+ ],
+ };
+ let expected = "[[inner]]
+
+[inner.Int]
+first = 1
+second = 1
+
+[[inner]]
+
+[inner.String]
+first = \"2\"
+second = \"2\"
+";
+ let raw = toml::to_string(&input).unwrap();
+ snapbox::assert_eq(expected, raw);
+
+ equivalent! {
+ Document {
+ inner: vec![
+ Enum::Int { first: 1, second: 1 },
+ Enum::String { first: "2".to_owned(), second: "2".to_owned() },
+ ],
+ },
+ map! {
+ inner: vec![
+ map! { Int: map! { first: 1, second: 1 } },
+ map! { String: map! { first: "2".to_owned(), second: "2".to_owned() } },
+ ]
+ },
+ }
+}
+
+#[test]
#[cfg(feature = "preserve_order")]
fn map_key_unit_variants() {
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Clone, PartialOrd, Ord)]
@@ -635,6 +742,25 @@ fn newtype_variant() {
}
}
+#[test]
+fn newtype_key() {
+ #[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Serialize, Deserialize)]
+ struct NewType(String);
+
+ type CustomKeyMap = std::collections::BTreeMap<NewType, u32>;
+
+ equivalent! {
+ [
+ (NewType("x".to_owned()), 1),
+ (NewType("y".to_owned()), 2),
+ ].into_iter().collect::<CustomKeyMap>(),
+ map! {
+ x: Value::Integer(1),
+ y: Value::Integer(2)
+ },
+ }
+}
+
#[derive(Debug, Default, PartialEq, Serialize, Deserialize)]
struct CanBeEmpty {
a: Option<String>,
@@ -1094,3 +1220,158 @@ fn datetime_offset_issue_496() {
let output = toml.to_string();
snapbox::assert_eq(original, output);
}
+
+#[test]
+fn serialize_array_with_none_value() {
+ #[derive(Serialize)]
+ struct Document {
+ values: Vec<Option<usize>>,
+ }
+
+ let input = Document {
+ values: vec![Some(1), Some(2), Some(3)],
+ };
+ let expected = "values = [1, 2, 3]\n";
+ let raw = toml::to_string(&input).unwrap();
+ snapbox::assert_eq(expected, raw);
+
+ let input = Document {
+ values: vec![Some(1), None, Some(3)],
+ };
+ let err = toml::to_string(&input).unwrap_err();
+ snapbox::assert_eq("unsupported None value", err.to_string());
+}
+
+#[test]
+fn serialize_array_with_optional_struct_field() {
+ #[derive(Debug, Deserialize, Serialize)]
+ struct Document {
+ values: Vec<OptionalField>,
+ }
+
+ #[derive(Debug, Deserialize, Serialize)]
+ struct OptionalField {
+ x: u8,
+ y: Option<u8>,
+ }
+
+ let input = Document {
+ values: vec![
+ OptionalField { x: 0, y: Some(4) },
+ OptionalField { x: 2, y: Some(5) },
+ OptionalField { x: 3, y: Some(7) },
+ ],
+ };
+ let expected = "\
+[[values]]
+x = 0
+y = 4
+
+[[values]]
+x = 2
+y = 5
+
+[[values]]
+x = 3
+y = 7
+";
+ let raw = toml::to_string(&input).unwrap();
+ snapbox::assert_eq(expected, raw);
+
+ let input = Document {
+ values: vec![
+ OptionalField { x: 0, y: Some(4) },
+ OptionalField { x: 2, y: None },
+ OptionalField { x: 3, y: Some(7) },
+ ],
+ };
+ let expected = "\
+[[values]]
+x = 0
+y = 4
+
+[[values]]
+x = 2
+
+[[values]]
+x = 3
+y = 7
+";
+ let raw = toml::to_string(&input).unwrap();
+ snapbox::assert_eq(expected, raw);
+}
+
+#[test]
+fn serialize_array_with_enum_of_optional_struct_field() {
+ #[derive(Debug, Deserialize, Serialize)]
+ struct Document {
+ values: Vec<Choice>,
+ }
+
+ #[derive(Debug, Deserialize, Serialize)]
+ enum Choice {
+ Optional(OptionalField),
+ Empty,
+ }
+
+ #[derive(Debug, Deserialize, Serialize)]
+ struct OptionalField {
+ x: u8,
+ y: Option<u8>,
+ }
+
+ let input = Document {
+ values: vec![
+ Choice::Optional(OptionalField { x: 0, y: Some(4) }),
+ Choice::Empty,
+ Choice::Optional(OptionalField { x: 2, y: Some(5) }),
+ Choice::Optional(OptionalField { x: 3, y: Some(7) }),
+ ],
+ };
+ let expected = "values = [{ Optional = { x = 0, y = 4 } }, \"Empty\", { Optional = { x = 2, y = 5 } }, { Optional = { x = 3, y = 7 } }]
+";
+ let raw = toml::to_string(&input).unwrap();
+ snapbox::assert_eq(expected, raw);
+
+ let input = Document {
+ values: vec![
+ Choice::Optional(OptionalField { x: 0, y: Some(4) }),
+ Choice::Empty,
+ Choice::Optional(OptionalField { x: 2, y: None }),
+ Choice::Optional(OptionalField { x: 3, y: Some(7) }),
+ ],
+ };
+ let expected = "values = [{ Optional = { x = 0, y = 4 } }, \"Empty\", { Optional = { x = 2 } }, { Optional = { x = 3, y = 7 } }]
+";
+ let raw = toml::to_string(&input).unwrap();
+ snapbox::assert_eq(expected, raw);
+}
+
+#[test]
+fn span_for_sequence_as_map() {
+ #[allow(dead_code)]
+ #[derive(Deserialize)]
+ struct Manifest {
+ package: Package,
+ bench: Vec<Bench>,
+ }
+
+ #[derive(Deserialize)]
+ struct Package {}
+
+ #[derive(Deserialize)]
+ struct Bench {}
+
+ let raw = r#"
+[package]
+name = "foo"
+version = "0.1.0"
+edition = "2021"
+[[bench.foo]]
+"#;
+ let err = match toml::from_str::<Manifest>(raw) {
+ Ok(_) => panic!("should fail"),
+ Err(err) => err,
+ };
+ assert_eq!(err.span(), Some(61..66));
+}