Skip to content

Commit

Permalink
chore: Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
spotandjake committed Jan 24, 2024
1 parent 9b7312b commit c385c26
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
7 changes: 7 additions & 0 deletions compiler/test/graindoc/singleReturn.input.gr
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module SingleReturn

/**
* @returns first return
* @returns second return
*/
provide let test = () => 1
7 changes: 7 additions & 0 deletions compiler/test/graindoc/singleSince.input.gr
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module SingleSince

/**
* @since v1.0.0
* @since v1.0.0
*/
provide let test = () => print("t")
11 changes: 11 additions & 0 deletions compiler/test/runner.re
Original file line number Diff line number Diff line change
Expand Up @@ -487,3 +487,14 @@ let makeGrainDocRunner = (test, name, filename, arguments) => {
},
);
};

let makeGrainDocErrorRunner = (test, name, filename, expected, arguments) => {
test(
name,
({expect}) => {
let infile = gaindoc_in_file(filename);
let (result, _) = doc(infile, arguments);
expect.string(result).toMatch(expected);
},
);
};
13 changes: 13 additions & 0 deletions compiler/test/suites/graindoc.re
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ describe("graindoc", ({test, testSkip}) => {
Sys.backend_type == Other("js_of_ocaml") ? testSkip : test;

let assertGrianDocOutput = makeGrainDocRunner(test_or_skip);
let assertGrainDocError = makeGrainDocErrorRunner(test_or_skip);
();
assertGrianDocOutput("noDoc", "noDoc", [||]);
assertGrianDocOutput(
Expand All @@ -18,4 +19,16 @@ describe("graindoc", ({test, testSkip}) => {
);
assertGrianDocOutput("since", "since", [|"--current-version=v0.2.0"|]);
assertGrianDocOutput("example", "example", [|"--current-version=v0.2.0"|]);
assertGrainDocError(
"singleSince",
"singleSince",
"Attribute @since is only allowed to appear once.",
[|"--current-version=v0.2.0"|],
);
assertGrainDocError(
"singleReturn",
"singleReturn",
"Attribute @returns is only allowed to appear once.",
[|"--current-version=v0.2.0"|],
);
});

0 comments on commit c385c26

Please sign in to comment.