2015-10-13 03:29:13 -04:00
|
|
|
import {describe, it, expect, beforeEach, ddescribe, iit, xit, el} from 'angular2/testing_internal';
|
2015-05-26 20:00:31 -04:00
|
|
|
import {
|
|
|
|
isPresent,
|
|
|
|
RegExpWrapper,
|
|
|
|
RegExpMatcherWrapper,
|
|
|
|
StringWrapper,
|
|
|
|
CONST_EXPR
|
2015-11-06 20:34:07 -05:00
|
|
|
} from 'angular2/src/facade/lang';
|
2015-05-26 20:00:31 -04:00
|
|
|
|
|
|
|
export function main() {
|
2015-06-02 11:07:13 -04:00
|
|
|
describe('RegExp', () => {
|
|
|
|
it('should expose the index for each match', () => {
|
2015-06-23 06:46:38 -04:00
|
|
|
var re = /(!)/g;
|
2015-06-02 11:07:13 -04:00
|
|
|
var matcher = RegExpWrapper.matcher(re, '0!23!567!!');
|
|
|
|
var indexes = [];
|
|
|
|
var m;
|
|
|
|
|
|
|
|
while (isPresent(m = RegExpMatcherWrapper.next(matcher))) {
|
2015-06-17 14:17:21 -04:00
|
|
|
indexes.push(m.index);
|
2015-06-02 11:07:13 -04:00
|
|
|
expect(m[0]).toEqual('!');
|
|
|
|
expect(m[1]).toEqual('!');
|
|
|
|
expect(m.length).toBe(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(indexes).toEqual([1, 4, 8, 9]);
|
|
|
|
});
|
2015-07-28 21:38:35 -04:00
|
|
|
|
|
|
|
it('should reset before it is reused', () => {
|
|
|
|
var re = /^['"]/g;
|
|
|
|
var str = "'";
|
|
|
|
expect(RegExpWrapper.test(re, str)).toEqual(true);
|
|
|
|
// If not reset, the second attempt to test results in false
|
|
|
|
expect(RegExpWrapper.test(re, str)).toEqual(true);
|
|
|
|
});
|
2015-06-02 11:07:13 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('const', () => {
|
|
|
|
it('should support const expressions both in TS and Dart', () => {
|
|
|
|
const numbers = CONST_EXPR([1, 2, 3]);
|
|
|
|
expect(numbers).toEqual([1, 2, 3]);
|
|
|
|
});
|
|
|
|
});
|
2015-05-26 20:00:31 -04:00
|
|
|
|
|
|
|
describe('String', () => {
|
2015-10-31 16:04:26 -04:00
|
|
|
var s;
|
2015-08-30 20:04:15 -04:00
|
|
|
|
|
|
|
describe('slice', () => {
|
|
|
|
beforeEach(() => { s = "abcdefghij"; });
|
|
|
|
|
|
|
|
it('should return the whole string if neither start nor end are specified',
|
|
|
|
() => { expect(StringWrapper.slice(s)).toEqual("abcdefghij"); });
|
|
|
|
|
|
|
|
it('should return up to the end if end is not specified',
|
|
|
|
() => { expect(StringWrapper.slice(s, 1)).toEqual("bcdefghij"); });
|
|
|
|
|
|
|
|
it('should support negative start',
|
|
|
|
() => { expect(StringWrapper.slice(s, -1)).toEqual("j"); });
|
|
|
|
|
|
|
|
it('should support negative end',
|
|
|
|
() => { expect(StringWrapper.slice(s, -3, -1)).toEqual("hi"); });
|
|
|
|
|
2015-08-30 20:05:02 -04:00
|
|
|
it('should return empty string if start is greater than end', () => {
|
|
|
|
expect(StringWrapper.slice(s, 4, 2)).toEqual("");
|
|
|
|
expect(StringWrapper.slice(s, -2, -4)).toEqual("");
|
|
|
|
});
|
2015-08-30 20:04:15 -04:00
|
|
|
});
|
|
|
|
|
2015-05-26 20:00:31 -04:00
|
|
|
});
|
|
|
|
}
|