string-qq (empty) → 0.0.2
raw patch · 5 files changed
+121/−0 lines, 5 filesdep +basedep +template-haskellbuild-type:Customsetup-changed
Dependencies added: base, template-haskell
Files
- LICENSE +8/−0
- Setup.hs +6/−0
- src/Data/String/QQ.hs +40/−0
- string-qq.cabal +26/−0
- tests/Test.hs +41/−0
+ LICENSE view
@@ -0,0 +1,8 @@+To the extent possible under law, 唐鳳 has waived all copyright and+related or neighboring rights to string-qq.++This work is published from Taiwan.++<http://creativecommons.org/publicdomain/zero/1.0>++
+ Setup.hs view
@@ -0,0 +1,6 @@+import Distribution.Simple+import System.Cmd(system)++main = defaultMainWithHooks $ simpleUserHooks { runTests = runElfTests }++runElfTests a b pd lb = system "runhaskell -i./src ./tests/Test.hs" >> return ()
+ src/Data/String/QQ.hs view
@@ -0,0 +1,40 @@+{-# LANGUAGE TemplateHaskell, CPP #-}++-- | QuasiQuoter for non-interpolated strings, texts and bytestrings.+--+-- The "s" quoter contains a multi-line string with no interpolation at all,+-- except that the leading newline is trimmed and carriage returns stripped.+--+-- @+-- {-\# LANGUAGE QuasiQuotes #-}+-- import Data.Text (Text)+-- import Data.String.QQ+-- foo :: Text -- "String", "ByteString" etc also works+-- foo = [s|+-- Well here is a+-- multi-line string!+-- |]+-- @+--+-- Any instance of the IsString type is permitted.+-- +-- (For GHC versions 6, write "[$s||]" instead of "[s||]".)+--+module Data.String.QQ (s) where+import GHC.Exts (IsString(..))+import qualified Language.Haskell.TH as TH+import Language.Haskell.TH.Quote++-- | QuasiQuoter for a non-interpolating IsString literal. The pattern portion is undefined.+s :: QuasiQuoter+s = QuasiQuoter ((\a -> [|fromString a|]) . trimLeadingNewline . removeCRs)+ (error "Cannot use q as a pattern")+#if (__GLASGOW_HASKELL__ >= 700)+ (error "Cannot use q as a type")+ (error "Cannot use q as a dec")+#endif+ where+ removeCRs = filter (/= '\r')+ trimLeadingNewline ('\n':xs) = xs+ trimLeadingNewline xs = xs+
+ string-qq.cabal view
@@ -0,0 +1,26 @@+Name: string-qq+Version: 0.0.2+License: PublicDomain+License-file: LICENSE+Category: Data+Author: Audrey Tang+Copyright: Audrey Tang+Maintainer: Audrey Tang <audreyt@audreyt.org>+Stability: unstable+Cabal-Version: >= 1.6+Build-Depends: base+Build-Type: Custom+Synopsis: QuasiQuoter for non-interpolated strings, texts and bytestrings.+Description: QuasiQuoter for non-interpolated strings, texts and bytestrings.+Data-Files: tests/Test.hs+Tested-With: GHC==6.10.1, GHC==7.0.2++Source-Repository head+ type: git+ location: git://github.com/audreyt/string-qq.git++library+ extensions: TemplateHaskell+ build-depends: base > 3 && < 6, template-haskell >= 2+ hs-source-dirs: src+ exposed-modules: Data.String.QQ
+ tests/Test.hs view
@@ -0,0 +1,41 @@+{-# LANGUAGE QuasiQuotes, ExtendedDefaultRules, CPP #-}++module Main where++import Data.Text+import Data.String.QQ+import Test.HUnit++#if (__GLASGOW_HASKELL__ >= 700)+test0 = assertBool "" ([s||] == "")+test1 = assertBool "" ([s|1|] == "1")+test2 = assertBool "" ([s|2|] == pack "2")+test0' = assertBool "" ([s|+|] == "")+test1' = assertBool "" ([s|+1|] == "1")+test2' = assertBool "" ([s|+2|] == pack "2")+#else+test0 = assertBool "" ([$s||] == "")+test1 = assertBool "" ([$s|1|] == "1")+test2 = assertBool "" ([$s|2|] == pack "2")+test0' = assertBool "" ([$s|+|] == "")+test1' = assertBool "" ([$s|+1|] == "1")+test2' = assertBool "" ([$s|+2|] == pack "2")+#endif++tests = TestList+ [ TestLabel "Empty String" $ TestCase test0+ , TestLabel "String instance" $ TestCase test1+ , TestLabel "Text instance" $ TestCase test2+ , TestLabel "Empty String with trimmed leading newline" $ TestCase test0'+ , TestLabel "String instance with trimmed leading newline" $ TestCase test1'+ , TestLabel "Text instance with trimmed leading newline" $ TestCase test2'+ ]++main = runTestTT tests+