| OLD | NEW |
| 1 /// <reference path="../typings/mocha/mocha.d.ts"/> | 1 /// <reference path="../typings/mocha/mocha.d.ts"/> |
| 2 import {expectErroneousCode, expectTranslate} from './test_support'; | 2 import {expectErroneousCode, expectTranslate} from './test_support'; |
| 3 | 3 |
| 4 describe('variables', () => { | 4 describe('variables', () => { |
| 5 it('should print variable declaration with initializer', () => { | 5 it('should print variable declaration with initializer', () => { |
| 6 expectTranslate('var a:number = 1;').to.equal(`@JS() | 6 expectTranslate('var a:number = 1;').to.equal(`@JS() |
| 7 external num get a; | 7 external num get a; |
| 8 @JS() | 8 @JS() |
| 9 external set a(num v);`); | 9 external set a(num v);`); |
| 10 }); | 10 }); |
| (...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 expectTranslate('interface X { x: string; y; }').to.equal(`@anonymous | 385 expectTranslate('interface X { x: string; y; }').to.equal(`@anonymous |
| 386 @JS() | 386 @JS() |
| 387 abstract class X { | 387 abstract class X { |
| 388 external String get x; | 388 external String get x; |
| 389 external set x(String v); | 389 external set x(String v); |
| 390 external get y; | 390 external get y; |
| 391 external set y(v); | 391 external set y(v); |
| 392 external factory X({String x, y}); | 392 external factory X({String x, y}); |
| 393 }`); | 393 }`); |
| 394 }); | 394 }); |
| 395 |
| 396 it('supports interfaces with constructors', () => { |
| 397 expectTranslate(` |
| 398 interface XStatic { |
| 399 new (a: string, b): X; |
| 400 foo(); |
| 401 } |
| 402 |
| 403 declare var X: XStatic; |
| 404 `).to.equal(`@JS("X") |
| 405 abstract class XStatic { |
| 406 external factory XStatic(String a, b); |
| 407 external foo(); |
| 408 } |
| 409 |
| 410 @JS() |
| 411 external XStatic get X; |
| 412 @JS() |
| 413 external set X(XStatic v);`); |
| 414 |
| 415 expectTranslate(` |
| 416 interface XStatic { |
| 417 new (a: string, b): XStatic; |
| 418 foo(); |
| 419 } |
| 420 |
| 421 declare module Foo { |
| 422 declare var X: XStatic; |
| 423 } |
| 424 `).to.equal(`@JS("Foo.X") |
| 425 abstract class XStatic { |
| 426 external factory XStatic(String a, b); |
| 427 external foo(); |
| 428 } |
| 429 |
| 430 // Module Foo |
| 431 @JS("Foo.X") |
| 432 external XStatic get X; |
| 433 @JS("Foo.X") |
| 434 external set X(XStatic v); |
| 435 // End module Foo`); |
| 436 |
| 437 // Case where we cannot find a variable matching the interface so it is unsa
fe to give the |
| 438 // interface a constructor. |
| 439 expectTranslate(` |
| 440 interface XStatic { |
| 441 new (a: string|bool, b): XStatic; |
| 442 foo(); |
| 443 }`).to.equal(`@anonymous |
| 444 @JS() |
| 445 abstract class XStatic { |
| 446 // Constructors on anonymous interfaces are not yet supported. |
| 447 /*external factory XStatic(String|bool a, b);*/ |
| 448 external foo(); |
| 449 }`); |
| 450 }); |
| 395 }); | 451 }); |
| 396 | 452 |
| 397 describe('single call signature interfaces', () => { | 453 describe('single call signature interfaces', () => { |
| 398 it('should support declaration', () => { | 454 it('should support declaration', () => { |
| 399 expectTranslate('interface F { (n: number): boolean; }').to.equal('typedef b
ool F(num n);'); | 455 expectTranslate('interface F { (n: number): boolean; }').to.equal('typedef b
ool F(num n);'); |
| 400 }); | 456 }); |
| 401 it('should support generics', () => { | 457 it('should support generics', () => { |
| 402 expectTranslate('interface F<A, B> { (a: A): B; }').to.equal('typedef B F<A,
B>(A a);'); | 458 expectTranslate('interface F<A, B> { (a: A): B; }').to.equal('typedef B F<A,
B>(A a);'); |
| 403 }); | 459 }); |
| 404 }); | 460 }); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 424 external static num get Blue; | 480 external static num get Blue; |
| 425 }`); | 481 }`); |
| 426 }); | 482 }); |
| 427 it('should ingore switch', () => { | 483 it('should ingore switch', () => { |
| 428 expectTranslate('switch(c) { case Color.Red: break; default: break; }').to.e
qual(''); | 484 expectTranslate('switch(c) { case Color.Red: break; default: break; }').to.e
qual(''); |
| 429 }); | 485 }); |
| 430 it('does not support const enum', () => { | 486 it('does not support const enum', () => { |
| 431 expectErroneousCode('const enum Color { Red }').to.throw('const enums are no
t supported'); | 487 expectErroneousCode('const enum Color { Red }').to.throw('const enums are no
t supported'); |
| 432 }); | 488 }); |
| 433 }); | 489 }); |
| OLD | NEW |