Skip to content

Commit

Permalink
Merge pull request #1571 from xodio/feat-1537-tabtest-comments
Browse files Browse the repository at this point in the history
Support comments in tabtests
  • Loading branch information
brusherru authored Nov 28, 2018
2 parents 5904622 + a242480 commit 301ec56
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/xod-tabtest/src/TabData.re
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,24 @@ let map = List.map;

let mapWithIndex = List.mapWithIndex;

let commentsRegEx = [%re
/* Finds comments started with "//" and ignores it inside quotes */
{|/\/\/(.(?=([^"]*"[^"]*")*[^"]*$))+/gm|}
];

let emptyLinesRegEx = [%re {|/^\s+$/gm|}];

let tabSplit = x =>
Js.String.split("\t", x) |. List.fromArray |. List.map(Js.String.trim);

let parse = (tsvSource: string) : t =>
tsvSource
|> Js.String.replaceByRe([%re {|/\r/gm|}], "")
|> Js.String.replaceByRe(commentsRegEx, "")
|> Js.String.replaceByRe(emptyLinesRegEx, "")
|> Js.String.split("\n")
|> List.fromArray
|. List.keep(x => x != "")
|> (
lines =>
switch (List.head(lines)) {
Expand Down
36 changes: 36 additions & 0 deletions packages/xod-tabtest/test/TabData_jest.re
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,42 @@ describe("TSV parser", () => {
];
expect(TabData.parse(tsv)) |> toEqual(expected);
});
test("skips empty lines and comments", () => {
let tsv =
"A\tB\tC\n"
++ "// This comment should be ommited\n"
++ "1\ttrue\t\"Hey\"\n"
++ "\t\t\n"
++ " \t \t \n"
++ "\n"
++ " \t \t //--This line and three above should be ommited too\n"
++ "2\tfalse\t\"Hello\" // Comment should be ommited\n"
++ "3\tfalse\t\"Slashes inside //String should not be ommited\" // This comment should be ommited\n"
++ "4\ttrue\t\"\"";
let expected: TabData.t = [
Map.String.fromArray([|
("A", Number(1.0)),
("B", Boolean(true)),
("C", String("Hey")),
|]),
Map.String.fromArray([|
("A", Number(2.0)),
("B", Boolean(false)),
("C", String("Hello")),
|]),
Map.String.fromArray([|
("A", Number(3.0)),
("B", Boolean(false)),
("C", String("Slashes inside //String should not be ommited")),
|]),
Map.String.fromArray([|
("A", Number(4.0)),
("B", Boolean(true)),
("C", String("")),
|]),
];
expect(TabData.parse(tsv)) |> toEqual(expected);
});
test("recognizes types", () => {
let tsv =
"Number\tBoolean\tByte\tString\tPulse\n"
Expand Down

0 comments on commit 301ec56

Please sign in to comment.