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

Function modify_values

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

Source from the content-addressed store, hash-verified

3200
3201 #[test]
3202 fn modify_values() {
3203 let cst = build_cst(
3204 r#"{
3205 "value": 5,
3206 // comment
3207 "value2": "hello",
3208 value3: true
3209}"#,
3210 );
3211
3212 let root_value = cst.value().unwrap();
3213 let root_obj = root_value.as_object().unwrap();
3214 {
3215 let prop = root_obj.get("value").unwrap();
3216 prop
3217 .value()
3218 .unwrap()
3219 .as_number_lit()
3220 .unwrap()
3221 .set_raw_value("10".to_string());
3222 assert!(prop.trailing_comma().is_some());
3223 assert!(prop.previous_property().is_none());
3224 assert_eq!(
3225 prop.next_property().unwrap().name().unwrap().decoded_value().unwrap(),
3226 "value2"
3227 );
3228 assert_eq!(prop.indent_text().unwrap(), " ");
3229 }
3230 {
3231 let prop = root_obj.get("value2").unwrap();
3232 prop
3233 .value()
3234 .unwrap()
3235 .as_string_lit()
3236 .unwrap()
3237 .set_raw_value("\"5\"".to_string());
3238 assert!(prop.trailing_comma().is_some());
3239 assert_eq!(
3240 prop
3241 .previous_property()
3242 .unwrap()
3243 .name()
3244 .unwrap()
3245 .decoded_value()
3246 .unwrap(),
3247 "value"
3248 );
3249 assert_eq!(
3250 prop.next_property().unwrap().name().unwrap().decoded_value().unwrap(),
3251 "value3"
3252 );
3253 }
3254 {
3255 let prop = root_obj.get("value3").unwrap();
3256 prop.value().unwrap().as_boolean_lit().unwrap().set_value(false);
3257 prop
3258 .name()
3259 .unwrap()

Callers

nothing calls this directly

Calls 11

build_cstFunction · 0.85
valueMethod · 0.80
set_raw_valueMethod · 0.80
set_valueMethod · 0.80
nameMethod · 0.80
as_objectMethod · 0.45
getMethod · 0.45
as_number_litMethod · 0.45
as_string_litMethod · 0.45
as_boolean_litMethod · 0.45
as_word_litMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…