diff options
author | Sylvain Henry <sylvain@haskus.fr> | 2020-04-24 14:38:54 +0200 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2020-04-27 20:24:46 -0400 |
commit | 99823ed24b22447b14202ca57f75550773c44dbe (patch) | |
tree | 6dd2de048e4f245dd3d29b86ee47de7302f13652 /testsuite | |
parent | 22bf5c738e0339fa12940414d6448896c6733808 (diff) | |
download | haskell-99823ed24b22447b14202ca57f75550773c44dbe.tar.gz |
TH: fix Show/Eq/Ord instances for Bytes (#16457)
We shouldn't compare pointer values but the actual bytes.
Diffstat (limited to 'testsuite')
-rw-r--r-- | testsuite/tests/th/TH_BytesShowEqOrd.hs | 40 | ||||
-rw-r--r-- | testsuite/tests/th/TH_BytesShowEqOrd.stdout | 6 | ||||
-rw-r--r-- | testsuite/tests/th/all.T | 1 |
3 files changed, 47 insertions, 0 deletions
diff --git a/testsuite/tests/th/TH_BytesShowEqOrd.hs b/testsuite/tests/th/TH_BytesShowEqOrd.hs new file mode 100644 index 0000000000..e7640a7df3 --- /dev/null +++ b/testsuite/tests/th/TH_BytesShowEqOrd.hs @@ -0,0 +1,40 @@ +{-# LANGUAGE MagicHash #-} +{-# LANGUAGE BangPatterns #-} + +module Main where + +import Language.Haskell.TH.Lib +import GHC.Ptr +import Foreign.ForeignPtr + +main :: IO () +main = do + + let + !x = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"# + !y = "ABCDEabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"# + + p1 <- newForeignPtr_ (Ptr x) + p2 <- newForeignPtr_ (Ptr y) + + let + b1 = mkBytes p1 0 5 + b2 = mkBytes p1 10 5 + b3 = mkBytes p1 26 5 + b4 = mkBytes p2 5 5 + b5 = mkBytes p2 10 5 + + let myCmp a b = putStrLn $ "compare " ++ show a ++ " to " ++ show b ++ " => " ++ show (compare a b) + + putStr "same pointer, same offset, same bytes: " + myCmp b1 b1 + putStr "same pointer, different offset, same bytes: " + myCmp b1 b3 + putStr "same pointer, different offset, different bytes: " + myCmp b1 b2 + putStr "same pointer, different offset, different bytes: " + myCmp b2 b1 + putStr "different pointer, different offset, same bytes: " + myCmp b1 b4 + putStr "different pointer, different offset, different bytes: " + myCmp b1 b5 diff --git a/testsuite/tests/th/TH_BytesShowEqOrd.stdout b/testsuite/tests/th/TH_BytesShowEqOrd.stdout new file mode 100644 index 0000000000..8da996586c --- /dev/null +++ b/testsuite/tests/th/TH_BytesShowEqOrd.stdout @@ -0,0 +1,6 @@ +same pointer, same offset, same bytes: compare abcde to abcde => EQ +same pointer, different offset, same bytes: compare abcde to abcde => EQ +same pointer, different offset, different bytes: compare abcde to klmno => LT +same pointer, different offset, different bytes: compare klmno to abcde => GT +different pointer, different offset, same bytes: compare abcde to abcde => EQ +different pointer, different offset, different bytes: compare abcde to fghij => LT diff --git a/testsuite/tests/th/all.T b/testsuite/tests/th/all.T index 127bdf665c..458b45d67f 100644 --- a/testsuite/tests/th/all.T +++ b/testsuite/tests/th/all.T @@ -504,3 +504,4 @@ test('T17688a', normal, compile, ['']) test('T17688b', normal, compile, ['']) test('TH_PprStar', normal, compile, ['-v0 -dsuppress-uniques']) test('TH_StringLift', normal, compile, ['']) +test('TH_BytesShowEqOrd', normal, compile_and_run, ['']) |