on master help sign in
Merge pull request #11 from wereHamster/to-from-text
e558bcdAntoine Latter
.travis.yml+19−9
@@ -1,12 +1,22 @@
1−language: haskell
1+env:
2−ghc:
2+ - CABALVER=1.18 GHCVER=7.6.3
3− - 7.10
3+ - CABALVER=1.18 GHCVER=7.8.4
4− - 7.8
4+ - CABALVER=1.22 GHCVER=7.10.1
5− - 7.6
5+ - CABALVER=head GHCVER=head
6− - 7.4
6+
7+matrix:
8+ allow_failures:
9+ - env: CABALVER=head GHCVER=head
7
10
8−sudo: false
9install:
11install:
10− - ./travis-scripts/install.sh
12+ - travis_retry sudo add-apt-repository -y ppa:hvr/ghc
13+ - travis_retry sudo apt-get update
14+ - travis_retry sudo apt-get install cabal-install-$CABALVER ghc-$GHCVER
15+ - export PATH=/opt/ghc/$GHCVER/bin:/opt/cabal/$CABALVER/bin:$PATH
16+ - cabal --version
17+ - echo "$(ghc --version) [$(ghc --print-project-git-commit-id 2> /dev/null || echo '?')]"
18+ - travis_retry cabal update
19+ - cabal install --only-dependencies --enable-tests --enable-benchmarks uuid-types/uuid-types.cabal uuid/uuid.cabal
20+
11script:
21script:
12− - ./travis-scripts/build.sh
22+ - for p in uuid-types uuid; do ./travis-scripts/build.sh $p; done
travis-scripts/build.sh+15−25
@@ -1,27 +1,17 @@
1−#!/usr/bin/env sh
1+#!/bin/sh
2−echo "==========================================="
3−echo "= Building and installing 'uuid-types'... ="
4−echo "==========================================="
5
2
6−# We install here because "uuid" is going to need it.
3+cd $1
7−(cd "uuid-types" && \
8− cabal configure --enable-tests && \
9− cabal build && \
10− cabal test && \
11− cabal install) || exit 1
12
4
13−echo "========================================="
14−echo "= Installing dependencies for 'uuid'... ="
15−echo "========================================="
16−
17−(cd "uuid" && \
18− cabal install --dependencies-only --enable-tests) || exit 1
19−
20−echo "======================"
21−echo "= Building 'uuid'... ="
22−echo "======================"
23−
24−(cd "uuid" && \
25− cabal configure --enable-tests && \
5+cabal configure --enable-tests --enable-benchmarks -v2
26− cabal build && \
6+cabal build
27− cabal test) || exit 1
7+cabal test
8+cabal check
9+cabal sdist
10+export SRC_TGZ=$(cabal info . | awk '{print $2 ".tar.gz";exit}') ;
11+cd dist/;
12+if [ -f "$SRC_TGZ" ]; then
13+ cabal install --force-reinstalls "$SRC_TGZ";
14+else
15+ echo "expected '$SRC_TGZ' not found";
16+ exit 1;
17+fi
travis-scripts/install.shdeleted−13
@@ -1,13 +0,0 @@
1−#!/usr/bin/env sh
2−
3−# We can only pre-install dependencies for the "uuid-types" project
4−# since the "uuid" project depends on "uuid-types". We could use
5−# sandboxing and "add-source", but it seems quite wasteful of
6−# CPU-cycles to compile everything twice for each version of GHC.
7−
8−echo "==============================================="
9−echo "= Installing dependencies for 'uuid-types'... ="
10−echo "==============================================="
11−
12−(cd "uuid-types" && \
13− cabal install --dependencies-only --enable-tests) || exit 1
uuid-types/Data/UUID/Types.hs+2
@@ -18,6 +18,8 @@ See <http://tools.ietf.org/html/rfc4122> for the specification.
18module Data.UUID.Types(UUID
18module Data.UUID.Types(UUID
19 ,toString
19 ,toString
20 ,fromString
20 ,fromString
21+ ,toText
22+ ,fromText
21 ,toASCIIBytes
23 ,toASCIIBytes
22 ,fromASCIIBytes
24 ,fromASCIIBytes
23 ,toLazyASCIIBytes
25 ,toLazyASCIIBytes
uuid-types/Data/UUID/Types/Internal.hs+10
@@ -20,6 +20,8 @@ module Data.UUID.Types.Internal
20 ,toByteString
20 ,toByteString
21 ,fromString
21 ,fromString
22 ,toString
22 ,toString
23+ ,fromText
24+ ,toText
23 ,fromWords
25 ,fromWords
24 ,toWords
26 ,toWords
25 ,toList
27 ,toList
@@ -61,6 +63,8 @@ import qualified Data.ByteString as B
61import qualified Data.ByteString.Internal as BI
63import qualified Data.ByteString.Internal as BI
62import qualified Data.ByteString.Lazy as BL
64import qualified Data.ByteString.Lazy as BL
63import qualified Data.ByteString.Unsafe as BU
65import qualified Data.ByteString.Unsafe as BU
66+import Data.Text (Text)
67+import qualified Data.Text as T
64
68
65import Data.UUID.Types.Internal.Builder
69import Data.UUID.Types.Internal.Builder
66
70
@@ -307,6 +311,12 @@ toString (UUID w0 w1 w2 w3) = hexw w0 $ hexw' w1 $ hexw' w2 $ hexw w3 ""
307 hexn :: Word32 -> Int -> Char
311 hexn :: Word32 -> Int -> Char
308 hexn w r = intToDigit $ fromIntegral ((w `shiftR` r) .&. 0xf)
312 hexn w r = intToDigit $ fromIntegral ((w `shiftR` r) .&. 0xf)
309
313
314+fromText :: Text -> Maybe UUID
315+fromText = fromString . T.unpack
316+
317+toText :: UUID -> Text
318+toText = T.pack . toString
319+
310-- | Convert a UUID into a hyphentated string using lower-case letters, packed
320-- | Convert a UUID into a hyphentated string using lower-case letters, packed
311-- as ASCII bytes into `B.ByteString`.
321-- as ASCII bytes into `B.ByteString`.
312--
322--
uuid-types/uuid-types.cabal+2−1
@@ -32,7 +32,8 @@ Library
32 bytestring >= 0.9 && < 0.11,
32 bytestring >= 0.9 && < 0.11,
33 deepseq >= 1.3 && < 1.5,
33 deepseq >= 1.3 && < 1.5,
34 hashable (>= 1.1.1.0 && < 1.2.0) || (>= 1.2.1 && < 1.3),
34 hashable (>= 1.1.1.0 && < 1.2.0) || (>= 1.2.1 && < 1.3),
35− random >= 1.0.1 && < 1.2
35+ random >= 1.0.1 && < 1.2,
36+ text >= 1 && < 1.3
36
37
37 Exposed-Modules:
38 Exposed-Modules:
38 Data.UUID.Types
39 Data.UUID.Types
uuid/Data/UUID.hs+2
@@ -26,6 +26,8 @@ MAC address and current system time in "Data.UUID.V1".
26module Data.UUID(UUID
26module Data.UUID(UUID
27 ,toString
27 ,toString
28 ,fromString
28 ,fromString
29+ ,toText
30+ ,fromText
29 ,toASCIIBytes
31 ,toASCIIBytes
30 ,fromASCIIBytes
32 ,fromASCIIBytes
31 ,toLazyASCIIBytes
33 ,toLazyASCIIBytes
uuid/uuid.cabal+1
@@ -33,6 +33,7 @@ Library
33 network-info == 0.2.*,
33 network-info == 0.2.*,
34 random >= 1.0.1 && < 1.2,
34 random >= 1.0.1 && < 1.2,
35 time >= 1.1 && < 1.6,
35 time >= 1.1 && < 1.6,
36+ text >= 1 && < 1.3,
36 uuid-types >= 1.0 && < 2
37 uuid-types >= 1.0 && < 2
37
38
38 Exposed-Modules:
39 Exposed-Modules: