kdl-rs icon indicating copy to clipboard operation
kdl-rs copied to clipboard

Fix tests

Open CAD97 opened this issue 2 years ago • 3 comments

In order,

  • Updates the test to pass on main (4ac459a)
  • Reverts #49 and the format mangling resulting from it (f820145)
  • Adds a new test showing the case in #49 working without #49 (b7fd360)

It might be worthwhile to change how indenting is handled (see e.g. the empty line in the new test), but this is a minimal patch to quickly fix test errors.

cc @cbiffle

CAD97 avatar Aug 14 '22 21:08 CAD97

FWIW, the all-closing-braces-at-the-left-margin behavior I was seeing (which I'm still seeing on the released package, btw) is from programmatically created documents, not parsed documents. So your test case may be testing something else.

cbiffle avatar Aug 14 '22 23:08 cbiffle

Reproduced in cec5858; something odd is certainly going on.

CAD97 avatar Aug 15 '22 00:08 CAD97

This fails:

#[test]
fn parse_vs_build() -> miette::Result<()> {
    let mut built = build_abc();
    let mut parsed: KdlDocument = built.to_string().parse()?;

    built.fmt();
    parsed.fmt();

    assert_eq!(built, parsed);

    Ok(())
}
diff
Diff < built / parsed > :
 KdlDocument {
<    leading: None,
>    leading: Some(
>        "",
>    ),
     nodes: [
         KdlNode {
<            leading: None,
>            leading: Some(
>                "",
>            ),
             ty: None,
             name: KdlIdentifier {
                 value: "a",
                 repr: None,
             },
             entries: [],
             before_children: None,
             children: Some(
                 KdlDocument {
<                    leading: None,
>                    leading: Some(
>                        "\n",
>                    ),
                     nodes: [
                         KdlNode {
<                            leading: None,
>                            leading: Some(
>                                "    ",
>                            ),
                             ty: None,
                             name: KdlIdentifier {
                                 value: "b",
                                 repr: None,
                             },
                             entries: [],
                             before_children: None,
                             children: Some(
                                 KdlDocument {
<                                    leading: None,
>                                    leading: Some(
>                                        "\n",
>                                    ),
                                     nodes: [
                                         KdlNode {
<                                            leading: None,
>                                            leading: Some(
>                                                "        ",
>                                            ),
                                             ty: None,
                                             name: KdlIdentifier {
                                                 value: "c",
                                                 repr: None,
                                             },
                                             entries: [],
                                             before_children: None,
                                             children: Some(
                                                 KdlDocument {
<                                                    leading: None,
>                                                    leading: Some(
>                                                        "\n",
>                                                    ),
                                                     nodes: [],
<                                                    trailing: None,
>                                                    trailing: Some(
>                                                        "\n        ",
>                                                    ),
                                                 },
                                             ),
<                                            trailing: None,
>                                            trailing: Some(
>                                                "\n",
>                                            ),
                                         },
                                     ],
<                                    trailing: None,
>                                    trailing: Some(
>                                        "    ",
>                                    ),
                                 },
                             ),
<                            trailing: None,
>                            trailing: Some(
>                                "\n",
>                            ),
                         },
                     ],
<                    trailing: None,
>                    trailing: Some(
>                        "",
>                    ),
                 },
             ),
<            trailing: None,
>            trailing: Some(
>                "\n",
>            ),
         },
     ],
<    trailing: None,
>    trailing: Some(
>        "",
>    ),
 }

CAD97 avatar Aug 15 '22 00:08 CAD97