Skip to content

Commit 5a9870e

Browse files
authored
Merge pull request #83 from bloomberg/spec/align-tuple-methods
2 parents 7097c77 + a7f05dc commit 5a9870e

File tree

2 files changed

+20
-32
lines changed

2 files changed

+20
-32
lines changed

packages/record-tuple-polyfill/src/tuple.js

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -117,20 +117,6 @@ define(Tuple.prototype, {
117117
return this;
118118
},
119119

120-
popped: arrayMethodUpdatingTuple("pop", "popped"),
121-
122-
pushed: arrayMethodUpdatingTuple("push", "pushed"),
123-
124-
reversed: arrayMethodUpdatingTuple("reverse", "reversed"),
125-
126-
shifted: arrayMethodUpdatingTuple("shift", "shifted"),
127-
128-
unshifted: arrayMethodUpdatingTuple("unshift", "unshifted"),
129-
130-
sorted: arrayMethodUpdatingTuple("sort", "sorted"),
131-
132-
spliced: arrayMethodUpdatingTuple("splice", "spliced"),
133-
134120
concat(...values) {
135121
assertTuple(this, "concat");
136122

@@ -181,9 +167,9 @@ define(Tuple.prototype, {
181167

182168
return this.reduce((acc, cur) => {
183169
if (Tuple.isTuple(cur)) {
184-
return acc.pushed.apply(acc, this.flat.call(cur, depth - 1));
170+
return acc.concat(this.flat.call(cur, depth - 1));
185171
} else {
186-
return acc.pushed(cur);
172+
return acc.concat(Tuple(cur));
187173
}
188174
}, Tuple());
189175
},
@@ -210,6 +196,12 @@ define(Tuple.prototype, {
210196

211197
toLocaleString: arrayMethod("toLocaleString"),
212198

199+
toReversed: arrayMethodUpdatingTuple("reverse", "toReversed"),
200+
201+
toSorted: arrayMethodUpdatingTuple("sort", "toSorted"),
202+
203+
toSpliced: arrayMethodUpdatingTuple("splice", "toSpliced"),
204+
213205
with(index, value) {
214206
assertTuple(this, "with");
215207

packages/record-tuple-polyfill/src/tuple.test.js

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,11 @@ describe("all and only the specified prototype methods exist", () => {
109109
const list = ([str]) => str.trim().split(/\s+/g);
110110

111111
const names = list`
112-
constructor valueOf length with
113-
popped pushed reversed shifted slice
114-
sorted spliced concat includes indexOf join
112+
constructor valueOf length with slice toReversed
113+
toSorted toSpliced concat includes indexOf join
115114
lastIndexOf entries every filter find findIndex
116115
flat flatMap forEach keys map reduce reduceRight some
117-
unshifted toLocaleString toString values
116+
toLocaleString toString values
118117
`.concat(Symbol.iterator, Symbol.toStringTag);
119118

120119
test.each(names)(".%s", name => {
@@ -162,18 +161,6 @@ test("Tuple.prototype.toString", () => {
162161
expect(() => Tuple.prototype.toString.call([])).toThrow(TypeError);
163162
});
164163

165-
test("Tuple.prototype.popped", () => {
166-
expect(Tuple().popped()).toBe(Tuple());
167-
expect(Tuple(1).popped()).toBe(Tuple());
168-
expect(Tuple(1, 2, 3).popped()).toBe(Tuple(1, 2));
169-
expect(() => Tuple.prototype.popped.call([1, 2, 3])).toThrow(TypeError);
170-
});
171-
test("Tuple.prototype.pushed", () => {
172-
expect(Tuple().pushed()).toBe(Tuple());
173-
expect(Tuple().pushed(undefined)).toBe(Tuple(undefined));
174-
expect(Tuple().pushed(1, 2, 3)).toBe(Tuple(1, 2, 3));
175-
expect(Tuple(1, 2, 3).pushed(4, 5, 6)).toBe(Tuple(1, 2, 3, 4, 5, 6));
176-
});
177164
test("Tuple.prototype.map", () => {
178165
expect(Tuple(1, 2, 3).map(x => 2 * x)).toBe(Tuple(2, 4, 6));
179166
expect(() => Tuple.prototype.map.call([1, 2, 3], x => 2 * x)).toThrow(
@@ -207,6 +194,15 @@ test("Tuple.prototype.concat", () => {
207194
Tuple(1, 2, 3, 4, 5, 6, 7),
208195
);
209196
});
197+
test("Tuple.prototype.toSorted", () => {
198+
expect(Tuple(1, 3, 2).toSorted()).toBe(Tuple(1, 2, 3));
199+
});
200+
test("Tuple.prototype.toReversed", () => {
201+
expect(Tuple(3, 2, 1).toReversed()).toBe(Tuple(1, 2, 3));
202+
});
203+
test("Tuple.prototype.toSpliced", () => {
204+
expect(Tuple(1, 1, 1, 4).toSpliced(1, 2, 2, 3)).toBe(Tuple(1, 2, 3, 4));
205+
});
210206
// TODO: Tuple prototype methods
211207

212208
describe("correct descriptors", () => {

0 commit comments

Comments
 (0)