-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #266 from chungyc/aspect-ratio
Add support for `aspect-ratio` CSS property.
- Loading branch information
Showing
2 changed files
with
156 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
|
||
module Clay.GeometrySpec where | ||
|
||
import Clay.Common | ||
import Clay.Geometry | ||
import Clay.Render | ||
import Clay.Stylesheet | ||
|
||
import Control.Exception (evaluate) | ||
import qualified Data.Ratio as R | ||
import Data.Text.Lazy | ||
|
||
import Test.Hspec | ||
|
||
compactRender :: Css -> Text | ||
compactRender = renderWith compact [] | ||
|
||
spec :: Spec | ||
spec = do | ||
describe "aspect-ratio" $ do | ||
it "has ratio" $ do | ||
compactRender (aspectRatio (2%1)) `shouldBe` "{aspect-ratio:2/1}" | ||
compactRender (aspectRatio (4%3)) `shouldBe` "{aspect-ratio:4/3}" | ||
compactRender (aspectRatio (8%6)) `shouldBe` "{aspect-ratio:4/3}" | ||
|
||
it "has rational ratio" $ do | ||
compactRender (aspectRatio $ fromRational $ 2 R.% 1) `shouldBe` "{aspect-ratio:2/1}" | ||
compactRender (aspectRatio $ fromRational $ 4 R.% 3) `shouldBe` "{aspect-ratio:4/3}" | ||
compactRender (aspectRatio $ fromRational $ 8 R.% 6) `shouldBe` "{aspect-ratio:4/3}" | ||
|
||
it "has auto value" $ do | ||
compactRender (aspectRatio auto) `shouldBe` "{aspect-ratio:auto}" | ||
|
||
it "has inherit value" $ do | ||
compactRender (aspectRatio inherit) `shouldBe` "{aspect-ratio:inherit}" | ||
|
||
it "has initial value" $ do | ||
compactRender (aspectRatio initial) `shouldBe` "{aspect-ratio:initial}" | ||
|
||
it "has unset value" $ do | ||
compactRender (aspectRatio unset) `shouldBe` "{aspect-ratio:unset}" | ||
|
||
it "has auto value and fallback ratio" $ do | ||
compactRender (aspectRatio $ auto `withFallback` (4%3)) `shouldBe` "{aspect-ratio:auto 4/3}" | ||
compactRender (aspectRatio $ (4%3) `withFallback` auto) `shouldBe` "{aspect-ratio:4/3 auto}" | ||
|
||
it "does not allow invalid fallbacks" $ do | ||
evaluate (compactRender $ aspectRatio $ auto `withFallback` auto) `shouldThrow` anyErrorCall | ||
evaluate (compactRender $ aspectRatio $ (4%3) `withFallback` (4%3)) `shouldThrow` anyErrorCall | ||
|
||
it "has arbitrary other value" $ do | ||
compactRender (aspectRatio $ other "not valid") `shouldBe` "{aspect-ratio:not valid}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters