Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Side by Side Diff: test/function_test.ts

Issue 2434903002: Fix crash generating facades for loasd. Fix bug in how we handle TypePredicates. Add test for TypeP… (Closed)
Patch Set: Fix crash generating facades for loasd. Fix bug in how we handle TypePredicates. Add test for TypeP… Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « package.json ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /// <reference path="../typings/mocha/mocha.d.ts"/> 1 /// <reference path="../typings/mocha/mocha.d.ts"/>
2 import {expectTranslate} from './test_support'; 2 import {expectTranslate} from './test_support';
3 3
4 describe('functions', () => { 4 describe('functions', () => {
5 it('supports declarations', () => { 5 it('supports declarations', () => {
6 expectTranslate('function x() {}').to.equal(`@JS() 6 expectTranslate('function x() {}').to.equal(`@JS()
7 external x();`); 7 external x();`);
8 }); 8 });
9 it('hide param default values', () => { 9 it('hide param default values', () => {
10 expectTranslate('function x(a = 42, b = 1) { return 42; }').to.equal(`@JS() 10 expectTranslate('function x(a = 42, b = 1) { return 42; }').to.equal(`@JS()
11 external x([a, b]);`); 11 external x([a, b]);`);
12 expectTranslate('function x(p1, a = 42, b = 1, p2) { return 42; }').to.equal (`@JS() 12 expectTranslate('function x(p1, a = 42, b = 1, p2) { return 42; }').to.equal (`@JS()
13 external x(p1, [a, b, p2]);`); 13 external x(p1, [a, b, p2]);`);
14 }); 14 });
15 it('translates optional parameters', () => { 15 it('translates optional parameters', () => {
16 expectTranslate('function x(a?: number, b?: number) { return 42; }').to.equa l(`@JS() 16 expectTranslate('function x(a?: number, b?: number) { return 42; }').to.equa l(`@JS()
17 external x([num a, num b]);`); 17 external x([num a, num b]);`);
18 expectTranslate('function x(p1, a?: number, b?: number, p2) { return 42; }') .to.equal(`@JS() 18 expectTranslate('function x(p1, a?: number, b?: number, p2) { return 42; }') .to.equal(`@JS()
19 external x(p1, [num a, num b, p2]);`); 19 external x(p1, [num a, num b, p2]);`);
20 }); 20 });
21 it('supports empty returns', () => { 21 it('supports empty returns', () => {
22 expectTranslate('function x() { return; }').to.equal(`@JS() 22 expectTranslate('function x() { return; }').to.equal(`@JS()
23 external x();`); 23 external x();`);
24 }); 24 });
25 25
26 it('supports type predicates', () => {
27 expectTranslate('function isArrayBuffer(value?: any): value is ArrayBuffer;' )
28 .to.equal(`import "dart:typed_data" show ByteBuffer;
29
30 @JS()
31 external bool /*value is ByteBuffer*/ isArrayBuffer([dynamic value]);`);
32 });
33
26 it('polyfill var args', () => { 34 it('polyfill var args', () => {
27 expectTranslate('function x(...a: number[]) { return 42; }').to.equal(`@JS() 35 expectTranslate('function x(...a: number[]) { return 42; }').to.equal(`@JS()
28 external x([num a1, num a2, num a3, num a4, num a5]);`); 36 external x([num a1, num a2, num a3, num a4, num a5]);`);
29 }); 37 });
30 it('supports function parameters', () => { 38 it('supports function parameters', () => {
31 expectTranslate('function f(fn: (a: A, b: B) => C) {}').to.equal(`@JS() 39 expectTranslate('function f(fn: (a: A, b: B) => C) {}').to.equal(`@JS()
32 external f(C fn(A a, B b));`); 40 external f(C fn(A a, B b));`);
33 }); 41 });
34 it('supports recursive function parameters', () => { 42 it('supports recursive function parameters', () => {
35 expectTranslate('function f(fn: (a: (b: B) => C) => D) {}').to.equal(`@JS() 43 expectTranslate('function f(fn: (a: (b: B) => C) => D) {}').to.equal(`@JS()
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 }); 101 });
94 it('replaces type usage sites, but not idents', () => { 102 it('replaces type usage sites, but not idents', () => {
95 expectTranslate(`function wobble<T, U>(u: U): T { }`).to.equal(`@JS() 103 expectTranslate(`function wobble<T, U>(u: U): T { }`).to.equal(`@JS()
96 external dynamic/*=T*/ wobble/*<T, U>*/(dynamic/*=U*/ u);`); 104 external dynamic/*=T*/ wobble/*<T, U>*/(dynamic/*=U*/ u);`);
97 }); 105 });
98 it('translates generic calls', () => { 106 it('translates generic calls', () => {
99 expectTranslate(`function wobble<T>(foo: T): T { }`).to.equal(`@JS() 107 expectTranslate(`function wobble<T>(foo: T): T { }`).to.equal(`@JS()
100 external dynamic/*=T*/ wobble/*<T>*/(dynamic/*=T*/ foo);`); 108 external dynamic/*=T*/ wobble/*<T>*/(dynamic/*=T*/ foo);`);
101 }); 109 });
102 }); 110 });
OLDNEW
« no previous file with comments | « package.json ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698