mirror of
https://github.com/xodio/xod.git
synced 2026-03-24 17:46:56 +01:00
refactor(xod-tabtest): get rid of special handing of "__time(ms)" column in TabData module
This commit is contained in:
@@ -1,3 +1 @@
|
||||
let time = "__time(ms)";
|
||||
|
||||
let list = [time];
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -19,7 +19,6 @@ module Value: {
|
||||
| String(string)
|
||||
| Byte(int)
|
||||
| Pulse(bool)
|
||||
| Millis(int)
|
||||
| Invalid(string);
|
||||
};
|
||||
|
||||
|
||||
@@ -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);"
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user