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

Unified Diff: test/function_test.ts

Issue 2225953002: Strip more unused features. (Closed) Base URL: git@github.com:dart-lang/js_facade_gen.git@master
Patch Set: Fix types Created 4 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/facade_converter_test.ts ('k') | test/js_interop_test.ts » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/function_test.ts
diff --git a/test/function_test.ts b/test/function_test.ts
index 547366bdb91f50e2ec88a475f1bb2e044f9599f7..01c869603f9859dc9a8ae5ac4ae0d5b33e7ef913 100644
--- a/test/function_test.ts
+++ b/test/function_test.ts
@@ -1,88 +1,67 @@
/// <reference path="../typings/mocha/mocha.d.ts"/>
-import {expectTranslate, expectErroneousCode} from './test_support';
+import {expectTranslate} from './test_support';
describe('functions', () => {
- it('supports declarations', () => { expectTranslate('function x() {}').to.equal('x() {}'); });
- it('supports param default values', () => {
- expectTranslate('function x(a = 42, b = 1) { return 42; }').to.equal(`x([a = 42, b = 1]) {
- return 42;
-}`);
- expectTranslate('function x(p1, a = 42, b = 1, p2) { return 42; }')
- .to.equal(`x(p1, [a = 42, b = 1, p2]) {
- return 42;
-}`);
+ it('supports declarations', () => {
+ expectTranslate('function x() {}').to.equal(`@JS()
+external x();`);
+ });
+ it('hide param default values', () => {
+ expectTranslate('function x(a = 42, b = 1) { return 42; }').to.equal(`@JS()
+external x([a, b]);`);
+ expectTranslate('function x(p1, a = 42, b = 1, p2) { return 42; }').to.equal(`@JS()
+external x(p1, [a, b, p2]);`);
});
it('translates optional parameters', () => {
- expectTranslate('function x(a?: number, b?: number) { return 42; }')
- .to.equal(`x([num a, num b]) {
- return 42;
-}`);
- expectTranslate('function x(p1, a?: number, b?: number, p2) { return 42; }')
- .to.equal(`x(p1, [num a, num b, p2]) {
- return 42;
-}`);
+ expectTranslate('function x(a?: number, b?: number) { return 42; }').to.equal(`@JS()
+external x([num a, num b]);`);
+ expectTranslate('function x(p1, a?: number, b?: number, p2) { return 42; }').to.equal(`@JS()
+external x(p1, [num a, num b, p2]);`);
});
it('supports empty returns', () => {
- expectTranslate('function x() { return; }').to.equal(`x() {
- return;
-}`);
+ expectTranslate('function x() { return; }').to.equal(`@JS()
+external x();`);
});
- it('does not support var args', () => {
- expectErroneousCode('function x(...a: number) { return 42; }')
- .to.throw('rest parameters are unsupported');
- });
- it('translates function expressions',
- () => { expectTranslate('var a = function() {}').to.equal('var a = () {};'); });
- it('translates fat arrow operator', () => {
- expectTranslate('var a = () => {}').to.equal('var a = () {};');
- expectTranslate('var a = (): string => {}').to.equal('var a = /* String */ () {};');
- expectTranslate('var a = (p) => isBlank(p)').to.equal('var a = (p) => isBlank(p);');
- expectTranslate('var a = (p = null) => isBlank(p)')
- .to.equal('var a = ([p = null]) => isBlank(p);');
- });
- it('translates types on function expressions', () => {
- expectTranslate('let a = function(p: string): string { return p; };')
- .to.equal(`var a = /* String */ (String p) {
- return p;
-};`);
+ it('polyfill var args', () => {
+ expectTranslate('function x(...a: number[]) { return 42; }').to.equal(`@JS()
+external x([num a1, num a2, num a3, num a4, num a5]);`);
});
it('supports function parameters', () => {
- expectTranslate('function f(fn: (a: A, b: B) => C) {}').to.equal('f(C fn(A a, B b)) {}');
+ expectTranslate('function f(fn: (a: A, b: B) => C) {}').to.equal(`@JS()
+external f(C fn(A a, B b));`);
});
it('supports recursive function parameters', () => {
- expectTranslate('function f(fn: (a: (b: B) => C) => D) {}').to.equal('f(D fn(C a(B b))) {}');
+ expectTranslate('function f(fn: (a: (b: B) => C) => D) {}').to.equal(`@JS()
+external f(D fn(C a(B b)));`);
});
it('supports generic-typed function parameters', () => {
- expectTranslate('function f<T, U>(fn: (a: T, b: U) => T) {}', {
- translateBuiltins: true
- }).to.equal('f/*< T, U >*/(dynamic/*= T */ fn(dynamic/*= T */ a, dynamic/*= U */ b)) {}');
+ expectTranslate('function f<T, U>(fn: (a: T, b: U) => T) {}').to.equal(`@JS()
+external f/*<T, U>*/(dynamic/*=T*/ fn(dynamic/*=T*/ a, dynamic/*=U*/ b));`);
});
it('translates functions taking rest parameters to untyped Function', () => {
- expectTranslate('function f(fn: (...a: string[]) => number) {}').to.equal('f(Function fn) {}');
+ expectTranslate('function f(fn: (...a: string[]) => number) {}').to.equal(`@JS()
+external f(Function /*(...a: string[]) => number*/ fn);`);
});
});
+/* TODO(jacobr): support named parameters.
describe('named parameters', () => {
it('supports named parameters', () => {
- expectTranslate('function x({a = "x", b}) { return a + b; }', {
- translateBuiltins: true
- }).to.equal(`x({a: "x", b}) {
+ expectTranslate('function x({a = "x", b}) { return a + b; }').to.equal(`x({a: "x", b}) {
return a + b;
}`);
});
it('supports types on named parameters', () => {
- expectTranslate('function x({a = 1, b = 2}: {a: number, b: number} = {}) { return a + b; }', {
- translateBuiltins: true
- }).to.equal(`x({num a: 1, num b: 2}) {
+ expectTranslate('function x({a = 1, b = 2}: {a: number, b: number} = {}) { return a + b;
+}').to.equal(`x({num a: 1, num b: 2}) {
return a + b;
}`);
});
it('supports reference types on named parameters', () => {
expectTranslate(
'interface Args { a: string; b: number }\n' +
- 'function x({a, b, c}: Args) { return a + b; }',
- {translateBuiltins: true})
+ 'function x({a, b, c}: Args) { return a + b; }')
.to.equal(`abstract class Args {
String a;
num b;
@@ -93,52 +72,31 @@ x({String a, num b, c}) {
}`);
});
it('supports declared, untyped named parameters', () => {
- expectTranslate('function x({a, b}: {a: number, b}) { return a + b; }', {
- translateBuiltins: true
- }).to.equal(`x({num a, b}) {
+ expectTranslate('function x({a, b}: {a: number, b}) { return a + b; }').to.equal(`x({num a, b})
+{
return a + b;
}`);
});
it('fails for non-property types on named parameters', () => {
expectErroneousCode(
'interface X { a(a: number); }\n' +
- 'function x({a}: X) { return a + b; }',
- {translateBuiltins: true})
+ 'function x({a}: X) { return a + b; }')
.to.throw('X.a used for named parameter definition must be a property');
});
});
+*/
describe('generic functions', () => {
it('supports generic types', () => {
- expectTranslate('function sort<T, U>(xs: T[]): T[] { return xs; }', {
- translateBuiltins: true
- }).to.equal(`List<dynamic/*= T */ > sort/*< T, U >*/(List<dynamic/*= T */ > xs) {
- return xs;
-}`);
+ expectTranslate('function sort<T, U>(xs: T[]): T[] { return xs; }').to.equal(`@JS()
+external List<dynamic/*=T*/ > sort/*<T, U>*/(List<dynamic/*=T*/ > xs);`);
});
it('replaces type usage sites, but not idents', () => {
- expectTranslate(
- `function wobble<T, U>(u: U): T {
- let t: T = <T>u;
- for (let T of [1, 2]) {}
- return t;
- }`,
- {translateBuiltins: true})
- .to.equal(`dynamic/*= T */ wobble/*< T, U >*/(dynamic/*= U */ u) {
- dynamic/*= T */ t = (u as dynamic/*= T */);
- for (var T in [1, 2]) {}
- return t;
-}`);
+ expectTranslate(`function wobble<T, U>(u: U): T { }`).to.equal(`@JS()
+external dynamic/*=T*/ wobble/*<T, U>*/(dynamic/*=U*/ u);`);
});
it('translates generic calls', () => {
- expectTranslate(
- `function wobble<T>(foo: T): T { return foo; }
- let f = foo<string>('hello');`,
- {translateBuiltins: true})
- .to.equal(`dynamic/*= T */ wobble/*< T >*/(dynamic/*= T */ foo) {
- return foo;
-}
-
-var f = foo/*< String >*/("hello");`);
+ expectTranslate(`function wobble<T>(foo: T): T { }`).to.equal(`@JS()
+external dynamic/*=T*/ wobble/*<T>*/(dynamic/*=T*/ foo);`);
});
});
« no previous file with comments | « test/facade_converter_test.ts ('k') | test/js_interop_test.ts » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698