packages feed

ptr 0.16.6 → 0.16.6.1

raw patch · 3 files changed

+27/−29 lines, 3 filesdep ~rerebasedep ~tastydep ~tasty-hunit

Dependency ranges changed: rerebase, tasty, tasty-hunit, tasty-quickcheck

Files

library/Ptr/Poking.hs view
@@ -112,25 +112,23 @@ pokeAndPeek (D.PokeAndPeek space poke _) input =   Poking space (\ptr -> poke ptr input) +{-| Unsigned ASCII integral -} {-# INLINABLE asciiIntegral #-}-asciiIntegral :: Integral a => a -> Poking-asciiIntegral =-  \case-    0 ->-      word8 48-    x ->-      bool ((<>) (word8 45)) id (x >= 0) $-      loop mempty $-      abs x-  where-    loop builder remainder =-      case remainder of-        0 ->-          builder-        _ ->-          case quotRem remainder 10 of-            (quot, rem) ->-              loop (word8 (48 + fromIntegral rem) <> builder) quot+asciiIntegral :: (Integral a) => a -> Poking+asciiIntegral = \ case+  0 -> word8 48+  x -> let+    lastIndex = (floor . logBase 10 . fromIntegral) x+    size = succ lastIndex+    action = let+      loop ptr x = case quotRem x 10 of+        (quot, rem) -> do+          A.pokeWord8 ptr (48 + fromIntegral rem)+          case quot of+            0 -> return ()+            _ -> loop (plusPtr ptr (-1)) quot+      in \ ptr -> loop (plusPtr ptr lastIndex) x+    in Poking size action  {-# INLINE asciiChar #-} asciiChar :: Char -> Poking
ptr.cabal view
@@ -1,7 +1,7 @@ name:   ptr version:-  0.16.6+  0.16.6.1 category:   Ptr, Data synopsis:@@ -87,14 +87,10 @@   default-language:     Haskell2010   build-depends:-    --     ptr,-    -- testing:-    tasty >=0.12 && <0.13,-    tasty-quickcheck >=0.9 && <0.10,-    tasty-hunit >=0.9 && <0.10,-    quickcheck-instances >=0.3.11 && <0.4,     QuickCheck >=2.8.1 && <3,-    ---    bug == 1.*,-    rerebase == 1.*+    quickcheck-instances >=0.3.11 && <0.4,+    rerebase <2,+    tasty >=0.12 && <2,+    tasty-hunit >=0.9 && <0.11,+    tasty-quickcheck >=0.9 && <0.11
tests/Main.hs view
@@ -1,7 +1,6 @@ module Main where  import Prelude-import Bug import Test.Tasty import Test.Tasty.Runners import Test.Tasty.HUnit@@ -21,6 +20,11 @@   defaultMain $   testGroup "All tests"   [+    testProperty "ASCII Numbers ByteString Roundtrip" $ \ (numbers :: [Word64]) -> let+      expected = foldMap (fromString . show) numbers+      actual = A.poking (foldMap F.asciiUnsignedIntegral numbers)+      in expected === actual+    ,     testProperty "Poke and peek (bytes)" $ \input -> input === fromJust (pokeThenPeek (B.bytes (D.length input)) (C.bytes (D.length input))) input     ,     testProperty "Poke and peek (word8)" $ \input -> input === fromJust (pokeThenPeek B.word8 C.word8) input