refactor(xod-tabtest): get rid of special handing of "__time(ms)" column in TabData module

This commit is contained in:
Kirill Shumilov
2018-11-29 19:02:18 +03:00
parent 11cd0b79f7
commit 29e61ba975
5 changed files with 4 additions and 36 deletions

View File

@@ -1,3 +1 @@
let time = "__time(ms)";
let list = [time];

View File

@@ -12,9 +12,7 @@ module Value = {
| String(string)
| Byte(int)
| Pulse(bool)
| Millis(int)
| Invalid(string);
let uintRegex = [%re {|/^\d+$/|}];
let numberRegex = [%re {|/^[+-]?(?=.)*\d*(?:\.\d+)?$/|}];
let approxNumberRegex = [%re {|/^[+-]?(?=.)*\d*(?:\.\d+)?~$/|}];
let stringRegex = [%re {|/^".*"$/|}];
@@ -64,12 +62,6 @@ module Value = {
byteStringToInt(byteString)
| x => Invalid(x)
};
let parseTime = str =>
switch (str) {
| timeString when Re.test(timeString, uintRegex) =>
Millis(int_of_string(timeString))
| x => Invalid(x)
};
};
module Record = {
@@ -120,13 +112,9 @@ let parse = (tsvSource: string) : t =>
| None => []
| Some(firstLine) =>
let header = tabSplit(firstLine);
let timeColumnIndex =
header |. List.toArray |> Js.Array.indexOf("__time(ms)");
let lineToRecord = (line: string) : Record.t =>
tabSplit(line)
|. List.mapWithIndex((i, el) =>
i === timeColumnIndex ? Value.parseTime(el) : Value.parse(el)
)
|. List.map(Value.parse)
|. List.zip(header, _)
|. Record.fromPairs;
List.tailExn(lines)

View File

@@ -19,7 +19,6 @@ module Value: {
| String(string)
| Byte(int)
| Pulse(bool)
| Millis(int)
| Invalid(string);
};

View File

@@ -211,7 +211,9 @@ module TestCase = {
});
let setTimeStatement =
switch (record |. TabData.Record.get(SpecialColumns.time)) {
| Some(Millis(t)) => {j|mockTime($t);|j}
| Some(Number(t)) =>
let time = int_of_float(t);
{j|mockTime($time);|j};
| Some(_)
| None => "mockTime(millis() + 1);"
};

View File

@@ -125,23 +125,4 @@ describe("TSV parser", () => {
];
expect(TabData.parse(tsv)) |> toEqual(expected);
});
test("recognizes time column", () => {
let tsv =
"__time(ms)\tNumber\n" ++ "0\t0\n" ++ "500\t0.5\n" ++ "1200\t1.2";
let expected: TabData.t = [
Map.String.fromArray([|
("__time(ms)", Millis(0)),
("Number", Number(0.0)),
|]),
Map.String.fromArray([|
("__time(ms)", Millis(500)),
("Number", Number(0.5)),
|]),
Map.String.fromArray([|
("__time(ms)", Millis(1200)),
("Number", Number(1.2)),
|]),
];
expect(TabData.parse(tsv)) |> toEqual(expected);
});
});