fix: String.split(str, n) stops after n separator (#10408)

This commit is contained in:
Victor Berchet
2016-08-01 11:33:35 -07:00
committed by GitHub
parent e73d0511cf
commit 13c8211065
8 changed files with 49 additions and 35 deletions

View File

@ -9,7 +9,7 @@
import {fakeAsync} from '@angular/core/testing/fake_async';
import {beforeEach, beforeEachProviders, ddescribe, describe, expect, iit, inject, it, xit} from '@angular/core/testing/testing_internal';
import {SyncAsyncResult} from '../src/util';
import {SyncAsyncResult, splitAtColon} from '../src/util';
export function main() {
describe('util', () => {
@ -20,5 +20,21 @@ export function main() {
sar.asyncResult.then((v: any) => expect(v).toBe(syncValue));
}));
});
describe('splitAtColon', () => {
it('should split when a single ":" is present', () => {
expect(splitAtColon('a:b', [])).toEqual(['a', 'b']);
});
it('should trim parts', () => { expect(splitAtColon(' a : b ', [])).toEqual(['a', 'b']); });
it('should support multiple ":"', () => {
expect(splitAtColon('a:b:c', [])).toEqual(['a', 'b:c']);
});
it('should use the default value when no ":" is present', () => {
expect(splitAtColon('ab', ['c', 'd'])).toEqual(['c', 'd']);
});
});
});
}