2024-05-13 13:37:53 +00:00
|
|
|
use crate::repl::tests::{run_test, TestResult};
|
2021-12-25 19:39:42 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn from_json_1() -> TestResult {
|
|
|
|
run_test(r#"('{"name": "Fred"}' | from json).name"#, "Fred")
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn from_json_2() -> TestResult {
|
|
|
|
run_test(
|
|
|
|
r#"('{"name": "Fred"}
|
|
|
|
{"name": "Sally"}' | from json -o).name.1"#,
|
|
|
|
"Sally",
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2021-12-27 10:51:38 +00:00
|
|
|
fn to_json_raw_flag_1() -> TestResult {
|
2021-12-25 19:39:42 +00:00
|
|
|
run_test(
|
|
|
|
"[[a b]; [jim susie] [3 4]] | to json -r",
|
2024-03-20 21:14:31 +00:00
|
|
|
r#"[{"a":"jim","b":"susie"},{"a":3,"b":4}]"#,
|
2021-12-27 10:51:38 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn to_json_raw_flag_2() -> TestResult {
|
|
|
|
run_test(
|
|
|
|
"[[\"a b\" c]; [jim susie] [3 4]] | to json -r",
|
2024-03-20 21:14:31 +00:00
|
|
|
r#"[{"a b":"jim","c":"susie"},{"a b":3,"c":4}]"#,
|
2021-12-27 10:51:38 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn to_json_raw_flag_3() -> TestResult {
|
|
|
|
run_test(
|
|
|
|
"[[\"a b\" \"c d\"]; [\"jim smith\" \"susie roberts\"] [3 4]] | to json -r",
|
2024-03-20 21:14:31 +00:00
|
|
|
r#"[{"a b":"jim smith","c d":"susie roberts"},{"a b":3,"c d":4}]"#,
|
2021-12-25 19:39:42 +00:00
|
|
|
)
|
|
|
|
}
|
2022-02-15 11:55:57 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn to_json_escaped() -> TestResult {
|
|
|
|
run_test(
|
|
|
|
r#"{foo: {bar: '[{"a":"b","c": 2}]'}} | to json --raw"#,
|
2024-03-20 21:14:31 +00:00
|
|
|
r#"{"foo":{"bar":"[{\"a\":\"b\",\"c\": 2}]"}}"#,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn to_json_raw_backslash_in_quotes() -> TestResult {
|
|
|
|
run_test(
|
|
|
|
r#"{a: '\', b: 'some text'} | to json -r"#,
|
|
|
|
r#"{"a":"\\","b":"some text"}"#,
|
2022-02-15 11:55:57 +00:00
|
|
|
)
|
|
|
|
}
|