From 526c51d1a6c2fa47b2bd9eb186f0ef4388b12982 Mon Sep 17 00:00:00 2001 From: Yegor Jbanov Date: Fri, 17 Apr 2015 13:20:03 -0700 Subject: [PATCH] fix(facades): fix splice semantics; add test --- modules/angular2/src/facade/collection.dart | 3 ++- modules/angular2/src/facade/collection.es6 | 4 ++-- modules/angular2/src/facade/collection.ts | 3 +++ modules/angular2/test/facade/collection_spec.js | 16 ++++++++++++++++ .../src/components/switcher/switch.js | 2 +- 5 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 modules/angular2/test/facade/collection_spec.js diff --git a/modules/angular2/src/facade/collection.dart b/modules/angular2/src/facade/collection.dart index e5b5e3c21e..98a8fcc846 100644 --- a/modules/angular2/src/facade/collection.dart +++ b/modules/angular2/src/facade/collection.dart @@ -154,7 +154,8 @@ class ListWrapper { static List slice(List l, int from, int to) { return l.sublist(from, to); } - static List splice(List l, int from, int to) { + static List splice(List l, int from, int length) { + var to = from + length; var sub = l.sublist(from, to); l.removeRange(from, to); return sub; diff --git a/modules/angular2/src/facade/collection.es6 b/modules/angular2/src/facade/collection.es6 index c6230b53ac..eed0ba58d3 100644 --- a/modules/angular2/src/facade/collection.es6 +++ b/modules/angular2/src/facade/collection.es6 @@ -193,8 +193,8 @@ export class ListWrapper { static slice(l:List, from:int, to:int):List { return l.slice(from, to); } - static splice(l:List, from:int, to:int):List { - return l.splice(from, to); + static splice(l:List, from:int, length:int):List { + return l.splice(from, length); } static sort(l:List, compareFn:Function) { l.sort(compareFn); diff --git a/modules/angular2/src/facade/collection.ts b/modules/angular2/src/facade/collection.ts index a65debc39d..367d9164c5 100644 --- a/modules/angular2/src/facade/collection.ts +++ b/modules/angular2/src/facade/collection.ts @@ -168,6 +168,9 @@ export class ListWrapper { return true; } static slice(l: List, from: int, to: int): List { return l.slice(from, to); } + static splice(l:List, from:int, length:int):List { + return l.splice(from, length); + } static sort(l: List, compareFn: (a: T, b: T) => number) { l.sort(compareFn); } } diff --git a/modules/angular2/test/facade/collection_spec.js b/modules/angular2/test/facade/collection_spec.js new file mode 100644 index 0000000000..0cf487141e --- /dev/null +++ b/modules/angular2/test/facade/collection_spec.js @@ -0,0 +1,16 @@ +import {describe, it, expect, beforeEach, ddescribe, iit, xit} + from 'angular2/test_lib'; + +import {List, ListWrapper} from 'angular2/src/facade/collection'; + +export function main() { + describe('ListWrapper', () => { + describe('splice', () => { + it('should remove sublist of given length and return it', () => { + var list = [1, 2, 3, 4, 5, 6]; + expect(ListWrapper.splice(list, 1, 3)).toEqual([2, 3, 4]); + expect(list).toEqual([1, 5, 6]); + }); + }); + }); +} diff --git a/modules/angular2_material/src/components/switcher/switch.js b/modules/angular2_material/src/components/switcher/switch.js index 8e5cc27fef..c092b686df 100644 --- a/modules/angular2_material/src/components/switcher/switch.js +++ b/modules/angular2_material/src/components/switcher/switch.js @@ -65,7 +65,7 @@ export class MdSwitch { } onKeydown(event: KeyboardEvent) { - if (event.keyCode == KEY_SPACE) { + if (event.keyCode === KEY_SPACE) { event.preventDefault(); this.toggle(event); }