forked from ocaml/dune
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is only one part of the issue; the other part is more difficult to test because it is related to `Modules.t` round-tripping correctly. Signed-off-by: Etienne Millon <[email protected]>
- Loading branch information
Showing
2 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
open Stdune | ||
module Kind = Dune_rules.Module.Kind | ||
|
||
(* See #10264 *) | ||
let%expect_test "Module.Kind encoding round trip" = | ||
let module_name s = Dune_rules.Module_name.of_string s in | ||
let test k = | ||
let ast = Kind.encode k in | ||
let sexp = Dune_sexp.Ast.add_loc ~loc:Loc.none ast in | ||
let decoded = | ||
match Dune_lang.Decoder.parse Kind.decode Univ_map.empty sexp with | ||
| r -> Ok r | ||
| exception e -> Error e | ||
in | ||
let dyn = | ||
Dyn.record | ||
[ "ast", Dyn.string (Dune_sexp.to_string ast) | ||
; "decoded", Or_exn.to_dyn Kind.to_dyn decoded | ||
] | ||
in | ||
Dune_tests_common.print_dyn dyn | ||
in | ||
test Impl; | ||
[%expect {| { ast = "impl"; decoded = Ok Impl } |}]; | ||
test (Alias []); | ||
[%expect {| { ast = "alias"; decoded = Ok Alias [] } |}]; | ||
test (Alias [ module_name "A" ]); | ||
[%expect | ||
{| | ||
{ ast = "(alias (A))" | ||
; decoded = | ||
Error | ||
"File \"<none>\", line 1, characters 0-0:\n\ | ||
Error: Atom or quoted string expected\n\ | ||
" | ||
} |}]; | ||
test (Alias [ module_name "A"; module_name "B" ]); | ||
[%expect | ||
{| | ||
{ ast = "(alias (A B))" | ||
; decoded = | ||
Error | ||
"File \"<none>\", line 1, characters 0-0:\n\ | ||
Error: Atom or quoted string expected\n\ | ||
" | ||
} |}] | ||
;; |