Skip to content

Commit

Permalink
chore(compiler): Convert inline tests to rely tests (#1277)
Browse files Browse the repository at this point in the history
  • Loading branch information
phated authored May 29, 2022
1 parent d491db8 commit acec7ff
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 109 deletions.
2 changes: 0 additions & 2 deletions compiler/src/utils/dune
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
(synopsis "Utilities for the Grain compiler")
(libraries fp fs.lib cmdliner compiler-libs.common ppx_sexp_conv.runtime-lib
sexplib str)
;Temporarily disabled due to https://github.com/janestreet/ppx_inline_test/issues/23
;(inline_tests)
(preprocess
(pps ppx_sexp_conv))
(js_of_ocaml
Expand Down
107 changes: 0 additions & 107 deletions compiler/src/utils/string_utils.re
Original file line number Diff line number Diff line change
Expand Up @@ -93,110 +93,3 @@ let trim_each_line = (~style=FullTrim, str) => {

lines |> List.map(trim_style) |> String.concat("\n");
};

/** TODO(#436): Re-enable these when we can include in the Windows build
let%expect_test "empty string" = {
print_endline(slice(""));
%expect
{||};
};
let%expect_test "no first/last" = {
print_endline(slice("abc"));
%expect
{| abc |};
};
let%expect_test "last: positive index within string" = {
print_endline(slice(~last=1, "abc"));
%expect
{| a |};
};
let%expect_test "last: string length" = {
let str = "abc";
print_endline(slice(~last=String.length(str), str));
%expect
{| abc |};
};
let%expect_test "last: greater than length" = {
print_endline(slice(~last=5, "abc"));
%expect
{| abc |};
};
let%expect_test "last: negative index (wraps)" = {
print_endline(slice(~last=-1, "abc"));
%expect
{| ab |};
};
let%expect_test "first: positive index within string" = {
print_endline(slice(~first=1, "abc"));
%expect
{| bc |};
};
let%expect_test "first: string length" = {
let str = "abc";
print_endline(slice(~first=String.length(str), str));
%expect
{||};
};
let%expect_test "first: greater than length" = {
print_endline(slice(~first=4, "abc"));
%expect
{||};
};
let%expect_test "first: negative index (wraps)" = {
print_endline(slice(~first=-1, "abc"));
%expect
{| c |};
};
let%expect_test "first + last: positive indexes within string" = {
print_endline(slice(~first=1, ~last=2, "abc"));
%expect
{| b |};
};
let%expect_test "first + last: overlapping indexes" = {
print_endline(slice(~first=1, ~last=1, "abc"));
%expect
{||};
};
let%expect_test "first + last: wrapping first with appropriate last" = {
let str = "abc";
print_endline(slice(~first=-1, ~last=String.length(str), str));
%expect
{| c |};
};
let%expect_test "first + last: incorrect wrapping" = {
print_endline(slice(~first=-1, ~last=1, "abc"));
%expect
{||};
};
let%expect_test "first + last: wrapping in last" = {
print_endline(slice(~first=1, ~last=-1, "abc"));
%expect
{| b |};
};
let%expect_test "first + last: greater than length" = {
print_endline(slice(~first=1, ~last=5, "abc"));
%expect
{| bc |};
};
let%expect_test "first + last: both negative" = {
print_endline(slice(~first=-2, ~last=-1, "abc"));
%expect
{| b |};
};
*/;
101 changes: 101 additions & 0 deletions compiler/test/utils/string_utils.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
open Grain_utils;

open Grain_tests.TestFramework;
open Grain_tests.Runner;

describe("utils/string_utils", ({describe}) => {
describe("slice", ({test}) => {
test("empty string", ({expect}) => {
expect.string(String_utils.slice("")).toEqual("")
});
test("no first/last", ({expect}) => {
expect.string(String_utils.slice("abc")).toEqual("abc")
});

test("last: positive index within string", ({expect}) => {
expect.string(String_utils.slice(~last=1, "abc")).toEqual("a")
});

test("last: string length", ({expect}) => {
let str = "abc";
expect.string(String_utils.slice(~last=String.length(str), str)).
toEqual(
"abc",
);
});

test("last: greater than length", ({expect}) => {
expect.string(String_utils.slice(~last=5, "abc")).toEqual("abc")
});

test("last: negative index (wraps)", ({expect}) => {
expect.string(String_utils.slice(~last=-1, "abc")).toEqual("ab")
});

test("first: positive index within string", ({expect}) => {
expect.string(String_utils.slice(~first=1, "abc")).toEqual("bc")
});

test("first: string length", ({expect}) => {
let str = "abc";
expect.string(String_utils.slice(~first=String.length(str), str)).
toEqual(
"",
);
});

test("first: greater than length", ({expect}) => {
expect.string(String_utils.slice(~first=4, "abc")).toEqual("")
});

test("first: negative index (wraps)", ({expect}) => {
expect.string(String_utils.slice(~first=-1, "abc")).toEqual("c")
});

test("first + last: positive indexes within string", ({expect}) => {
expect.string(String_utils.slice(~first=1, ~last=2, "abc")).toEqual(
"b",
)
});

test("first + last: overlapping indexes", ({expect}) => {
expect.string(String_utils.slice(~first=1, ~last=1, "abc")).toEqual(
"",
)
});

test("first + last: wrapping first with appropriate last", ({expect}) => {
let str = "abc";
expect.string(
String_utils.slice(~first=-1, ~last=String.length(str), str),
).
toEqual(
"c",
);
});

test("first + last: incorrect wrapping", ({expect}) => {
expect.string(String_utils.slice(~first=-1, ~last=1, "abc")).toEqual(
"",
)
});

test("first + last: wrapping in last", ({expect}) => {
expect.string(String_utils.slice(~first=1, ~last=-1, "abc")).toEqual(
"b",
)
});

test("first + last: greater than length", ({expect}) => {
expect.string(String_utils.slice(~first=1, ~last=5, "abc")).toEqual(
"bc",
)
});

test("first + last: both negative", ({expect}) => {
expect.string(String_utils.slice(~first=-2, ~last=-1, "abc")).toEqual(
"b",
)
});
})
});

0 comments on commit acec7ff

Please sign in to comment.