Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions old-time.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,16 @@ Library
build-tools: hsc2hs

ghc-options: -Wall

test-suite old-time-tests
type: exitcode-stdio-1.0
default-language: Haskell2010
ghc-options: -Wall
main-is: Tests.hs
hs-source-dirs: tests
build-depends:
base,
old-locale < 2,
old-time,
tasty < 2,
tasty-hunit < 1
14 changes: 0 additions & 14 deletions tests/.gitignore

This file was deleted.

7 changes: 0 additions & 7 deletions tests/Makefile

This file was deleted.

14 changes: 0 additions & 14 deletions tests/T5430.hs

This file was deleted.

1 change: 0 additions & 1 deletion tests/T5430.stdout

This file was deleted.

78 changes: 78 additions & 0 deletions tests/Tests.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
module Main (main) where

import System.Locale (defaultTimeLocale)
import System.Time
import Test.Tasty
import Test.Tasty.HUnit

main :: IO ()
main = defaultMain $ testGroup "All"
[ testCase "T5430" t5430
, testCase "time002" time002
, testCase "time003" time003
, testCase "time004" time004
, testCase "issue18" issue18
]

t5430 :: Assertion
t5430 = do
let clockTime = TOD 32400 0 -- 00:00:00 on 1 Jan 1970
calTime <- toCalendarTime clockTime
-- We check for 001 or 365 (timezone locale will determine which one)
-- and output 001 for testing output consistently.
let j = formatCalendarTime defaultTimeLocale "%j" calTime
assertBool "Either 001 or 365" $
j `elem` ["001", "365"]

time002 :: Assertion
time002 = do
t <- getClockTime
let clock = show t
c <- toCalendarTime t
let cal = calendarTimeToString c
let t2 = toClockTime c
clock2 = show t2
assertEqual "calendarTimeToString . toCalendarTime = id" clock cal
assertEqual "show . toClockTime . toCalendarTime = id" clock clock2

time003 :: Assertion
time003 = do
time <- getClockTime
assertBool "does show look plausible?" $
plausible (show time)

let (CalendarTime year month mday hour minute sec _psec
wday _yday timezone _gmtoff _isdst) = toUTCTime time
time2 = wdays !! fromEnum wday ++
(' ' : months !! fromEnum month) ++
(' ' : shows2 mday (' ' : shows2 hour (':' : shows2 minute (':' : shows2 sec
(' ' : timezone ++ ' ' : shows year "\n")))))
assertBool "does time2 look plausible?" $
plausible time2

where
wdays = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
shows2 x = showString (pad2 x)
pad2 x = case show x of
c@[_] -> '0' : c
cs -> cs

plausible str = filter (== ':') str == "::"

time004 :: Assertion
time004 = do
time <- getClockTime
let (CalendarTime year month mday hour minute sec psec
wday yday timezone gmtoff isdst) = toUTCTime time
time' = toClockTime (CalendarTime (year - 1) month mday hour minute sec psec
wday yday timezone gmtoff isdst)
assertEqual "should have same length"
(length (show time)) (length (show time'))

issue18 :: Assertion
issue18 = do
let c = TOD ((19078*24+2)*3600+1357) 0
assertEqual "noTimeDiff should not make a diff"
c (addToClockTime noTimeDiff c)
4 changes: 0 additions & 4 deletions tests/all.T

This file was deleted.

16 changes: 0 additions & 16 deletions tests/time002.hs

This file was deleted.

1 change: 0 additions & 1 deletion tests/time002.stdout

This file was deleted.

24 changes: 0 additions & 24 deletions tests/time003.hs

This file was deleted.

2 changes: 0 additions & 2 deletions tests/time003.stdout

This file was deleted.

10 changes: 0 additions & 10 deletions tests/time004.hs

This file was deleted.

1 change: 0 additions & 1 deletion tests/time004.stdout

This file was deleted.