File: test.mlt

package info (click to toggle)
ppx-js-style 0.17.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 176 kB
  • sloc: ml: 560; makefile: 14
file content (65 lines) | stat: -rw-r--r-- 1,636 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
module type S = sig
  val x : (int[@deprecated "[since 2018-01] ..."])
end

[%%expect
  {|
Line _, characters _-_:
Error: Jane Street style: Invalid deprecated attribute, it will be ignored by the compiler
|}]

let ( let* ) o f =
  match o with
  | None -> None
  | Some x -> f x
;;

let return x = Some x

let find_and_sum tbl k1 k2 =
  let* x1 = Hashtbl.find_opt tbl k1 in
  let* x2 = Hashtbl.find_opt tbl k2 in
  return (x1 + x2)
;;

[%%expect
  {|
Line _, characters _-_:
Error: Jane Street style: This use of ( let* ) is forbidden.
ppx_let is currently more featureful, please use that instead to keep a consistent style
|}]

let find_and_sum tbl k1 k2 =
  ( let* ) (Hashtbl.find_opt tbl k1) (fun x1 ->
    ( let* ) (Hashtbl.find_opt tbl k2) (fun x2 -> return (x1 + x2)))
;;

[%%expect {| |}]
(* we check annotated ignores when extensions are used too *)
let%foo _ = "whatever"

[%%expect
  {|
Line _, characters _-_:
Error: Jane Street style: Ignored expression must come with a type annotation
|}]

(* expect test expansion is done before annotated ignores, so this is allowed *)
let%expect_test _ = "whatever"

[%%expect
  {|
Line _, characters _-_:
Error: ppx_expect: extension is disabled because the tests would be ignored (the build system didn't pass -inline-test-lib. With jenga or dune, this usually happens when writing tests in files that are part of an executable stanza, but only library stanzas support inline tests)
|}]

(* a regression test (this used to result in a strange error message): *)
let foo = [%expect " 
 foo
 "]

[%%expect
  {|
Line _, characters _-_:
Error: Extension `expect' was not translated
|}]