"Fossies" - the Fresh Open Source Software Archive

Member "ponyc-0.33.0/packages/time/_test.pony" (1 Nov 2019, 1660 Bytes) of package /linux/misc/ponyc-0.33.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Pony source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 use "ponytest"
    2 
    3 actor Main is TestList
    4   new create(env: Env) => PonyTest(env, this)
    5   new make() => None
    6 
    7   fun tag tests(test: PonyTest) =>
    8     test(_TestNanos)
    9     test(_TestPosixDate)
   10 
   11 class iso _TestNanos is UnitTest
   12   fun name(): String => "time/Nanos"
   13 
   14   fun apply(h: TestHelper) =>
   15     h.assert_eq[U64](5_000_000_000, Nanos.from_seconds(5))
   16     h.assert_eq[U64](5_000_000, Nanos.from_millis(5))
   17     h.assert_eq[U64](5_000, Nanos.from_micros(5))
   18 
   19     h.assert_eq[U64](1_230_000_000, Nanos.from_seconds_f(1.23))
   20     h.assert_eq[U64](1_230_000, Nanos.from_millis_f(1.23))
   21     h.assert_eq[U64](1_230, Nanos.from_micros_f(1.23))
   22 
   23 class iso _TestPosixDate is UnitTest
   24   fun name(): String => "time/PosixDate"
   25 
   26   fun apply(h: TestHelper) =>
   27     // time is in seconds
   28     h.assert_eq[I64](0, PosixDate(0, 0).time())
   29     h.assert_eq[I64](1, PosixDate(1, 0).time())
   30     // small nanoseconds can not affect time
   31     h.assert_eq[I64](0, PosixDate(0, 900_000_000).time())
   32     // big nanoseconds can affect time
   33     h.assert_eq[I64](1, PosixDate(0, 1_000_000_000).time())
   34     h.assert_eq[I64](2, PosixDate(1, 1_000_000_000).time())
   35     // negaive seconds should be changed to zero
   36     h.assert_eq[I64](0, PosixDate(-1, 0).time())
   37     h.assert_eq[I64](1, PosixDate(-1, 1_000_000_000).time())
   38     // negative nanoseconds cannot not affect time
   39     h.assert_eq[I64](1, PosixDate(1, -1_000_000_000).time())
   40 
   41     // Windows should throw error when %L is in format string
   42     ifdef windows then
   43       h.assert_error({() ? =>
   44         (let seconds, let nanos) = Time.now()
   45         let d = PosixDate(seconds, nanos)
   46         d.format("%Y-%m-%d %H:%M:%S.%L")?
   47       })
   48     end