Skip to content

Commit

Permalink
Add image parsing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jym77 committed Oct 11, 2023
1 parent 9301142 commit 156316b
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 166 deletions.
74 changes: 74 additions & 0 deletions packages/alfa-css/test/value/image/image.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { test } from "@siteimprove/alfa-test";

import { Image, Lexer } from "../../../src";

function parse(input: string) {
return Image.parse(Lexer.lex(input)).getUnsafe()[1].toJSON();
}

test("parse() parses an image with relative URL", (t) => {
t.deepEqual(parse("url('foo.jpg')"), {
type: "image",
image: { type: "url", url: "foo.jpg" },
});
});

test("parse() parses an image with absolute URL", (t) => {
t.deepEqual(parse("url('https://example.com/foo.jpg')"), {
type: "image",
image: { type: "url", url: "https://example.com/foo.jpg" },
});
});

test("parse() parses a linear gradient", (t) => {
t.deepEqual(parse("linear-gradient(red, blue)"), {
type: "image",
image: {
type: "gradient",
kind: "linear",
direction: { type: "side", side: "bottom" },
items: [
{
type: "stop",
color: { type: "color", format: "named", color: "red" },
position: null,
},
{
type: "stop",
color: { type: "color", format: "named", color: "blue" },
position: null,
},
],
repeats: false,
},
});
});

test("parse() parses a radial gradient", (t) => {
t.deepEqual(parse("radial-gradient(red, blue)"), {
type: "image",
image: {
type: "gradient",
kind: "radial",
shape: { type: "extent", shape: "circle", size: "farthest-corner" },
position: {
type: "position",
horizontal: { type: "keyword", value: "center" },
vertical: { type: "keyword", value: "center" },
},
items: [
{
type: "stop",
color: { type: "color", format: "named", color: "red" },
position: null,
},
{
type: "stop",
color: { type: "color", format: "named", color: "blue" },
position: null,
},
],
repeats: false,
},
});
});
Loading

0 comments on commit 156316b

Please sign in to comment.