Skip to content

Commit

Permalink
Add 5.1.0 tests
Browse files Browse the repository at this point in the history
Signed-off-by: Nick Roberts <[email protected]>
  • Loading branch information
ncik-roberts committed Jul 6, 2023
1 parent ea5d52e commit 7d86d54
Showing 1 changed file with 89 additions and 0 deletions.
89 changes: 89 additions & 0 deletions test/driver/attributes/test_510.ml
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,92 @@ type t2 = < >
Line _, characters 17-20:
Error: Attribute `foo' was not used
|}]

(* Reserved Namespaces *)

(* ppxlib checks that unreserved attributes aren't dropped *)

let x = (42 [@bar])
[%%expect{|

Line _, characters 14-17:
Error: Attribute `bar' was silently dropped
|}]

let x = (42 [@bar.baz])
[%%expect{|

Line _, characters 14-21:
Error: Attribute `bar.baz' was silently dropped
|}]

(* But reserving a namespace disables those checks. *)

let () = Reserved_namespaces.reserve "bar"

let x = (42 [@bar])
let x = (42 [@bar.baz])
[%%expect{|

val x : int = 42

val x : int = 42
|}]

let x = (42 [@bar_not_proper_sub_namespace])
[%%expect{|

Line _, characters 14-42:
Error: Attribute `bar_not_proper_sub_namespace' was silently dropped
|}]

(* The namespace reservation process understands dots as namespace
separators. *)

let () = Reserved_namespaces.reserve "baz.qux"

let x = (42 [@baz])
[%%expect{|

Line _, characters 14-17:
Error: Attribute `baz' was silently dropped
|}]

let x = (42 [@baz.qux])
[%%expect{|

val x : int = 42
|}]

let x = (42 [@baz.qux.quux])
[%%expect{|

val x : int = 42
|}]

let x = (42 [@baz.qux_not_proper_sub_namespace])
[%%expect{|

Line _, characters 14-46:
Error: Attribute `baz.qux_not_proper_sub_namespace' was silently dropped
|}]

(* You can reserve multiple subnamespaces under the same namespace *)

let () = Reserved_namespaces.reserve "baz.qux2"

let x = (42 [@baz.qux])
let x = (42 [@baz.qux2])
[%%expect{|

val x : int = 42

val x : int = 42
|}]

let x = (42 [@baz.qux3])
[%%expect{|

Line _, characters 14-22:
Error: Attribute `baz.qux3' was silently dropped
|}]

0 comments on commit 7d86d54

Please sign in to comment.