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

Some alfa compatibility tests #89

Merged
merged 8 commits into from
Feb 20, 2019
Merged
12 changes: 12 additions & 0 deletions packages/alfa-compatibility/test/every.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { test } from "@siteimprove/alfa-test";
import { BrowserSpecific } from "../src/browser-specific";
import { every } from "../src/every";

test("Can run every on a set of browser branches", t => {
const n = BrowserSpecific.of(1, ["chrome"])
.branch(2, ["firefox"])
.branch(4, ["safari"]);

t(!every(n, t => t === 4));
t(every(n, t => t < 8));
});
17 changes: 17 additions & 0 deletions packages/alfa-compatibility/test/guards.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { test } from "@siteimprove/alfa-test";
import { BrowserSpecific } from "../src/browser-specific";
import { isBrowserName, isBrowserSpecific } from "../src/guards";

test("isBrowserName returns true on valid browser names", t => {
t(isBrowserName("chrome"));
t(!isBrowserName("foo"));
});

test("isBrowserName returns true on valid browser names", t => {
const n = BrowserSpecific.of(1, ["chrome"])
.branch(2, ["firefox"])
.branch(4, ["safari"]);

t(isBrowserSpecific(n));
t(!isBrowserSpecific("foo"));
});
16 changes: 16 additions & 0 deletions packages/alfa-compatibility/test/map.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { test } from "@siteimprove/alfa-test";
import { BrowserSpecific } from "../src/browser-specific";
import { map } from "../src/map";

test("Can map a set of browser branches", t => {
const n = BrowserSpecific.of(1, ["chrome"])
.branch(2, ["firefox"])
.branch(4, ["safari"]);
const f: (n: number) => number = n => n * 2;
t.deepEqual(
map(n, f),
BrowserSpecific.of(2, ["chrome"])
.branch(4, ["firefox"])
.branch(8, ["safari"])
);
});
37 changes: 37 additions & 0 deletions packages/alfa-compatibility/test/reduce.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { test } from "@siteimprove/alfa-test";
import { BrowserSpecific } from "../src/browser-specific";
import { reduce } from "../src/reduce";

test("Can run every on a set of browser branches with initial value", t => {
const n = BrowserSpecific.of(10, ["chrome"])
.branch(11, ["firefox"])
.branch(10, ["safari"]);

const o = BrowserSpecific.of(10, ["chrome"])
.branch(11, ["firefox"])
.branch(12, ["safari"])
.branch(9, ["ie"]);

const expected = BrowserSpecific.of(3, ["chrome"])
.branch(3, ["firefox"])
.branch(3, ["safari"]);

t.deepEqual(reduce([n, o], (acc, val) => acc + 1, 1), expected);
});

test("Can run every on a set of browser branches without initial value", t => {
const n = BrowserSpecific.of(10, ["chrome"])
.branch(11, ["firefox"])
.branch(10, ["safari"]);

const o = BrowserSpecific.of(10, ["chrome"])
.branch(11, ["firefox"])
.branch(12, ["safari"])
.branch(9, ["ie"]);

const expected = BrowserSpecific.of(11, ["chrome"])
.branch(12, ["firefox"])
.branch(11, ["safari"]);

t.deepEqual(reduce([n, o], (acc, val) => acc + 1), expected);
});
12 changes: 12 additions & 0 deletions packages/alfa-compatibility/test/some.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { test } from "@siteimprove/alfa-test";
import { BrowserSpecific } from "../src/browser-specific";
import { some } from "../src/some";

test("Can run some on a set of browser branches", t => {
const n = BrowserSpecific.of(1, ["chrome"])
.branch(2, ["firefox"])
.branch(4, ["safari"]);

t(some(n, t => t === 4));
t(!some(n, t => t === 8));
});