Add empty set patches, add test for empty set patches

This commit is contained in:
John David Pressman 2019-10-10 13:35:38 -07:00
parent c82076281f
commit 0de17f4b57
3 changed files with 9 additions and 2 deletions

View File

@ -828,7 +828,7 @@ and simpl_single_instruction : Raw.single_instr -> (_ -> expression result) resu
| MapPatch patch -> | MapPatch patch ->
fail @@ unsupported_map_patches patch fail @@ unsupported_map_patches patch
| SetPatch patch -> ( | SetPatch patch -> (
let setp = patch.value in let (setp, loc) = r_split patch in
let (name , access_path) = simpl_path setp.path in let (name , access_path) = simpl_path setp.path in
let%bind inj = bind_list let%bind inj = bind_list
@@ List.map (fun (x:Raw.expr) -> @@ List.map (fun (x:Raw.expr) ->
@ -840,7 +840,7 @@ and simpl_single_instruction : Raw.single_instr -> (_ -> expression result) resu
e_assign name access_path (e_constant "SET_ADD" [v ; e_variable name]) in e_assign name access_path (e_constant "SET_ADD" [v ; e_variable name]) in
let assigns = List.map aux inj in let assigns = List.map aux inj in
match assigns with match assigns with
| [] -> fail @@ unsupported_empty_record_patch setp.set_inj | [] -> ok @@ e_skip ~loc ()
| hd :: tl -> ( | hd :: tl -> (
let aux acc cur = e_sequence acc cur in let aux acc cur = e_sequence acc cur in
ok @@ List.fold_left aux hd tl ok @@ List.fold_left aux hd tl

View File

@ -20,6 +20,9 @@ function remove_syntax (var s : set(string)) : set(string) is
function patch_op (var s: set(string)) : set(string) is function patch_op (var s: set(string)) : set(string) is
begin patch s with set ["foobar"]; end with s begin patch s with set ["foobar"]; end with s
function patch_op_empty (var s: set(string)) : set(string) is
begin patch s with set []; end with s
function mem_op (const s : set(string)) : bool is function mem_op (const s : set(string)) : bool is
begin skip end with set_mem("foobar" , s) begin skip end with set_mem("foobar" , s)

View File

@ -249,6 +249,10 @@ let set_arithmetic () : unit result =
expect_eq program "patch_op" expect_eq program "patch_op"
(e_set [e_string "foo" ; e_string "bar"]) (e_set [e_string "foo" ; e_string "bar"])
(e_set [e_string "foo" ; e_string "bar"; e_string "foobar"]) in (e_set [e_string "foo" ; e_string "bar"; e_string "foobar"]) in
let%bind () =
expect_eq program "patch_op_empty"
(e_set [e_string "foo" ; e_string "bar"])
(e_set [e_string "foo" ; e_string "bar"]) in
let%bind () = let%bind () =
expect_eq program "mem_op" expect_eq program "mem_op"
(e_set [e_string "foo" ; e_string "bar" ; e_string "foobar"]) (e_set [e_string "foo" ; e_string "bar" ; e_string "foobar"])