Skip to content

Commit

Permalink
Promote test for 5.1
Browse files Browse the repository at this point in the history
Signed-off-by: Paul-Elliot <[email protected]>
  • Loading branch information
panglesd committed Sep 26, 2023
1 parent b7d72dd commit ade4878
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions test/driver/attributes/test_510.ml
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,40 @@ let x = (42 [@baz.qux3])
Line _, characters 14-22:
Error: Attribute `baz.qux3' was silently dropped
|}]

(* Testing flags *)

let flag = Attribute.declare_flag "flag" Attribute.Context.expression
[%%expect{|

val flag : expression Attribute.flag = <abstr>
|}]

let replace_flagged = object
inherit Ast_traverse.map as super

method! expression e =
match Attribute.has_flag_res flag e with
| Ok true -> Ast_builder.Default.estring ~loc:e.pexp_loc "Found flag"
| Ok false -> super#expression e
| Error (err, _) -> Ast_builder.Default.estring ~loc:e.pexp_loc (Location.Error.message err)
end
[%%expect{|

val replace_flagged : Ast_traverse.map = <obj>
|}]

let () =
Driver.register_transformation "" ~impl:replace_flagged#structure

let e1 = "flagged" [@flag]
[%%expect{|

val e1 : string = "Found flag"
|}]

let e1 = "flagged" [@flag 12]
[%%expect{|

val e1 : string = "[] expected"
|}]

0 comments on commit ade4878

Please sign in to comment.