Repository: toml-rs/toml
Pull request #855 (2025-04-18 20:12:27)

test(parse): Improve tests


Patch:
diff --git a/crates/toml_edit/src/encode.rs b/crates/toml_edit/src/encode.rs
index ea917b10..993fb6ac 100644
--- a/crates/toml_edit/src/encode.rs
+++ b/crates/toml_edit/src/encode.rs
@@ -563,8 +563,8 @@ mod test {
         #[test]
         #[cfg(feature = "parse")]
         fn parseable_string(string in "\\PC*") {
-            let string = Value::from(string);
-            let encoded = string.to_string();
+            let value = Value::from(string.clone());
+            let encoded = value.to_string();
             let _: Value = encoded.parse().unwrap_or_else(|err| {
                 panic!("error: {err}
 
@@ -572,6 +572,10 @@ string:
 ```
 {string}
 ```
+value:
+```
+{value}
+```
 ")
             });
         }
@@ -581,8 +585,8 @@ string:
         #[test]
         #[cfg(feature = "parse")]
         fn parseable_key(string in "\\PC*") {
-            let string = Key::new(string);
-            let encoded = string.to_string();
+            let key = Key::new(string.clone());
+            let encoded = key.to_string();
             let _: Key = encoded.parse().unwrap_or_else(|err| {
                 panic!("error: {err}
 
@@ -590,6 +594,10 @@ string:
 ```
 {string}
 ```
+key:
+```
+{key}
+```
 ")
             });
         }


Test patch:
diff --git a/crates/toml_edit/tests/testsuite/parse.rs b/crates/toml_edit/tests/testsuite/parse.rs
index 39e00cfd..3668473f 100644
--- a/crates/toml_edit/tests/testsuite/parse.rs
+++ b/crates/toml_edit/tests/testsuite/parse.rs
@@ -1610,14 +1610,14 @@ fn string_repr_roundtrip() {
     assert_string_repr_roundtrip(r#""""#, str![[r#""""#]]);
     assert_string_repr_roundtrip(r#""a""#, str![[r#""a""#]]);
 
-    assert_string_repr_roundtrip(r#""tab \t tab""#, str![[r#""tab /t tab""#]]);
-    assert_string_repr_roundtrip(r#""lf \n lf""#, str![[r#""lf /n lf""#]]);
-    assert_string_repr_roundtrip(r#""crlf \r\n crlf""#, str![[r#""crlf /r/n crlf""#]]);
-    assert_string_repr_roundtrip(r#""bell \b bell""#, str![[r#""bell /b bell""#]]);
-    assert_string_repr_roundtrip(r#""feed \f feed""#, str![[r#""feed /f feed""#]]);
+    assert_string_repr_roundtrip(r#""tab \t tab""#, str![[r#""tab \t tab""#]]);
+    assert_string_repr_roundtrip(r#""lf \n lf""#, str![[r#""lf \n lf""#]]);
+    assert_string_repr_roundtrip(r#""crlf \r\n crlf""#, str![[r#""crlf \r\n crlf""#]]);
+    assert_string_repr_roundtrip(r#""bell \b bell""#, str![[r#""bell \b bell""#]]);
+    assert_string_repr_roundtrip(r#""feed \f feed""#, str![[r#""feed \f feed""#]]);
     assert_string_repr_roundtrip(
         r#""backslash \\ backslash""#,
-        str![[r#""backslash // backslash""#]],
+        str![[r#""backslash \\ backslash""#]],
     );
 
     assert_string_repr_roundtrip(r#""squote ' squote""#, str![[r#""squote ' squote""#]]);
@@ -1627,15 +1627,15 @@ fn string_repr_roundtrip() {
     );
     assert_string_repr_roundtrip(r#""end squote '""#, str![[r#""end squote '""#]]);
 
-    assert_string_repr_roundtrip(r#""quote \" quote""#, str![[r#""quote /" quote""#]]);
+    assert_string_repr_roundtrip(r#""quote \" quote""#, str![[r#""quote \" quote""#]]);
     assert_string_repr_roundtrip(
         r#""triple quote \"\"\" triple quote""#,
-        str![[r#""triple quote /"/"/" triple quote""#]],
+        str![[r#""triple quote \"\"\" triple quote""#]],
     );
-    assert_string_repr_roundtrip(r#""end quote \"""#, str![[r#""end quote /"""#]]);
+    assert_string_repr_roundtrip(r#""end quote \"""#, str![[r#""end quote \"""#]]);
     assert_string_repr_roundtrip(
         r#""quoted \"content\" quoted""#,
-        str![[r#""quoted /"content/" quoted""#]],
+        str![[r#""quoted \"content\" quoted""#]],
     );
     assert_string_repr_roundtrip(
         r#""squoted 'content' squoted""#,
@@ -1643,7 +1643,7 @@ fn string_repr_roundtrip() {
     );
     assert_string_repr_roundtrip(
         r#""mixed quoted \"start\" 'end'' mixed quote""#,
-        str![[r#""mixed quoted /"start/" 'end'' mixed quote""#]],
+        str![[r#""mixed quoted \"start\" 'end'' mixed quote""#]],
     );
 }
 
@@ -1660,8 +1660,7 @@ fn assert_string_repr_roundtrip(input: &str, expected: impl IntoData) {
 "
         )
     });
-    let expected = expected.into_data();
-    assert_data_eq!(actual, expected);
+    assert_data_eq!(actual, expected.raw());
 }
 
 #[test]
@@ -1669,7 +1668,7 @@ fn string_value_roundtrip() {
     assert_string_value_roundtrip(r#""""#, str![[r#""""#]]);
     assert_string_value_roundtrip(r#""a""#, str![[r#""a""#]]);
 
-    assert_string_value_roundtrip(r#""tab \t tab""#, str![[r#""tab /t tab""#]]);
+    assert_string_value_roundtrip(r#""tab \t tab""#, str![[r#""tab \t tab""#]]);
     assert_string_value_roundtrip(
         r#""lf \n lf""#,
         str![[r#"
@@ -1682,15 +1681,15 @@ lf
         r#""crlf \r\n crlf""#,
         str![[r#"
 """
-crlf /r
+crlf \r
  crlf"""
 "#]],
     );
-    assert_string_value_roundtrip(r#""bell \b bell""#, str![[r#""bell /b bell""#]]);
-    assert_string_value_roundtrip(r#""feed \f feed""#, str![[r#""feed /f feed""#]]);
+    assert_string_value_roundtrip(r#""bell \b bell""#, str![[r#""bell \b bell""#]]);
+    assert_string_value_roundtrip(r#""feed \f feed""#, str![[r#""feed \f feed""#]]);
     assert_string_value_roundtrip(
         r#""backslash \\ backslash""#,
-        str!["'backslash / backslash'"],
+        str![[r#"'backslash \ backslash'"#]],
     );
 
     assert_string_value_roundtrip(r#""squote ' squote""#, str![[r#""squote ' squote""#]]);
@@ -1734,8 +1733,7 @@ fn assert_string_value_roundtrip(input: &str, expected: impl IntoData) {
 "
         )
     });
-    let expected = expected.into_data();
-    assert_data_eq!(actual, expected);
+    assert_data_eq!(actual, expected.raw());
 }
 
 #[test]
@@ -1743,14 +1741,14 @@ fn key_repr_roundtrip() {
     assert_key_repr_roundtrip(r#""""#, str![[r#""""#]]);
     assert_key_repr_roundtrip(r#""a""#, str![[r#""a""#]]);
 
-    assert_key_repr_roundtrip(r#""tab \t tab""#, str![[r#""tab /t tab""#]]);
-    assert_key_repr_roundtrip(r#""lf \n lf""#, str![[r#""lf /n lf""#]]);
-    assert_key_repr_roundtrip(r#""crlf \r\n crlf""#, str![[r#""crlf /r/n crlf""#]]);
-    assert_key_repr_roundtrip(r#""bell \b bell""#, str![[r#""bell /b bell""#]]);
-    assert_key_repr_roundtrip(r#""feed \f feed""#, str![[r#""feed /f feed""#]]);
+    assert_key_repr_roundtrip(r#""tab \t tab""#, str![[r#""tab \t tab""#]]);
+    assert_key_repr_roundtrip(r#""lf \n lf""#, str![[r#""lf \n lf""#]]);
+    assert_key_repr_roundtrip(r#""crlf \r\n crlf""#, str![[r#""crlf \r\n crlf""#]]);
+    assert_key_repr_roundtrip(r#""bell \b bell""#, str![[r#""bell \b bell""#]]);
+    assert_key_repr_roundtrip(r#""feed \f feed""#, str![[r#""feed \f feed""#]]);
     assert_key_repr_roundtrip(
         r#""backslash \\ backslash""#,
-        str![[r#""backslash // backslash""#]],
+        str![[r#""backslash \\ backslash""#]],
     );
 
     assert_key_repr_roundtrip(r#""squote ' squote""#, str![[r#""squote ' squote""#]]);
@@ -1760,15 +1758,15 @@ fn key_repr_roundtrip() {
     );
     assert_key_repr_roundtrip(r#""end squote '""#, str![[r#""end squote '""#]]);
 
-    assert_key_repr_roundtrip(r#""quote \" quote""#, str![[r#""quote /" quote""#]]);
+    assert_key_repr_roundtrip(r#""quote \" quote""#, str![[r#""quote \" quote""#]]);
     assert_key_repr_roundtrip(
         r#""triple quote \"\"\" triple quote""#,
-        str![[r#""triple quote /"/"/" triple quote""#]],
+        str![[r#""triple quote \"\"\" triple quote""#]],
     );
-    assert_key_repr_roundtrip(r#""end quote \"""#, str![[r#""end quote /"""#]]);
+    assert_key_repr_roundtrip(r#""end quote \"""#, str![[r#""end quote \"""#]]);
     assert_key_repr_roundtrip(
         r#""quoted \"content\" quoted""#,
-        str![[r#""quoted /"content/" quoted""#]],
+        str![[r#""quoted \"content\" quoted""#]],
     );
     assert_key_repr_roundtrip(
         r#""squoted 'content' squoted""#,
@@ -1776,7 +1774,7 @@ fn key_repr_roundtrip() {
     );
     assert_key_repr_roundtrip(
         r#""mixed quoted \"start\" 'end'' mixed quote""#,
-        str![[r#""mixed quoted /"start/" 'end'' mixed quote""#]],
+        str![[r#""mixed quoted \"start\" 'end'' mixed quote""#]],
     );
 }
 
@@ -1793,8 +1791,7 @@ fn assert_key_repr_roundtrip(input: &str, expected: impl IntoData) {
 "
         )
     });
-    let expected = expected.into_data();
-    assert_data_eq!(actual, expected);
+    assert_data_eq!(actual, expected.raw());
 }
 
 #[test]
@@ -1802,14 +1799,14 @@ fn key_value_roundtrip() {
     assert_key_value_roundtrip(r#""""#, str![[r#""""#]]);
     assert_key_value_roundtrip(r#""a""#, str!["a"]);
 
-    assert_key_value_roundtrip(r#""tab \t tab""#, str![[r#""tab /t tab""#]]);
-    assert_key_value_roundtrip(r#""lf \n lf""#, str![[r#""lf /n lf""#]]);
-    assert_key_value_roundtrip(r#""crlf \r\n crlf""#, str![[r#""crlf /r/n crlf""#]]);
-    assert_key_value_roundtrip(r#""bell \b bell""#, str![[r#""bell /b bell""#]]);
-    assert_key_value_roundtrip(r#""feed \f feed""#, str![[r#""feed /f feed""#]]);
+    assert_key_value_roundtrip(r#""tab \t tab""#, str![[r#""tab \t tab""#]]);
+    assert_key_value_roundtrip(r#""lf \n lf""#, str![[r#""lf \n lf""#]]);
+    assert_key_value_roundtrip(r#""crlf \r\n crlf""#, str![[r#""crlf \r\n crlf""#]]);
+    assert_key_value_roundtrip(r#""bell \b bell""#, str![[r#""bell \b bell""#]]);
+    assert_key_value_roundtrip(r#""feed \f feed""#, str![[r#""feed \f feed""#]]);
     assert_key_value_roundtrip(
         r#""backslash \\ backslash""#,
-        str!["'backslash / backslash'"],
+        str![[r#"'backslash \ backslash'"#]],
     );
 
     assert_key_value_roundtrip(r#""squote ' squote""#, str![[r#""squote ' squote""#]]);
@@ -1835,7 +1832,7 @@ fn key_value_roundtrip() {
     );
     assert_key_value_roundtrip(
         r#""mixed quoted \"start\" 'end'' mixed quote""#,
-        str![[r#""mixed quoted /"start/" 'end'' mixed quote""#]],
+        str![[r#""mixed quoted \"start\" 'end'' mixed quote""#]],
     );
 }
 
@@ -1853,6 +1850,5 @@ fn assert_key_value_roundtrip(input: &str, expected: impl IntoData) {
 "
         )
     });
-    let expected = expected.into_data();
-    assert_data_eq!(actual, expected);
+    assert_data_eq!(actual, expected.raw());
 }