fix(facades): fix splice semantics; add test

This commit is contained in:
Yegor Jbanov 2015-04-17 13:20:03 -07:00
parent 2b4d30d931
commit 526c51d1a6
5 changed files with 24 additions and 4 deletions

View File

@ -154,7 +154,8 @@ class ListWrapper {
static List slice(List l, int from, int to) { static List slice(List l, int from, int to) {
return l.sublist(from, 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); var sub = l.sublist(from, to);
l.removeRange(from, to); l.removeRange(from, to);
return sub; return sub;

View File

@ -193,8 +193,8 @@ export class ListWrapper {
static slice(l:List, from:int, to:int):List { static slice(l:List, from:int, to:int):List {
return l.slice(from, to); return l.slice(from, to);
} }
static splice(l:List, from:int, to:int):List { static splice(l:List, from:int, length:int):List {
return l.splice(from, to); return l.splice(from, length);
} }
static sort(l:List, compareFn:Function) { static sort(l:List, compareFn:Function) {
l.sort(compareFn); l.sort(compareFn);

View File

@ -168,6 +168,9 @@ export class ListWrapper {
return true; return true;
} }
static slice<T>(l: List<T>, from: int, to: int): List<T> { return l.slice(from, to); } static slice<T>(l: List<T>, from: int, to: int): List<T> { return l.slice(from, to); }
static splice<T>(l:List<T>, from:int, length:int):List<T> {
return l.splice(from, length);
}
static sort<T>(l: List<T>, compareFn: (a: T, b: T) => number) { l.sort(compareFn); } static sort<T>(l: List<T>, compareFn: (a: T, b: T) => number) { l.sort(compareFn); }
} }

View File

@ -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]);
});
});
});
}

View File

@ -65,7 +65,7 @@ export class MdSwitch {
} }
onKeydown(event: KeyboardEvent) { onKeydown(event: KeyboardEvent) {
if (event.keyCode == KEY_SPACE) { if (event.keyCode === KEY_SPACE) {
event.preventDefault(); event.preventDefault();
this.toggle(event); this.toggle(event);
} }