From e24db8291acb466750018cb8930a0f78b8ab6e4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Fija=C5=82kowski?= Date: Mon, 2 Apr 2018 18:18:14 +0200 Subject: [PATCH] Do not include test files in the package (store them in temp) Fixes #11 --- CHANGELOG.md | 5 ++ hsass.cabal | 4 +- test/Text/Sass/EncodingSpec.hs | 67 +++++++++++++------ test/data/imports.scss | 3 - ...za\305\274\303\263\305\202ci\304\207.scss" | 1 - test/data/pl.scss | 1 - 6 files changed, 54 insertions(+), 27 deletions(-) delete mode 100644 test/data/imports.scss delete mode 100644 "test/data/pl-za\305\274\303\263\305\202ci\304\207.scss" delete mode 100644 test/data/pl.scss diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d2d554..5ad1c74 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 @@ -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 diff --git a/hsass.cabal b/hsass.cabal index 7f7f4e9..1dbe393 100644 --- a/hsass.cabal +++ b/hsass.cabal @@ -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 @@ -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 diff --git a/test/Text/Sass/EncodingSpec.hs b/test/Text/Sass/EncodingSpec.hs index 3dc05df..144025d 100644 --- a/test/Text/Sass/EncodingSpec.hs +++ b/test/Text/Sass/EncodingSpec.hs @@ -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 @@ -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" @@ -43,13 +48,29 @@ 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 @@ -57,16 +78,23 @@ spec = do 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 @@ -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 diff --git a/test/data/imports.scss b/test/data/imports.scss deleted file mode 100644 index 4ebc385..0000000 --- a/test/data/imports.scss +++ /dev/null @@ -1,3 +0,0 @@ -@import "pl-zażółcić.scss"; - -a { content: 'Zażółcić gęślą jaźń'; } diff --git "a/test/data/pl-za\305\274\303\263\305\202ci\304\207.scss" "b/test/data/pl-za\305\274\303\263\305\202ci\304\207.scss" deleted file mode 100644 index 7d6b572..0000000 --- "a/test/data/pl-za\305\274\303\263\305\202ci\304\207.scss" +++ /dev/null @@ -1 +0,0 @@ -a { content: 'Zażółcić gęślą jaźń'; } diff --git a/test/data/pl.scss b/test/data/pl.scss deleted file mode 100644 index 7d6b572..0000000 --- a/test/data/pl.scss +++ /dev/null @@ -1 +0,0 @@ -a { content: 'Zażółcić gęślą jaźń'; }