| OLD | NEW |
| (Empty) |
| 1 /// <reference path="../typings/mocha/mocha.d.ts"/> | |
| 2 import {expectTranslate, expectErroneousCode} from './test_support'; | |
| 3 | |
| 4 describe('literals', () => { | |
| 5 it('translates string literals', () => { | |
| 6 expectTranslate(`'hello\\' "world'`).to.equal(`"hello' \\"world";`); | |
| 7 expectTranslate(`"hello\\" 'world"`).to.equal(`"hello\\" 'world";`); | |
| 8 }); | |
| 9 | |
| 10 it('translates string templates', () => { | |
| 11 expectTranslate('`hello \nworld`').to.equal(`'''hello \nworld''';`); | |
| 12 expectTranslate('`hello ${world}`').to.equal(`'''hello \${ world}''';`); | |
| 13 expectTranslate('`${a}$b${$c}`').to.equal(`'''\${ a}\\$b\${ $c}''';`); | |
| 14 expectTranslate('`\'${a}\'`').to.equal(`'''\\\'\${ a}\\\'''';`); | |
| 15 expectTranslate('`\'a\'`').to.equal(`'''\\\'a\\\'''';`); | |
| 16 // https://github.com/angular/angular/issues/509 | |
| 17 expectTranslate('"${a}"').to.equal('"\\${a}";'); | |
| 18 expectTranslate('"\\${a}"').to.equal('"\\${a}";'); | |
| 19 expectTranslate('\'\\${a}\'').to.equal('"\\${a}";'); | |
| 20 expectTranslate('\'$a\'').to.equal(`"\\$a";`); | |
| 21 expectTranslate('`$a`').to.equal(`'''\\$a''';`); | |
| 22 expectTranslate('`\\$a`').to.equal(`'''\\$a''';`); | |
| 23 }); | |
| 24 | |
| 25 it('escapes escape sequences', | |
| 26 () => { expectTranslate('`\\\\u1234`').to.equal(`'''\\\\u1234''';`); }); | |
| 27 | |
| 28 it('translates boolean literals', () => { | |
| 29 expectTranslate('true').to.equal('true;'); | |
| 30 expectTranslate('false').to.equal('false;'); | |
| 31 expectTranslate('var b:boolean = true;').to.equal('bool b = true;'); | |
| 32 }); | |
| 33 | |
| 34 it('translates the null literal', () => { expectTranslate('null').to.equal('nu
ll;'); }); | |
| 35 | |
| 36 it('translates number literals', () => { | |
| 37 // Negative numbers are handled by unary minus expressions. | |
| 38 expectTranslate('1234').to.equal('1234;'); | |
| 39 expectTranslate('12.34').to.equal('12.34;'); | |
| 40 expectTranslate('1.23e-4').to.equal('1.23e-4;'); | |
| 41 }); | |
| 42 | |
| 43 it('translates regexp literals', () => { | |
| 44 expectTranslate('/wo\\/t?/g').to.equal('new RegExp(r\'wo\\/t?\');'); | |
| 45 expectTranslate('/\'/g').to.equal('new RegExp(r\'\' + "\'" + r\'\');'); | |
| 46 expectTranslate('/\'o\'/g').to.equal('new RegExp(r\'\' + "\'" + r\'o\' + "\'
" + r\'\');'); | |
| 47 expectTranslate('/abc/gmi') | |
| 48 .to.equal('new RegExp(r\'abc\', multiLine: true, caseSensitive: false);'
); | |
| 49 expectErroneousCode('/abc/').to.throw(/Regular Expressions must use the \/\/
g flag/); | |
| 50 }); | |
| 51 | |
| 52 it('translates array literals', () => { | |
| 53 expectTranslate('[1,2]').to.equal('[1, 2];'); | |
| 54 expectTranslate('[1,]').to.equal('[1];'); | |
| 55 expectTranslate('[]').to.equal('[];'); | |
| 56 }); | |
| 57 | |
| 58 it('translates object literals', () => { | |
| 59 expectTranslate('var x = {a: 1, b: 2}').to.equal('var x = {"a": 1, "b": 2};'
); | |
| 60 expectTranslate('var x = {a: 1, }').to.equal('var x = {"a": 1};'); | |
| 61 expectTranslate('var x = {}').to.equal('var x = {};'); | |
| 62 expectTranslate('var x = {y}').to.equal('var x = {"y": y};'); | |
| 63 }); | |
| 64 }); | |
| OLD | NEW |