Skip to content
This repository has been archived by the owner on Feb 9, 2022. It is now read-only.

Commit

Permalink
Format code with prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
honzabrecka committed Oct 19, 2018
1 parent 46e10db commit 04a42a0
Show file tree
Hide file tree
Showing 33 changed files with 447 additions and 350 deletions.
2 changes: 1 addition & 1 deletion assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const wu = require("./wu");
const chai = require("chai");
const mocha = require("mocha");

const assert = module.exports = chai.assert;
const assert = (module.exports = chai.assert);

// Helper for asserting that the given thing is iterable.
assert.iterable = thing => {
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"scripts": {
"docs": "bundle exec jekyll serve --watch",
"build": "webpack --color",
"test": "npm run build && mocha --full-trace --no-colors --compilers js:babel/register"
"test": "npm run build && mocha --full-trace --no-colors --compilers js:babel/register",
"format": "prettier --write wu.js assert.js test/*.js"
},
"devDependencies": {
"babel": "^5.8.23",
Expand All @@ -32,6 +33,7 @@
"babel-runtime": "^5.8.25",
"chai": "^3.3.0",
"mocha": "^2.3.3",
"prettier": "^1.14.3",
"webpack": "^1.12.2"
}
}
3 changes: 1 addition & 2 deletions test/test-chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const wu = require("../wu");
const assert = require("../assert");
describe("wu.chain", () => {
it("should concatenate iterables", () => {
assert.eqArray([1, 2, 3, 4, 5, 6],
wu.chain([1, 2], [3, 4], [5, 6]));
assert.eqArray([1, 2, 3, 4, 5, 6], wu.chain([1, 2], [3, 4], [5, 6]));
});
});
3 changes: 1 addition & 2 deletions test/test-chunk.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const wu = require("../wu");
const assert = require("../assert");
describe("wu.chunk", () => {
it("should chunk items into tuples", () => {
assert.eqArray([[1,2,3], [4,5,6]],
wu.chunk(3, [1,2,3,4,5,6]));
assert.eqArray([[1, 2, 3], [4, 5, 6]], wu.chunk(3, [1, 2, 3, 4, 5, 6]));
});
});
6 changes: 4 additions & 2 deletions test/test-concatMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ const wu = require("../wu");
const assert = require("../assert");
describe("wu.concatMap", () => {
it("should map the function over the iterable and concatenate results", () => {
assert.eqArray([1, 1, 2, 4, 3, 9],
wu.concatMap(x => [x, x * x], [1, 2, 3]));
assert.eqArray(
[1, 1, 2, 4, 3, 9],
wu.concatMap(x => [x, x * x], [1, 2, 3])
);
});
});
3 changes: 1 addition & 2 deletions test/test-enumerate.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const wu = require("../wu");
const assert = require("../assert");
describe("wu.enumerate", () => {
it("should yield items with their index", () => {
assert.eqArray([["a", 0], ["b", 1], ["c", 2]],
wu.enumerate("abc"));
assert.eqArray([["a", 0], ["b", 1], ["c", 2]], wu.enumerate("abc"));
});
});
7 changes: 4 additions & 3 deletions test/test-filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ const wu = require("../wu");
const assert = require("../assert");
describe("wu.filter", () => {
it("should filter based on the predicate", () => {
assert.eqArray(["a", "b", "c"],
wu.filter(x => typeof x === "string",
[1, "a", true, "b", {}, "c"]));
assert.eqArray(
["a", "b", "c"],
wu.filter(x => typeof x === "string", [1, "a", true, "b", {}, "c"])
);
});
});
30 changes: 18 additions & 12 deletions test/test-find.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,26 @@ const wu = require("../wu");
const assert = require("../assert");
describe("wu.find", () => {
it("should return the first item that matches the predicate", () => {
assert.deepEqual({ name: "rza" },
wu.find(x => x.name.match(/.za$/),
[{ name: "odb" },
{ name: "method man" },
{ name: "rza" },
{ name: "gza" }]));
assert.deepEqual(
{ name: "rza" },
wu.find(x => x.name.match(/.za$/), [
{ name: "odb" },
{ name: "method man" },
{ name: "rza" },
{ name: "gza" }
])
);
});

it("should return undefined if no items match the predicate", () => {
assert.equal(undefined,
wu.find(x => x === "raekwon",
[{ name: "odb" },
{ name: "method man" },
{ name: "rza" },
{ name: "gza" }]));
assert.equal(
undefined,
wu.find(x => x === "raekwon", [
{ name: "odb" },
{ name: "method man" },
{ name: "rza" },
{ name: "gza" }
])
);
});
});
9 changes: 5 additions & 4 deletions test/test-flatten.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ const wu = require("../wu");
const assert = require("../assert");
describe("wu.flatten", () => {
it("should flatten iterables", () => {
assert.eqArray(["I", "like", "LISP"],
wu(["I", ["like", ["LISP"]]]).flatten());
assert.eqArray(
["I", "like", "LISP"],
wu(["I", ["like", ["LISP"]]]).flatten()
);
});

it("should shallowly flatten iterables", () => {
assert.eqArray([1, 2, 3, [[4]]],
wu.flatten(true, [1, [2], [3, [[4]]]]));
assert.eqArray([1, 2, 3, [[4]]], wu.flatten(true, [1, [2], [3, [[4]]]]));
});
});
4 changes: 2 additions & 2 deletions test/test-forEach.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const assert = require("../assert");
describe("wu.forEach", () => {
it("should iterate over every item", () => {
const items = [];
wu.forEach(x => items.push(x), [1,2,3]);
assert.eqArray([1,2,3], items);
wu.forEach(x => items.push(x), [1, 2, 3]);
assert.eqArray([1, 2, 3], items);
});
});
4 changes: 2 additions & 2 deletions test/test-has.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ const wu = require("../wu");
const assert = require("../assert");
describe("wu.has", () => {
it("should return true if the item is in the iterable", () => {
assert.ok(wu.has(3, [1,2,3]));
assert.ok(wu.has(3, [1, 2, 3]));
});

it("should return false if the item is not in the iterable", () => {
assert.ok(!wu.has("36 chambers", [1,2,3]));
assert.ok(!wu.has("36 chambers", [1, 2, 3]));
});
});
11 changes: 6 additions & 5 deletions test/test-invoke.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ const assert = require("../assert");
describe("wu.invoke", () => {
it("should yield the method invokation on each item", () => {
function Greeter(name) {
this.name = name
this.name = name;
}
Greeter.prototype.greet = function (tail) {
Greeter.prototype.greet = function(tail) {
return "hello " + this.name + tail;
};
assert.eqArray(["hello world!", "hello test!"],
wu.invoke("greet", "!",
[new Greeter("world"), new Greeter("test")]));
assert.eqArray(
["hello world!", "hello test!"],
wu.invoke("greet", "!", [new Greeter("world"), new Greeter("test")])
);
});
});
6 changes: 4 additions & 2 deletions test/test-keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ const wu = require("../wu");
const assert = require("../assert");
describe("wu.keys", () => {
it("should iterate over keys", () => {
assert.eqSet(new Set(["foo", "bar", "baz"]),
wu.keys({ foo: 1, bar: 2, baz: 3 }));
assert.eqSet(
new Set(["foo", "bar", "baz"]),
wu.keys({ foo: 1, bar: 2, baz: 3 })
);
});
});
3 changes: 1 addition & 2 deletions test/test-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const wu = require("../wu");
const assert = require("../assert");
describe("wu.map", () => {
it("should map the function over the iterable", () => {
assert.eqArray([1, 4, 9],
wu.map(x => x * x, [1, 2, 3]));
assert.eqArray([1, 4, 9], wu.map(x => x * x, [1, 2, 3]));
});
});
15 changes: 5 additions & 10 deletions test/test-nth.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,21 @@ const wu = require("../wu");
const assert = require("../assert");
describe("wu.nth", () => {
it("should return the nth item in the iterable", () => {
assert.equal(3,
wu.nth(3, [0, 1, 2, 3, 4]));
assert.equal(3, wu.nth(3, [0, 1, 2, 3, 4]));
});

it("should return undefined if the index is negative", () => {
assert.equal(undefined,
wu.nth(-1, []));
assert.equal(undefined, wu.nth(-1, []));
});

it("should not consume if the index is negative", () => {
const iterable = wu([0, 1, 2]);
iterable.nth(-1);
assert.equal(0,
iterable.next().value);
assert.equal(0, iterable.next().value);
});

it("should return undefined if the index is out of bounds", () => {
assert.equal(undefined,
wu.nth(0, []));
assert.equal(undefined,
wu.nth(3, ['a', 'b', 'c']));
assert.equal(undefined, wu.nth(0, []));
assert.equal(undefined, wu.nth(3, ["a", "b", "c"]));
});
});
3 changes: 1 addition & 2 deletions test/test-pluck.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const wu = require("../wu");
const assert = require("../assert");
describe("wu.pluck", () => {
it("should access the named property of each item in the iterable", () => {
assert.eqArray([1, 2, 3],
wu.pluck("i", [{ i: 1 }, { i: 2 }, { i: 3 }]));
assert.eqArray([1, 2, 3], wu.pluck("i", [{ i: 1 }, { i: 2 }, { i: 3 }]));
});
});
4 changes: 2 additions & 2 deletions test/test-reduce.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ const wu = require("../wu");
const assert = require("../assert");
describe("wu.reduce", () => {
it("should reduce the iterable with the function", () => {
assert.equal(6, wu([1,2,3]).reduce((x, y) => x + y));
assert.equal(6, wu([1, 2, 3]).reduce((x, y) => x + y));
});

it("should accept an initial state for the reducer function", () => {
assert.equal(16, wu.reduce((x, y) => x + y, 10, [1,2,3]));
assert.equal(16, wu.reduce((x, y) => x + y, 10, [1, 2, 3]));
});
});
6 changes: 4 additions & 2 deletions test/test-reductions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ const wu = require("../wu");
const assert = require("../assert");
describe("wu.reductions", () => {
it("should yield the intermediate reductions of the iterable", () => {
assert.eqArray([1, 3, 6],
wu.reductions((x, y) => x + y, undefined, [1, 2, 3]));
assert.eqArray(
[1, 3, 6],
wu.reductions((x, y) => x + y, undefined, [1, 2, 3])
);
});
});
7 changes: 4 additions & 3 deletions test/test-reject.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ const wu = require("../wu");
const assert = require("../assert");
describe("wu.reject", () => {
it("should yield items for which the predicate is false", () => {
assert.eqArray([1, true, {}],
wu.reject(x => typeof x === "string",
[1, "a", true, "b", {}, "c"]));
assert.eqArray(
[1, true, {}],
wu.reject(x => typeof x === "string", [1, "a", true, "b", {}, "c"])
);
});
});
8 changes: 2 additions & 6 deletions test/test-slice.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@ const wu = require("../wu");
const assert = require("../assert");
describe("wu.slice", () => {
it("should slice the front of iterables", () => {
assert.eqArray([3, 4, 5],
wu.slice(3, undefined, [0, 1, 2, 3, 4, 5]));
assert.eqArray([3, 4, 5], wu.slice(3, undefined, [0, 1, 2, 3, 4, 5]));
});

it("should slice the end of iterables", () => {
assert.eqArray([0, 1, 2],
wu.slice(undefined,
3,
[0, 1, 2, 3, 4, 5]));
assert.eqArray([0, 1, 2], wu.slice(undefined, 3, [0, 1, 2, 3, 4, 5]));
});
});
4 changes: 2 additions & 2 deletions test/test-some.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ const wu = require("../wu");
const assert = require("../assert");
describe("wu.some", () => {
it("should return true if any item matches the predicate", () => {
assert.ok(wu.some(x => x % 2 === 0, [1,2,3]));
assert.ok(wu.some(x => x % 2 === 0, [1, 2, 3]));
});

it("should return false if no items match the predicate", () => {
assert.ok(!wu.some(x => x % 5 === 0, [1,2,3]));
assert.ok(!wu.some(x => x % 5 === 0, [1, 2, 3]));
});
});
6 changes: 4 additions & 2 deletions test/test-spreadMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ const wu = require("../wu");
const assert = require("../assert");
describe("wu.spreadMap", () => {
it("should map the function over the iterable with spread arguments", () => {
assert.eqArray([32, 9, 1000],
wu.spreadMap(Math.pow, [[2, 5], [3, 2], [10, 3]]));
assert.eqArray(
[32, 9, 1000],
wu.spreadMap(Math.pow, [[2, 5], [3, 2], [10, 3]])
);
});
});
3 changes: 1 addition & 2 deletions test/test-take.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const wu = require("../wu");
const assert = require("../assert");
describe("wu.take", () => {
it("should yield as many items as requested", () => {
assert.eqArray([0, 1, 2, 3, 4],
wu.take(5, wu.count()));
assert.eqArray([0, 1, 2, 3, 4], wu.take(5, wu.count()));
});
});
3 changes: 1 addition & 2 deletions test/test-takeWhile.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const wu = require("../wu");
const assert = require("../assert");
describe("wu.takeWhile", () => {
it("should keep yielding items from the iterable until the predicate is false", () => {
assert.eqArray([0, 1, 2, 3, 4],
wu.takeWhile(x => x < 5, wu.count()));
assert.eqArray([0, 1, 2, 3, 4], wu.takeWhile(x => x < 5, wu.count()));
});
});
3 changes: 1 addition & 2 deletions test/test-tap.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ const assert = require("../assert");
describe("wu.tap", () => {
it("should perform side effects and yield the original item", () => {
let i = 0;
assert.eqArray([1, 2, 3],
wu.tap(x => i++, [1, 2, 3]));
assert.eqArray([1, 2, 3], wu.tap(x => i++, [1, 2, 3]));
assert.equal(i, 3);
});
});
3 changes: 1 addition & 2 deletions test/test-unique.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const wu = require("../wu");
const assert = require("../assert");
describe("wu.unique", () => {
it("should yield only the unique items from the iterable", () => {
assert.eqArray([1, 2, 3],
wu.unique([1,1,2,2,1,1,3,3]));
assert.eqArray([1, 2, 3], wu.unique([1, 1, 2, 2, 1, 1, 3, 3]));
});
});
6 changes: 1 addition & 5 deletions test/test-unzip.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ const wu = require("../wu");
const assert = require("../assert");
describe("wu.unzip", () => {
it("should create iterables from zipped items", () => {
const pairs = [
["one", 1],
["two", 2],
["three", 3]
];
const pairs = [["one", 1], ["two", 2], ["three", 3]];
const [i1, i2] = wu(pairs).unzip();
assert.eqArray(["one", "two", "three"], [...i1]);
assert.eqArray([1, 2, 3], [...i2]);
Expand Down
3 changes: 1 addition & 2 deletions test/test-values.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const wu = require("../wu");
const assert = require("../assert");
describe("wu.values", () => {
it("should iterate over values", () => {
assert.eqSet(new Set([1, 2, 3]),
wu.values({ foo: 1, bar: 2, baz: 3 }));
assert.eqSet(new Set([1, 2, 3]), wu.values({ foo: 1, bar: 2, baz: 3 }));
});
});
6 changes: 2 additions & 4 deletions test/test-zip.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ const wu = require("../wu");
const assert = require("../assert");
describe("wu.zip", () => {
it("should zip two iterables together", () => {
assert.eqArray([["a", 1], ["b", 2], ["c", 3]],
wu.zip("abc", [1, 2, 3]));
assert.eqArray([["a", 1], ["b", 2], ["c", 3]], wu.zip("abc", [1, 2, 3]));
});

it("should stop with the shorter iterable", () => {
assert.eqArray([["a", 1], ["b", 2], ["c", 3]],
wu.zip("abc", wu.count(1)));
assert.eqArray([["a", 1], ["b", 2], ["c", 3]], wu.zip("abc", wu.count(1)));
});
});
Loading

0 comments on commit 04a42a0

Please sign in to comment.