Files
angular-docs-cn/modules/angular2/test/compiler/util_spec.ts
T

62 lines
1.9 KiB
TypeScript
Raw Normal View History

import {
AsyncTestCompleter,
beforeEach,
ddescribe,
describe,
el,
expect,
iit,
inject,
it,
xit,
TestComponentBuilder
2015-10-13 00:29:13 -07:00
} from 'angular2/testing_internal';
2015-11-06 17:34:07 -08:00
import {IS_DART} from 'angular2/src/facade/lang';
2015-11-05 14:07:57 -08:00
import {escapeSingleQuoteString, escapeDoubleQuoteString} from 'angular2/src/compiler/util';
export function main() {
describe('util', () => {
describe('escapeSingleQuoteString', () => {
it('should escape single quotes',
() => { expect(escapeSingleQuoteString(`'`)).toEqual(`'\\''`); });
it('should escape backslash',
() => { expect(escapeSingleQuoteString('\\')).toEqual(`'\\\\'`); });
it('should escape newlines',
() => { expect(escapeSingleQuoteString('\n')).toEqual(`'\\n'`); });
2015-09-18 10:33:23 -07:00
it('should escape carriage returns',
() => { expect(escapeSingleQuoteString('\r')).toEqual(`'\\r'`); });
2015-09-18 10:33:23 -07:00
if (IS_DART) {
it('should escape $', () => { expect(escapeSingleQuoteString('$')).toEqual(`'\\$'`); });
} else {
it('should not escape $', () => { expect(escapeSingleQuoteString('$')).toEqual(`'$'`); });
}
});
describe('escapeDoubleQuoteString', () => {
it('should escape double quotes',
() => { expect(escapeDoubleQuoteString(`"`)).toEqual(`"\\""`); });
it('should escape backslash',
() => { expect(escapeDoubleQuoteString('\\')).toEqual(`"\\\\"`); });
it('should escape newlines',
() => { expect(escapeDoubleQuoteString('\n')).toEqual(`"\\n"`); });
2015-09-18 10:33:23 -07:00
it('should escape carriage returns',
() => { expect(escapeDoubleQuoteString('\r')).toEqual(`"\\r"`); });
2015-09-18 10:33:23 -07:00
if (IS_DART) {
it('should escape $', () => { expect(escapeDoubleQuoteString('$')).toEqual(`"\\$"`); });
} else {
it('should not escape $', () => { expect(escapeDoubleQuoteString('$')).toEqual(`"$"`); });
}
});
});
}