fix excessive JSON escaping (#337)

This commit is contained in:
Rijnard van Tonder 2022-05-19 22:19:03 -04:00 committed by GitHub
parent d218ed4c8d
commit 7ba338850c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 3 additions and 6 deletions

View File

@ -67,9 +67,6 @@ let update_environment f env =
let to_json source_path matches =
let json_matches matches =
matches
|> List.map ~f:(fun m ->
{ m with matched = String.escaped m.matched;
environment = update_environment String.escaped m.environment })
|> List.map ~f:to_yojson
|> fun matches ->
`List matches

View File

@ -863,7 +863,7 @@ in
let command = Format.sprintf "%s %s" binary_path command_args in
read_expect_stdin_and_stdout command source
|> print_string;
[%expect_exact {|{"uri":null,"matches":[{"range":{"start":{"offset":5,"line":2,"column":5},"end":{"offset":11,"line":2,"column":11}},"environment":[],"matched":"let ()"},{"range":{"start":{"offset":23,"line":3,"column":5},"end":{"offset":34,"line":5,"column":7}},"environment":[],"matched":"let\\n\\n ()"},{"range":{"start":{"offset":42,"line":7,"column":5},"end":{"offset":48,"line":7,"column":11}},"environment":[],"matched":"let ()"}]}
[%expect_exact {|{"uri":null,"matches":[{"range":{"start":{"offset":5,"line":2,"column":5},"end":{"offset":11,"line":2,"column":11}},"environment":[],"matched":"let ()"},{"range":{"start":{"offset":23,"line":3,"column":5},"end":{"offset":34,"line":5,"column":7}},"environment":[],"matched":"let\n\n ()"},{"range":{"start":{"offset":42,"line":7,"column":5},"end":{"offset":48,"line":7,"column":11}},"environment":[],"matched":"let ()"}]}
WARNING: -count and -json-lines is specified. Ignoring -count.
|}];

View File

@ -211,7 +211,7 @@ let%expect_test "correct_columns" =
print_string @@ Format.sprintf "Offset conversion does not match. Expect@.%s@.got %s" slow_result fast_result
else
print_string fast_result;
[%expect_exact {|{"uri":"file","matches":[{"range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":25,"line":3,"column":1}},"environment":[{"variable":"1","value":"world\\nhello potato\\n","range":{"start":{"offset":6,"line":1,"column":7},"end":{"offset":25,"line":3,"column":1}}}],"matched":"hello world\\nhello potato\\n"}]}
[%expect_exact {|{"uri":"file","matches":[{"range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":25,"line":3,"column":1}},"environment":[{"variable":"1","value":"world\nhello potato\n","range":{"start":{"offset":6,"line":1,"column":7},"end":{"offset":25,"line":3,"column":1}}}],"matched":"hello world\nhello potato\n"}]}
|}];
let source = "hello world\nhello potato" in
@ -221,5 +221,5 @@ let%expect_test "correct_columns" =
print_string @@ Format.sprintf "Offset conversion does not match. Expect@.%s@.got %s" slow_result fast_result
else
print_string fast_result;
[%expect_exact {|{"uri":"file","matches":[{"range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":24,"line":2,"column":13}},"environment":[{"variable":"1","value":"world\\nhello potato","range":{"start":{"offset":6,"line":1,"column":7},"end":{"offset":24,"line":2,"column":13}}}],"matched":"hello world\\nhello potato"}]}
[%expect_exact {|{"uri":"file","matches":[{"range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":24,"line":2,"column":13}},"environment":[{"variable":"1","value":"world\nhello potato","range":{"start":{"offset":6,"line":1,"column":7},"end":{"offset":24,"line":2,"column":13}}}],"matched":"hello world\nhello potato"}]}
|}]