| Index: test/expression_test.ts
|
| diff --git a/test/expression_test.ts b/test/expression_test.ts
|
| index 85eec7b7fa9709fed758c411b1147e225de1c17f..64302ff3d91fe79f821c70101ed8dd253aa7dda2 100644
|
| --- a/test/expression_test.ts
|
| +++ b/test/expression_test.ts
|
| @@ -1,97 +1,88 @@
|
| /// <reference path="../typings/mocha/mocha.d.ts"/>
|
| -import {expectTranslate, expectErroneousCode} from './test_support';
|
| +import {expectTranslate} from './test_support';
|
|
|
| -function expectTranslates(cases: any) {
|
| - for (let tsCode of Object.keys(cases)) {
|
| - expectTranslate(tsCode).to.equal(cases[tsCode]);
|
| +function expectEmptyTranslates(cases: string[]) {
|
| + for (let tsCode of cases) {
|
| + expectTranslate(tsCode).to.equal('');
|
| }
|
| }
|
|
|
| // TODO(jacobr): we don't really need to be specifying separate code for the
|
| // JS and Dart version for these tests as the code formatting is identical.
|
| -describe('expressions', () => {
|
| - it('does math', () => {
|
| - expectTranslates({
|
| - '1 + 2': '1 + 2;',
|
| - '1 - 2': '1 - 2;',
|
| - '1 * 2': '1 * 2;',
|
| - '1 / 2': '1 / 2;',
|
| - '1 % 2': '1 % 2;',
|
| - 'x++': 'x++;',
|
| - 'x--': 'x--;',
|
| - '++x': '++x;',
|
| - '--x': '--x;',
|
| - '-x': '-x;',
|
| - });
|
| +describe('ignore expressions', () => {
|
| + it('math', () => {
|
| + expectEmptyTranslates([
|
| + '1 + 2',
|
| + '1 - 2',
|
| + '1 * 2',
|
| + '1 / 2',
|
| + '1 % 2',
|
| + 'x++',
|
| + 'x--',
|
| + '++x',
|
| + '--x',
|
| + '-x',
|
| + ]);
|
| });
|
| it('assigns', () => {
|
| - expectTranslates({
|
| - 'x += 1': 'x += 1;',
|
| - 'x -= 1': 'x -= 1;',
|
| - 'x *= 1': 'x *= 1;',
|
| - 'x /= 1': 'x /= 1;',
|
| - 'x %= 1': 'x %= 1;',
|
| - 'x <<= 1': 'x = (x as int) << 1;',
|
| - 'x >>= 1': 'x = (x as int) >> 1;',
|
| - // 'x >>>= 1': 'x >>>= 1;', // This doesn't appear to be a valid operator in Dart.
|
| - 'x &= 1': 'x = (x as int) & 1;',
|
| - 'x ^= 1': 'x = (x as int) ^ 1;',
|
| - 'x |= 1': 'x = (x as int) | 1;',
|
| - });
|
| + expectEmptyTranslates([
|
| + 'x += 1',
|
| + 'x -= 1',
|
| + 'x *= 1',
|
| + 'x /= 1',
|
| + 'x %= 1',
|
| + 'x <<= 1',
|
| + 'x >>= 1',
|
| + 'x >>>= 1',
|
| + 'x &= 1',
|
| + 'x ^= 1',
|
| + 'x |= 1',
|
| + ]);
|
| });
|
| it('compares', () => {
|
| - expectTranslates({
|
| - '1 == 2': '1 == 2;',
|
| - '1 != 2': '1 != 2;',
|
| - '1 > 2': '1 > 2;',
|
| - '1 < 2': '1 < 2;',
|
| - '1 >= 2': '1 >= 2;',
|
| - '1 <= 2': '1 <= 2;',
|
| - });
|
| - });
|
| - it('compares identity', () => {
|
| - expectTranslate('1 === 2').to.equal('identical(1, 2);');
|
| - expectTranslate('1 !== 2').to.equal('!identical(1, 2);');
|
| + expectEmptyTranslates([
|
| + '1 == 2',
|
| + '1 != 2',
|
| + '1 > 2',
|
| + '1 < 2',
|
| + '1 >= 2',
|
| + '1 <= 2',
|
| + ]);
|
| });
|
| + it('compares identity', () => { expectEmptyTranslates(['1 === 2', '1 !== 2']); });
|
| it('bit fiddles', () => {
|
| - expectTranslates({
|
| - 'x & 2': '(x as int) & 2;',
|
| - '1 & 2': '1 & 2;',
|
| - '1 | 2': '1 | 2;',
|
| - '1 ^ 2': '1 ^ 2;',
|
| - '~1': '~1;',
|
| - '1 << 2': '1 << 2;',
|
| - '1 >> 2': '1 >> 2;',
|
| - '0x1 & 0x2': '0x1 & 0x2;',
|
| - // '1 >>> 2': '1 >>> 2;', // This doesn't appear to be a valid operator in Dart.
|
| - });
|
| + expectEmptyTranslates(
|
| + ['x & 2', '1 & 2', '1 | 2', '1 ^ 2', '~1', '1 << 2', '1 >> 2', '0x1 & 0x2', '1 >>> 2']);
|
| });
|
| it('translates logic', () => {
|
| - expectTranslates({
|
| - '1 && 2': '1 && 2;',
|
| - '1 || 2': '1 || 2;',
|
| - '!1': '!1;',
|
| - });
|
| + expectEmptyTranslates([
|
| + '1 && 2',
|
| + '1 || 2',
|
| + '!1',
|
| + ]);
|
| + });
|
| + it('translates ternary', () => {
|
| + expectTranslate('var x = 1 ? 2 : 3').to.equal(`@JS()
|
| +external get x;
|
| +@JS()
|
| +external set x(v);`);
|
| + });
|
| + it('translates the comma operator', () => {
|
| + expectTranslate('var x = [1, 2]').to.equal(`@JS()
|
| +external get x;
|
| +@JS()
|
| +external set x(v);`);
|
| });
|
| - it('translates ternary',
|
| - () => { expectTranslate('var x = 1 ? 2 : 3').to.equal('var x = 1 ? 2 : 3;'); });
|
| - it('translates the comma operator',
|
| - () => { expectTranslate('var x = [1, 2]').to.equal('var x = [1, 2];'); });
|
| - it('translates "in"',
|
| - () => { expectErroneousCode('x in y').to.throw('in operator is unsupported'); });
|
| - it('translates "instanceof"',
|
| - () => { expectTranslate('1 instanceof Foo').to.equal('1 is Foo;'); });
|
| - it('translates "this"', () => { expectTranslate('this.x').to.equal('this.x;'); });
|
| - it('translates "delete"',
|
| - () => { expectErroneousCode('delete x[y];').to.throw('delete operator is unsupported'); });
|
| - it('translates "typeof"',
|
| - () => { expectErroneousCode('typeof x;').to.throw('typeof operator is unsupported'); });
|
| - it('translates "void"',
|
| - () => { expectErroneousCode('void x;').to.throw('void operator is unsupported'); });
|
| - it('translates parens', () => { expectTranslate('(1)').to.equal('(1);'); });
|
| + it('translates "in"', () => { expectTranslate('x in y').to.equal(''); });
|
| + it('translates "instanceof"', () => { expectTranslate('1 instanceof Foo').to.equal(''); });
|
| + it('translates "this"', () => { expectTranslate('this.x').to.equal(''); });
|
| + it('translates "delete"', () => { expectTranslate('delete x[y];').to.equal(''); });
|
| + it('translates "typeof"', () => { expectTranslate('typeof x;').to.equal(''); });
|
| + it('translates "void"', () => { expectTranslate('void x;').to.equal(''); });
|
| + it('translates parens', () => { expectTranslate('(1)').to.equal(''); });
|
|
|
| it('translates property paths', () => {
|
| - expectTranslate('foo.bar;').to.equal('foo.bar;');
|
| - expectTranslate('foo[bar];').to.equal('foo[bar];');
|
| + expectTranslate('foo.bar;').to.equal('');
|
| + expectTranslate('foo[bar];').to.equal('');
|
| });
|
| });
|
|
|