@@ -14,7 +14,9 @@ import qualified Data.ByteString as B
14
14
import Data.ByteString.Char8 ()
15
15
import qualified Data.ByteString.Lazy as LB
16
16
import qualified Data.Text as T
17
+ import qualified Data.Text.Array as TA
17
18
import qualified Data.Text.Encoding as TE
19
+ import qualified Data.Text.Internal as T
18
20
import qualified Data.Text.IO as T
19
21
import qualified Data.Text.Lazy as LT
20
22
import qualified Data.Text.Lazy.Encoding as LE
@@ -95,6 +97,24 @@ t227 =
95
97
(T. length $ T. filter isLetter $ T. take (- 3 ) " Hello! How are you doing today?" )
96
98
0
97
99
100
+ -- See GitHub issue #301
101
+ -- This tests whether the "TEXT take . drop -> unfused" rule is applied to the
102
+ -- slice function. When the slice function is fused, a new array will be
103
+ -- constructed that is shorter than the original array. Without fusion the
104
+ -- array remains unmodified.
105
+ t301 :: IO ()
106
+ t301 = do
107
+ assertEqual " The length of the array remains the same despite slicing"
108
+ (TA. length originalArr)
109
+ (TA. length newArr)
110
+
111
+ assertEqual " The new array still contains the original value"
112
+ (T. Text newArr originalOff originalLen)
113
+ original
114
+ where
115
+ original@ (T. Text originalArr originalOff originalLen) = T. pack " 1234567890"
116
+ T. Text newArr _off _len = T. take 1 $ T. drop 1 original
117
+
98
118
tests :: F. Test
99
119
tests = F. testGroup " Regressions"
100
120
[ F. testCase " hGetContents_crash" hGetContents_crash
@@ -105,4 +125,5 @@ tests = F.testGroup "Regressions"
105
125
, F. testCase " t197" t197
106
126
, F. testCase " t221" t221
107
127
, F. testCase " t227" t227
128
+ , F. testCase " t301" t301
108
129
]
0 commit comments