Skip to content

Commit

Permalink
Merge pull request #140 from Leonidas-from-XIV/atd-example
Browse files Browse the repository at this point in the history
Add regression test for pretty-printing
  • Loading branch information
Leonidas-from-XIV authored Jun 3, 2022
2 parents 9f53260 + 34926d5 commit 40db674
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 9 deletions.
11 changes: 11 additions & 0 deletions test/pretty/atd.expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[
{ "r1": "testing" }, { "r2": [ "Some", 2 ] }, { "r2": "None" }, {
"r3": [ "Some", 3 ] }, {}, { "r4": true }, { "r5": [ "Some", 5 ] }, {}, {
"r6": 6 }, {}, { "r7": -1000 }, { "r8": [ 1, 2, 3 ] }, [ "foo", "bar" ],
[], null, [ 1, 2, 3 ], 99, { "foo": 7, "bar": 8, "baz": 43 }, { "foo2": 5,
"bar2": 6, "baz2": 41, "42": 42 }, [ 100, "foo" ], [ 100, 200, 42 ], [
100, 200, -1 ], [
"V1", "v22", [ "V3", "testing" ], [ "V44", 255 ], [ "V5", "None" ], [
"V5", [ "Some", true ] ] ], { "v2": "A" }, { "v2": [ "B", 100 ] }, [
"C1", [ "C2", true ], [ "C2", false ] ], [ 50, 30, -1, 400 ]
]
46 changes: 46 additions & 0 deletions test/pretty/atd.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
let massive_json =
`List [
`Assoc [("r1", `String "testing")];
`Assoc [("r2", `List [`String "Some"; `Int 2])];
`Assoc [("r2", `String "None")];
`Assoc [("r3", `List [`String "Some"; `Int 3])];
`Assoc [];
`Assoc [("r4", `Bool true) ];
`Assoc [("r5", `List [`String "Some"; `Int 5])];
`Assoc [];
`Assoc [("r6", `Int 6)];
`Assoc [];
`Assoc [("r7", `Int (-1_000))];
`Assoc [("r8", `List [`Int 1; `Int 2; `Int 3])];
`List [`String "foo"; `String "bar"];
`List [];
`Null;
`List [`Int 1; `Int 2; `Int 3];
`Int 99;
`Assoc [("foo", `Int 7); ("bar", `Int 8); ("baz", `Int 43)];
`Assoc [("foo2", `Int 5); ("bar2", `Int 6); ("baz2", `Int 41); ("42", `Int 42)];
`List [`Int 100; `String "foo"];
`List [`Int 100; `Int 200; `Int 42];
`List [`Int 100; `Int 200; `Int (-1)];
`List [
`String "V1";
`String "v22";
`List [`String "V3"; `String "testing"];
`List [`String "V44"; `Int 255];
`List [`String "V5"; `String "None"];
`List [`String "V5"; `List [`String "Some"; `Bool true]]
];
`Assoc [("v2", `String "A")];
`Assoc [("v2", `List [`String "B"; `Int 100])];
`List [
`String "C1";
`List [`String "C2"; `Bool true];
`List [`String "C2"; `Bool false]];
`List[`Int 50; `Int 30; `Int (-1); `Int 400];
]

let pp_json fmt json =
Format.pp_print_string fmt (Yojson.Safe.pretty_to_string ~std:true json)

let () =
Format.printf "%a\n" pp_json massive_json
25 changes: 16 additions & 9 deletions test/pretty/dune
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
(executable
(name test)
(executables
(names test atd)
(libraries yojson))

(rule
(targets test.output)
(deps ./sample.json ./test.exe)
(action
(with-stdout-to
%{targets}
(run ./test.exe))))
(deps ./sample.json)
(action
(with-stdout-to
test.output.json
(run ./test.exe))))

(rule
(action
(with-stdout-to
atd.output.json
(run ./atd.exe))))

(alias
(name runtest)
(action
(diff test.expected test.output)))
(progn
(diff test.expected.json test.output.json)
(diff atd.expected.json atd.output.json))))
File renamed without changes.

0 comments on commit 40db674

Please sign in to comment.