MCPcopy Create free account
hub / github.com/dprint/jsonc-parser / array_ensure_multiline

Function array_ensure_multiline

src/cst/mod.rs:3729–3807  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

3727
3728 #[test]
3729 fn array_ensure_multiline() {
3730 // empty
3731 {
3732 let cst = build_cst(r#"[]"#);
3733 cst.value().unwrap().as_array().unwrap().ensure_multiline();
3734 assert_eq!(cst.to_string(), "[\n]");
3735 }
3736 // whitespace only
3737 {
3738 let cst = build_cst(r#"[ ]"#);
3739 cst.value().unwrap().as_array().unwrap().ensure_multiline();
3740 assert_eq!(cst.to_string(), "[\n]");
3741 }
3742 // comments only
3743 {
3744 let cst = build_cst(r#"[ /* test */ ]"#);
3745 cst.value().unwrap().as_array().unwrap().ensure_multiline();
3746 assert_eq!(cst.to_string(), "[\n /* test */\n]");
3747 }
3748 // elements
3749 {
3750 let cst = build_cst(r#"[ 1, 2, /* test */ 3 ]"#);
3751 cst.value().unwrap().as_array().unwrap().ensure_multiline();
3752 assert_eq!(
3753 cst.to_string(),
3754 r#"[
3755 1,
3756 2,
3757 /* test */ 3
3758]"#
3759 );
3760 }
3761 // elements deep
3762 {
3763 let cst = build_cst(
3764 r#"{
3765 "prop": {
3766 "value": [ 1, 2, /* test */ 3 ]
3767 }
3768}"#,
3769 );
3770 cst
3771 .value()
3772 .unwrap()
3773 .as_object()
3774 .unwrap()
3775 .get("prop")
3776 .unwrap()
3777 .value()
3778 .unwrap()
3779 .as_object()
3780 .unwrap()
3781 .get("value")
3782 .unwrap()
3783 .value()
3784 .unwrap()
3785 .as_array()
3786 .unwrap()

Callers

nothing calls this directly

Calls 6

build_cstFunction · 0.85
ensure_multilineMethod · 0.80
valueMethod · 0.80
as_arrayMethod · 0.45
getMethod · 0.45
as_objectMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…