Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Add @font-face #251

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
},
"devDependencies": {
"chai": "3.4.1",
"mocha": "2.3.4"
"mocha": "2.3.4",
"node-elm-compiler": "2.3.2",
"tmp": "0.0.28"
},
"engineStrict": true,
"engines": {
Expand Down
119 changes: 119 additions & 0 deletions tests/AtRules.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
module AtRules exposing (all)

import Test exposing (..)
import Expect exposing (Expectation)
import TestUtil exposing (outdented, prettyPrint)
import Fixtures


all : Test
all =
describe "at-rules"
[ mediaQueryTests
, nestedAtRules
, fontFaceTests
]


fontFaceTests : Test
fontFaceTests =
let
input =
Fixtures.fontFaceAtRule

output =
"""
@font-face {
font-family: "MyFontName";
src: url(https://example.com/fonts/MyFont-Weird.ttf),
url(https://example.com/fonts/MyFont-Odd.ttf);
font-variant: small-caps;
font-weight: 500;
font-style: italic;
}

@font-face {
font-family: "MyFontName";
src: url(https://example.com/fonts/MyFont-Bold.woff);
font-weight: bold;
}
"""
in
describe "@font-face"
[ test "pretty prints the expected output" <|
\_ ->
outdented (prettyPrint input)
|> Expect.equal (outdented output)
]


mediaQueryTests : Test
mediaQueryTests =
let
input =
Fixtures.mediaQueryAtRule

output =
"""
body {
padding: 0;
}

@media print {
body {
margin: 2em;
}
}

@media screen and ( max-width: 600px ) {
body {
margin: 3em;
}
}

button {
margin: auto;
}
"""
in
describe "@media test"
[ test "pretty prints the expected output" <|
\_ ->
outdented (prettyPrint input)
|> Expect.equal (outdented output)
]


nestedAtRules : Test
nestedAtRules =
let
input =
Fixtures.nestedAtRule

output =
"""
button {
padding: 0;
}

body {
margin: auto;
}

@media print {
body {
margin: 2em;
}
}

a {
text-decoration: none;
}
"""
in
describe "nested @media test"
[ test "pretty prints the expected output" <|
\_ ->
outdented (prettyPrint input)
|> Expect.equal (outdented output)
]
26 changes: 24 additions & 2 deletions tests/Fixtures.elm
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,30 @@ divWidthHeight =
]


atRule : Stylesheet
atRule =
fontFaceAtRule : Stylesheet
fontFaceAtRule =
-- NOTE: The following code is aspirational and does not compile (yet)
(stylesheet << namespace "homepage")
[ fontFace
[ fontFamily "MyFontName"
, src
[ url "https://example.com/fonts/MyFont-Weird.ttf"
, url "https://example.com/fonts/MyFont-Odd.ttf"
]
, fontVariant smallCaps
, fontWeight <| int 500
, fontStyle italic
]
, fontFace
[ fontFamily "MyFontName"
, src <| url "https://example.com/fonts/MyFont-Bold.woff"
, fontWeight bold
]
]


mediaQueryAtRule : Stylesheet
mediaQueryAtRule =
(stylesheet << namespace "homepage")
[ body [ padding zero ]
, (media [ print ]) [ body [ margin (Css.em 2) ] ]
Expand Down
76 changes: 2 additions & 74 deletions tests/Tests.elm
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Fixtures
import Properties
import Selectors
import Colors
import AtRules


all : Test
Expand All @@ -23,8 +24,6 @@ all =
, divWidthHeight
, leftRightTopBottom
, borders
, atRule
, nestedAtRule
, bug99
, bug140
, universal
Expand All @@ -42,6 +41,7 @@ all =
, Properties.all
, Selectors.all
, Arithmetic.all
, AtRules.all
, backgrounds
]

Expand Down Expand Up @@ -145,78 +145,6 @@ leftRightTopBottom =
]


atRule : Test
atRule =
let
input =
Fixtures.atRule

output =
"""
body {
padding: 0;
}

@media print {
body {
margin: 2em;
}
}

@media screen and ( max-width: 600px ) {
body {
margin: 3em;
}
}

button {
margin: auto;
}
"""
in
describe "@media test"
[ test "pretty prints the expected output" <|
\_ ->
outdented (prettyPrint input)
|> Expect.equal (outdented output)
]


nestedAtRule : Test
nestedAtRule =
let
input =
Fixtures.nestedAtRule

output =
"""
button {
padding: 0;
}

body {
margin: auto;
}

@media print {
body {
margin: 2em;
}
}

a {
text-decoration: none;
}
"""
in
describe "nested @media test"
[ test "pretty prints the expected output" <|
\_ ->
outdented (prettyPrint input)
|> Expect.equal (outdented output)
]


{-| Regression test for https://github.com/rtfeldman/elm-css/issues/140
-}
bug140 : Test
Expand Down