Skip to content

Commit

Permalink
Do not include test files in the package (store them in temp)
Browse files Browse the repository at this point in the history
Fixes #11
  • Loading branch information
jakubfijalkowski committed Apr 2, 2018
1 parent c1532a5 commit e24db82
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 27 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [0.7.0] - 2018-04-02
### Changed
- This library uses UTF-8 to encode/decode all `CString`s (paths included!)

## [0.6.0] - 2018-03-24
### Changed
- Switched to `hLibsass` 0.1.7.0 and `libsass` 3.5.2
Expand Down Expand Up @@ -74,3 +78,4 @@ This project adheres to [Semantic Versioning](http://semver.org/).
[0.4.2]: https://github.com/jakubfijalkowski/hsass/compare/v0.4.1...v0.4.2
[0.5.0]: https://github.com/jakubfijalkowski/hsass/compare/v0.4.2...v0.5.0
[0.6.0]: https://github.com/jakubfijalkowski/hsass/compare/v0.5.0...v0.6.0
[0.7.0]: https://github.com/jakubfijalkowski/hsass/compare/v0.6.0...v0.7.0
4 changes: 1 addition & 3 deletions hsass.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ description:

extra-source-files:
CHANGELOG.md
test/data/imports.scss
test/data/pl.scss
test/data/pl-zażółcić.scss

source-repository head
type: git
Expand Down Expand Up @@ -81,6 +78,7 @@ test-suite test
, hspec >= 2.1.5
, hspec-discover >= 2.1.5
, temporary >= 1.1
, text >= 1.2
, hsass
, data-default-class
default-language: Haskell2010
67 changes: 48 additions & 19 deletions test/Text/Sass/EncodingSpec.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
module Text.Sass.EncodingSpec where

import Control.Concurrent.MVar
import Data.List (isSuffixOf)
import qualified Data.ByteString as BS
import qualified Data.Text as T
import qualified Data.Text.Encoding as TE
import GHC.IO.Encoding (setFileSystemEncoding, utf8)
import System.IO
import System.IO.Temp
import Test.Hspec
import Text.Sass
import qualified Text.Sass.Values.Internal as VI
Expand All @@ -13,7 +18,7 @@ testString :: String
testString = "Zażółcić gęślą jaźń"

testInput :: String
testInput = "a { content: '" ++ testString ++ "'; }"
testInput = "a { content: '" ++ testString ++ "'; }"

expectedResult :: Either a String
expectedResult = Right $ "a {\n content: '" ++ testString ++ "'; }\n"
Expand Down Expand Up @@ -43,30 +48,53 @@ returnFuncSig = SassFunction "ret()" returnFunc
nonUTFNameSig :: SassFunction
nonUTFNameSig = SassFunction "zażółcić()" returnFunc

importFunction :: String -> String -> IO [SassImport]
importFunction "src" _ = return [makeSourceImport testInput]
importFunction "path" _ = return [makePathImport "test/data/pl-zażółcić.scss" "."]
importFunction _ _ = fail "Unknown import"

importers :: [SassImporter]
importers = [SassImporter 1 importFunction]
importFunction :: FilePath -> String -> String -> IO [SassImport]
importFunction _ "src" _ = return [makeSourceImport testInput]
importFunction p "path" _ = return [makePathImport p "."]
importFunction _ _ _ = fail "Unknown import"

importers :: FilePath -> [SassImporter]
importers p = [SassImporter 1 $ importFunction p]

withNonASCIIContentFile :: (String -> IO a) -> IO a
withNonASCIIContentFile f =
withSystemTempFile "styles.scss" $ \p h -> do
BS.hPutStr h (TE.encodeUtf8 $ T.pack testInput)
hClose h
f p

withNonASCIIPathFile :: (String -> IO a) -> IO a
withNonASCIIPathFile f = do
setFileSystemEncoding utf8
res <- withSystemTempFile "pl-zażółcić.scss" $ \p h -> do
BS.hPutStr h (TE.encodeUtf8 $ T.pack testInput)
hClose h
f p
return res

spec :: Spec
spec = do
it "should preserve UTF-8 encoding when compiling Strings" $
compileString testInput opts `shouldReturn` expectedResult

it "should preserve UTF-8 encoding when compiling files" $
compileFile "test/data/pl.scss" opts `shouldReturn` expectedResult
withNonASCIIContentFile $ \p ->
compileFile p opts `shouldReturn` expectedResult

it "should correctly encode UTF-8 chars in source paths" $
compileFile "test/data/pl-zażółcić.scss" opts
`shouldReturn` expectedResult
withNonASCIIPathFile $ \p ->
compileFile p opts `shouldReturn` expectedResult

it "should correctly encode UTF-8 chars in included files path" $
withNonASCIIPathFile $ \p ->
withSystemTempFile "styles.scss" $ \impP impH -> do
let cnt = "@import \"" ++ p ++ "\";"
BS.hPutStr impH $ TE.encodeUtf8 $ T.pack cnt
hClose impH

it "should correctly encode UTF-8 chars in included files path" $ do
Right res <- compileFile "test/data/imports.scss" opts :: ExtendedResult
includes <- resultIncludes res
includes `shouldSatisfy` any (isSuffixOf "test/data/pl-zażółcić.scss")
Right res <- compileFile impP opts :: ExtendedResult
includes <- resultIncludes res
includes `shouldSatisfy` elem p

it "should correctly encode/decode UTF-8 SassStrings" $
testValue $ SassString testString
Expand Down Expand Up @@ -99,9 +127,10 @@ spec = do
`shouldReturn` expectedResult

it "should correctly encode UTF-8 string from importer" $
let iopts = opts { sassImporters = Just importers }
let iopts = opts { sassImporters = Just $ importers "" }
in compileString "@import 'src';" iopts `shouldReturn` expectedResult

it "should correctly encode UTF-8 path from importer" $
let iopts = opts { sassImporters = Just importers }
in compileString "@import 'path';" iopts `shouldReturn` expectedResult
withNonASCIIPathFile $ \p ->
let iopts = opts { sassImporters = Just $ importers p }
in compileString "@import 'path';" iopts `shouldReturn` expectedResult
3 changes: 0 additions & 3 deletions test/data/imports.scss

This file was deleted.

1 change: 0 additions & 1 deletion test/data/pl-zażółcić.scss

This file was deleted.

1 change: 0 additions & 1 deletion test/data/pl.scss

This file was deleted.

0 comments on commit e24db82

Please sign in to comment.