Skip to content

Commit

Permalink
add tests for printing Inf/NaN
Browse files Browse the repository at this point in the history
  • Loading branch information
Ptival committed Feb 27, 2024
1 parent f6981ec commit 1977949
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions test/Output.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module Output ( tests ) where

import Control.Monad ( unless )
import qualified Data.Text as T
import GHC.Float (castWord32ToFloat, castWord64ToDouble)
import qualified Test.Tasty as Tasty
import Test.Tasty.HUnit
import qualified Text.PrettyPrint as PP
Expand Down Expand Up @@ -243,6 +244,46 @@ tests = Tasty.testGroup "LLVM pretty-printing output tests"
--------
|]

, testCase "Positive Infinity (float)" $
assertEqLines
(ppToText $ ppLLVM37 ppValue (ValFloat (castWord32ToFloat 0x7F800000)))
"0x7f800000"

, testCase "Negative Infinity (float)" $
assertEqLines
(ppToText $ ppLLVM37 ppValue (ValFloat (castWord32ToFloat 0xFF800000)))
"0xff800000"

, testCase "NaN 1 (float)" $
assertEqLines
(ppToText $ ppLLVM37 ppValue (ValFloat (castWord32ToFloat 0x7FC00000)))
"0x7fc00000"

, testCase "NaN 2 (float)" $
assertEqLines
(ppToText $ ppLLVM37 ppValue (ValFloat (castWord32ToFloat 0x7FD00000)))
"0x7fd00000"

, testCase "Positive Infinity (double)" $
assertEqLines
(ppToText $ ppLLVM37 ppValue (ValDouble (castWord64ToDouble 0x7FF0000000000000)))
"0x7ff0000000000000"

, testCase "Negative Infinity (double)" $
assertEqLines
(ppToText $ ppLLVM37 ppValue (ValDouble (castWord64ToDouble 0xFFF0000000000000)))
"0xfff0000000000000"

, testCase "NaN 1 (double)" $
assertEqLines
(ppToText $ ppLLVM37 ppValue (ValDouble (castWord64ToDouble 0x7FFC000000000000)))
"0x7ffc000000000000"

, testCase "NaN 2 (double)" $
assertEqLines
(ppToText $ ppLLVM37 ppValue (ValDouble (castWord64ToDouble 0x7FFD000000000000)))
"0x7ffd000000000000"

]

----------------------------------------------------------------------
Expand Down

0 comments on commit 1977949

Please sign in to comment.