Skip to content

Commit

Permalink
[main] Stringify all input in to-json (#139).
Browse files Browse the repository at this point in the history
  • Loading branch information
tomhrr committed Jun 8, 2024
1 parent 4459e70 commit 3099982
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/vm/vm_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,19 @@ fn convert_to_json(v: &Value) -> String {
.join(",");
format!("{{{}}}", s)
}
_ => "".to_string(),
_ => {
let s_opt = v.to_string();
match s_opt {
Some(s) => {
format!("\"{}\"", s)
}
None => {
let type_str = v.type_string();
let s = format!("\"v[{}]\"", type_str);
s
}
}
}
}
}

Expand Down
6 changes: 6 additions & 0 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2224,3 +2224,9 @@ fn single_address_range() {
basic_test("1.1.1.1-1.1.1.1 ip", "v[ip 1.1.1.1]");
basic_test("::-:: ip", "v[ip ::]");
}

#[test]
fn to_json_unhandled() {
basic_test("(1.1.1.1 ip; README.md f<;) to-json; println",
"[\"1.1.1.1\",\"v[gen]\"]");
}

0 comments on commit 3099982

Please sign in to comment.