UNPKG

@brimdata/zealot

Version:

The Javascript Client for Zed Lakes

170 lines (169 loc) 3.73 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const _duration = require("./duration"); const cases = [ [ "0s", 0n ], [ "5s", 5n * _duration.Second ], [ "30s", 30n * _duration.Second ], [ "1478s", 1478n * _duration.Second ], // minus sign [ "-5s", -5n * _duration.Second ], [ "-0s", 0n ], [ "+0s", 0n ], // decimal [ "5.0s", 5n * _duration.Second ], [ "5.6s", 5n * _duration.Second + 600n * _duration.Millisecond ], [ "5.s", 5n * _duration.Second ], [ ".5s", 500n * _duration.Millisecond ], [ "1.0s", 1n * _duration.Second ], [ "1.00s", 1n * _duration.Second ], [ "1.004s", 1n * _duration.Second + 4n * _duration.Millisecond ], [ "1.0040s", 1n * _duration.Second + 4n * _duration.Millisecond ], [ "100.00100s", 100n * _duration.Second + 1n * _duration.Millisecond ], // different units [ "10ns", 10n * _duration.Nanosecond ], [ "11us", 11n * _duration.Microsecond ], [ "13ms", 13n * _duration.Millisecond ], [ "14s", 14n * _duration.Second ], [ "15m", 15n * _duration.Minute ], [ "16h", 16n * _duration.Hour ], // composite durations [ "3h30m", 3n * _duration.Hour + 30n * _duration.Minute ], [ "10.5s4m", 4n * _duration.Minute + 10n * _duration.Second + 500n * _duration.Millisecond ], [ "-2m3.4s", -(2n * _duration.Minute + 3n * _duration.Second + 400n * _duration.Millisecond) ], [ "1h2m3s4ms5us6ns", 1n * _duration.Hour + 2n * _duration.Minute + 3n * _duration.Second + 4n * _duration.Millisecond + 5n * _duration.Microsecond + 6n * _duration.Nanosecond ], [ "39h9m14.425s", 39n * _duration.Hour + 9n * _duration.Minute + 14n * _duration.Second + 425n * _duration.Millisecond ], // large value [ "52763797000ns", 52763797000n * _duration.Nanosecond ], // more than 9 digits after decimal point, see https://golang.org/issue/6617 [ "0.3333333333333333333h", 20n * _duration.Minute ], // 9007199254740993 = 1<<53+1 cannot be stored precisely in a float64 [ "9007199254740993ns", (1n << 53n) + 1n * _duration.Nanosecond ], // largest duration that can be represented by int64 in nanoseconds [ "9223372036854775807ns", (1n << 63n) - 1n * _duration.Nanosecond ], [ "9223372036854775.807us", (1n << 63n) - 1n * _duration.Nanosecond ], [ "9223372036s854ms775us807ns", (1n << 63n) - 1n * _duration.Nanosecond ], // large negative value [ "-9223372036854775807ns", (-1n << 63n) + 1n * _duration.Nanosecond ], // huge string; issue 15011. [ "0.100000000000000000000h", 6n * _duration.Minute ], // This value tests the first overflow check in leadingFraction. [ "0.830103483285477580700h", 49n * _duration.Minute + 48n * _duration.Second + 372539827n * _duration.Nanosecond ] ]; describe("go test library", ()=>{ for (const [input, expected] of cases){ test("input: " + input, ()=>{ expect(new _duration.Duration(input).asNanos()).toEqual(expected); }); } });