SIGN IN SIGN UP
reasonml / reason UNCLAIMED

Simple, fast & type safe code that leverages the JavaScript & OCaml ecosystems

0 0 161 OCaml
Migrate tests to cram suite (#2694) * test(refmt) Add basic type-check tests to cram * test(refmt) Make ocamlc a valid windows script * test(refmt) Hide refmt_impl.exe under run-refmt.sh * test(refmt) Remove run-refmt * test(refmt) Fix path for run-ocamlc * test(refmt) Remove ocamlc check * refactor(refmt) Make run-ocamlc available to run everywhere * refactor(refmt) Remove failing dir * fix(refmt_test) cd work in windows * test(refmt) Check ocamlc instalation working * test(refmt) Remove ocamlc check * test(refmt) Remove set in run-ocamlc * test(refmt) Enable debug to see Windows command * test(refmt) Remove binary from refmt * test(refmt) Revert binary from refmt * test(refmt) Move to direct path * test(refmt) Try ./ and ocamlopt * test(refmt) export readlink * test(refmt) Assign variable based on the path * test(refmt) Try with bash * test(refmt) Add readlink to REFMT * test(refmt) Add batch and sh script for refmt * test(refmt) Setup refmt_impl as binary * test(refmt) Remove batch and sh wrappers * test(refmt) Remove --print-width and set REFMT_PRINT_WIDTH as env var * test(refmt) Trying single quote, wat * test(refmt) buildInSource and run refmt in cram * test(refmt) Revert buildInSource and run esy x * test(refmt) Remove refmt_impl for print w and debug PATH * test(refmt) Add -p reason * test(refmt) Update dune * test(refmt) Remove logging on PATH * Add idempotency test in basics * Add error test * Add testOprint case * Moved and renamed testOprint into refmt_test/ folder * Remove OCaml-versioned based cram tests * Add backportSyntax * Add rtopIntegration * Move back testOprint into src * Trim rtop output * Remove the begining of the error message for OCaml 4.03 * Try tests based on ocaml version * Fix test 4.03 * Fix test for ocaml_version * Ensure works with 4.03 * Move test to 4.07 * Build all packages needed for tests in release mode * Don't build testOprint * Move testOprint inside refmt_test and rename to typedtree_printer * Ensure works with 4.08 * Remove test.re from version test * Revert rename on reason-parser-test * Revert debugging on test.sh * Improve safety for rtop * Migrate all error cases * Migrate all oprint tests * Migrate all typecheck tests * Clean up tests * Enable 4.03 in CI * Move newast to 4.06 * Fix 4.10 tests * Move mlsyntax to 4.08 * Move type-trailing to 4.04 * Remove 4.03 * Fix 4.06 test * Fix 4.08 tests * Fix 4.10 tests * Fix 4.12 tests * Remove 4.04 since we have them on 4.06 * Update ocamlfind to 1.9.6 * Rollback ocamlfind to 1.9.5 * Disable tests on windows in 4.12 * Remove debugging * Change path and condition * Disable all tests in win * Install right OCaml in esy ci * Explain how to run different ocaml versions for testing * Remove empty space from pattern matching
2023-03-20 20:10:30 +01:00
Format basic
$ refmt --print re ./input.re > ./formatted.re
Print the formatted file
$ cat ./formatted.re
type point = {
x: int,
y: int,
};
let id = x => x;
type myVariant =
| TwoCombos(inner, inner)
| Short
| AlsoHasARecord(int, int, point)
and inner =
| Unused
| HeresTwoConstructorArguments(int, int);
let computeTuple = (a, b, c, d, e, f, g, h) => (
a + b,
c + d,
e + f,
g + h,
);
let res =
switch (TwoCombos(Unused, Unused)) {
| TwoCombos(
HeresTwoConstructorArguments(x, y),
HeresTwoConstructorArguments(a, b),
) => (
x,
y,
a,
b,
)
| TwoCombos(_, _) => (0, 0, 0, 0)
| Short
| AlsoHasARecord(300, _, _) => (
100000,
100000,
100000,
100000,
)
| AlsoHasARecord(firstItem, two, { x, y }) =>
computeTuple(
firstItem,
firstItem,
firstItem,
firstItem,
firstItem,
two,
two,
two,
)
};
/**
* Match bodies may include sequence expressions, but without the `{}`
* braces required.
*/
let res =
switch (TwoCombos(Unused, Unused)) {
| TwoCombos(
HeresTwoConstructorArguments(x, y),
HeresTwoConstructorArguments(a, b),
) =>
let ret = (x, y, a, b);
ret;
| TwoCombos(_, _) =>
/**
* See, no braces required - saves indentation as well!
*/
let ret = (0, 0, 0, 0);
ret;
| Short
| AlsoHasARecord(300, _, _) =>
/**
* And no final semicolon is required.
*/
let ret = (100000, 100000, 100000, 100000);
ret;
| AlsoHasARecord(firstItem, two, { x, y }) =>
computeTuple(
firstItem,
firstItem,
firstItem,
firstItem,
firstItem,
two,
two,
two,
)
};
/**
* Ensure that nested Pexp_functions are correctly wrapped in parens.
*
*/
let res =
switch (TwoCombos(Unused, Unused)) {
| TwoCombos(
HeresTwoConstructorArguments(x, y),
HeresTwoConstructorArguments(a, b),
) => (
fun
| Some(x) => x + 1
| None => 0
)
| TwoCombos(_, _) =>
let x = (
fun
| Some(x) => x + 1
| None => 0
);
x;
| Short
| AlsoHasARecord(300, _, _) =>
id(
fun
| Some(x) => x + 1
| None => 0,
)
| AlsoHasARecord(firstItem, two, { x, y }) =>
id(
fun
| Some(x) => x + 1
| None => 0,
)
};
/* test (), which is sugar for (()) */
switch (Some()) {
| Some () => 1
| _ => 2
};
switch (Some()) {
| Some () => 1
| _ => 2
};
switch (Some()) {
| Some () => 1
| _ => 2
};
switch (Some()) {
| Some () => 1
| _ => 2
};
type foo =
| Foo(unit);
switch (Foo()) {
| Foo () => 1
};
switch (Foo()) {
| Foo () => 1
};
switch (Foo()) {
| Foo () => 1
};
switch (Foo()) {
| Foo () => 1
};
switch () {
| () => 1
};
switch () {
| () => 1
};
switch () {
| () => 1
};
switch () {
| () => 1
};
switch (Some(1)) {
| Some(1) => 1
| None => 2
| _ => 3
};
let myInt = 100;
/* Numeric ranges are rejected by the type checker, but validly parsed so drop
* this in an annotation to test the parsing. */
[@something? 1 .. 2]
let rangeInt = 0;
let myChar = 'x';
let rangeChar =
switch (myChar) {
| 'a' .. 'b' => "a to b"
| 'b' .. 'z' => "b to z"
| c => "something else"
};
/* with parens around direct list pattern in constructor pattern */
switch (None) {
| Some([]) => ()
| Some([_]) when true => ()
| Some([x]) => ()
| Some([x, ...xs]) when true => ()
| Some([x, y, z]) => ()
| _ => ()
};
/* no parens around direct list pattern in constructor pattern (sugar) */
switch (None) {
| Some([]) => ()
| Some([_]) when true => ()
| Some([x]) => ()
| Some([x, ...xs]) when true => ()
| Some([x, y, z]) => ()
| _ => ()
};
/* with parens around direct array pattern in constructor pattern */
switch (None) {
| Some([||]) => "empty"
| Some([|_|]) when true => "one any"
| Some([|a|]) => "one"
| Some([|a, b|]) => "two"
| _ => "many"
};
/* no parens around direct array pattern in constructor pattern (sugar) */
switch (None) {
| Some([||]) => "empty"
| Some([|_|]) when true => "one any"
| Some([|a|]) => "one"
| Some([|a, b|]) => "two"
| _ => "many"
};
/* parens around direct record pattern in constructor pattern */
switch (None) {
| Some({ x }) when true => ()
| Some({ x, y }) => ()
| _ => ()
};
/* no parens around direct record pattern in constructor pattern (sugar) */
switch (None) {
| Some({ x }) when true => ()
| Some({ x, y }) => ()
| _ => ()
};
switch (None) {
| Some([|
someSuperLongString,
thisShouldBreakTheLine,
|]) =>
()
| _ => ()
};
switch (None) {
| Some((
someSuperLongString,
thisShouldBreakTheLine,
)) =>
()
| _ => ()
};
switch (None) {
| Some([
someSuperLongString,
thisShouldBreakTheLine,
]) =>
()
| Some([
someSuperLongString,
...es6ListSugarLikeSyntaxWhichIsSuperLong,
])
when true === true =>
()
| Some([
someSuperLongString,
...es6ListSugarLikeSyntaxWhichIsSuperLong,
]) =>
()
| _ => ()
};
type aOrB =
| A(int)
| B(int);
let ((nestedAnnotation: int): int) = 0;
let ((A(i) | B(i)): aOrB) = A(0);
type test_foo =
| VariantType1
| VariantType2;
let branch_with_variant_and_annotation =
fun
| (VariantType1: test_foo) => true
| VariantType2 => false;
type intRange = {
from: option(string),
to_: option(string),
};
type optIntRange = option(intRange);
let optIntRangeOfIntRange =
fun
| ({ from: None, to_: None }: intRange) => (
None: optIntRange
)
| { from, to_ } =>
Some({
from,
to_,
});
Migrate tests to cram suite (#2694) * test(refmt) Add basic type-check tests to cram * test(refmt) Make ocamlc a valid windows script * test(refmt) Hide refmt_impl.exe under run-refmt.sh * test(refmt) Remove run-refmt * test(refmt) Fix path for run-ocamlc * test(refmt) Remove ocamlc check * refactor(refmt) Make run-ocamlc available to run everywhere * refactor(refmt) Remove failing dir * fix(refmt_test) cd work in windows * test(refmt) Check ocamlc instalation working * test(refmt) Remove ocamlc check * test(refmt) Remove set in run-ocamlc * test(refmt) Enable debug to see Windows command * test(refmt) Remove binary from refmt * test(refmt) Revert binary from refmt * test(refmt) Move to direct path * test(refmt) Try ./ and ocamlopt * test(refmt) export readlink * test(refmt) Assign variable based on the path * test(refmt) Try with bash * test(refmt) Add readlink to REFMT * test(refmt) Add batch and sh script for refmt * test(refmt) Setup refmt_impl as binary * test(refmt) Remove batch and sh wrappers * test(refmt) Remove --print-width and set REFMT_PRINT_WIDTH as env var * test(refmt) Trying single quote, wat * test(refmt) buildInSource and run refmt in cram * test(refmt) Revert buildInSource and run esy x * test(refmt) Remove refmt_impl for print w and debug PATH * test(refmt) Add -p reason * test(refmt) Update dune * test(refmt) Remove logging on PATH * Add idempotency test in basics * Add error test * Add testOprint case * Moved and renamed testOprint into refmt_test/ folder * Remove OCaml-versioned based cram tests * Add backportSyntax * Add rtopIntegration * Move back testOprint into src * Trim rtop output * Remove the begining of the error message for OCaml 4.03 * Try tests based on ocaml version * Fix test 4.03 * Fix test for ocaml_version * Ensure works with 4.03 * Move test to 4.07 * Build all packages needed for tests in release mode * Don't build testOprint * Move testOprint inside refmt_test and rename to typedtree_printer * Ensure works with 4.08 * Remove test.re from version test * Revert rename on reason-parser-test * Revert debugging on test.sh * Improve safety for rtop * Migrate all error cases * Migrate all oprint tests * Migrate all typecheck tests * Clean up tests * Enable 4.03 in CI * Move newast to 4.06 * Fix 4.10 tests * Move mlsyntax to 4.08 * Move type-trailing to 4.04 * Remove 4.03 * Fix 4.06 test * Fix 4.08 tests * Fix 4.10 tests * Fix 4.12 tests * Remove 4.04 since we have them on 4.06 * Update ocamlfind to 1.9.6 * Rollback ocamlfind to 1.9.5 * Disable tests on windows in 4.12 * Remove debugging * Change path and condition * Disable all tests in win * Install right OCaml in esy ci * Explain how to run different ocaml versions for testing * Remove empty space from pattern matching
2023-03-20 20:10:30 +01:00
Type-check basics
$ ocamlc -c -pp 'refmt --print binary' -intf-suffix .rei -impl formatted.re
Format the formatted file back
$ refmt --print re ./formatted.re > ./formatted_back.re
Ensure idempotency: first format and second format are the same
$ diff formatted.re formatted_back.re