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

Unified Diff: test/codegen_expected/language/no_such_method_mock_test.js

Issue 2158173003: fix #603, support mock objects (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: add test Created 4 years, 5 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
Index: test/codegen_expected/language/no_such_method_mock_test.js
diff --git a/test/codegen_expected/language/no_such_method_mock_test.js b/test/codegen_expected/language/no_such_method_mock_test.js
new file mode 100644
index 0000000000000000000000000000000000000000..c7174245a49c2f99d7355c491408490ad07ff783
--- /dev/null
+++ b/test/codegen_expected/language/no_such_method_mock_test.js
@@ -0,0 +1,87 @@
+dart_library.library('language/no_such_method_mock_test', null, /* Imports */[
+ 'dart_sdk',
+ 'expect'
+], function load__no_such_method_mock_test(exports, dart_sdk, expect) {
+ 'use strict';
+ const core = dart_sdk.core;
+ const dart = dart_sdk.dart;
+ const dartx = dart_sdk.dartx;
+ const expect$ = expect.expect;
+ const no_such_method_mock_test = Object.create(null);
+ let VoidToint = () => (VoidToint = dart.constFn(dart.definiteFunctionType(core.int, [])))();
+ let VoidTovoid = () => (VoidTovoid = dart.constFn(dart.definiteFunctionType(dart.void, [])))();
+ no_such_method_mock_test.Cat = class Cat extends core.Object {
+ eatFood(food) {
+ return true;
+ }
+ scratch(furniture) {
+ return 100;
+ }
+ };
+ dart.setSignature(no_such_method_mock_test.Cat, {
+ methods: () => ({
+ eatFood: dart.definiteFunctionType(core.bool, [core.String]),
+ scratch: dart.definiteFunctionType(core.int, [core.String])
+ })
+ });
+ no_such_method_mock_test.MockCat = class MockCat extends core.Object {
+ noSuchMethod(invocation) {
+ return core.String.as(invocation.positionalArguments[dartx.get](0))[dartx.isNotEmpty];
+ }
+ eatFood(food) {
+ return core.bool._check(this.noSuchMethod(new dart.InvocationImpl('eatFood', [food], {isMethod: true})));
+ }
+ scratch(furniture) {
+ return core.int._check(this.noSuchMethod(new dart.InvocationImpl('scratch', [furniture], {isMethod: true})));
+ }
+ };
+ no_such_method_mock_test.MockCat[dart.implements] = () => [no_such_method_mock_test.Cat];
+ no_such_method_mock_test.MockCat2 = class MockCat2 extends no_such_method_mock_test.MockCat {
+ eatFood(food) {
+ return core.bool._check(this.noSuchMethod(new dart.InvocationImpl('eatFood', [food], {isMethod: true})));
+ }
+ scratch(furniture) {
+ return core.int._check(this.noSuchMethod(new dart.InvocationImpl('scratch', [furniture], {isMethod: true})));
+ }
+ };
+ let const$;
+ no_such_method_mock_test.MockCat3 = class MockCat3 extends no_such_method_mock_test.MockCat2 {
+ noSuchMethod(invocation) {
+ return dart.test(core.String.as(invocation.positionalArguments[dartx.get](0))[dartx.isNotEmpty]) && dart.test(dart.dsend(invocation.namedArguments[dartx.get](const$ || (const$ = dart.const(core.Symbol.new('amount')))), '>', 0.5));
+ }
+ eatFood(food, opts) {
+ return core.bool._check(this.noSuchMethod(new dart.InvocationImpl('eatFood', [food], {namedArguments: opts, isMethod: true})));
+ }
+ scratch(furniture, furniture2) {
+ return core.int._check(this.noSuchMethod(new dart.InvocationImpl('scratch', [furniture, furniture2], {isMethod: true})));
+ }
+ };
+ no_such_method_mock_test.MockCat3[dart.implements] = () => [no_such_method_mock_test.Cat];
+ no_such_method_mock_test.MockWithGenerics = class MockWithGenerics extends core.Object {
+ noSuchMethod(i) {
+ return dart.dsend(i.positionalArguments[dartx.get](0), '+', 100);
+ }
+ doStuff(T) {
+ return t => {
+ return T._check(this.noSuchMethod(new dart.InvocationImpl('doStuff', [t], {isMethod: true})));
+ };
+ }
+ };
+ no_such_method_mock_test.main = function() {
+ let mock = new no_such_method_mock_test.MockCat();
+ expect$.Expect.isTrue(dart.dsend(mock, 'eatFood', "cat food"));
+ expect$.Expect.isFalse(mock.eatFood(""));
+ expect$.Expect.throws(dart.fn(() => dart.notNull(mock.scratch("couch")) + 0, VoidToint()));
+ let mock2 = new no_such_method_mock_test.MockCat2();
+ expect$.Expect.isTrue(mock2.eatFood("cat food"));
+ let mock3 = new no_such_method_mock_test.MockCat3();
+ expect$.Expect.isTrue(mock3.eatFood("cat food", {amount: 0.9}));
+ expect$.Expect.isFalse(mock3.eatFood("cat food", {amount: 0.3}));
+ let g = new no_such_method_mock_test.MockWithGenerics();
+ expect$.Expect.equals(g.doStuff(core.int)(42), 142);
+ expect$.Expect.throws(dart.fn(() => g.doStuff(dart.dynamic)('hi'), VoidTovoid()));
+ };
+ dart.fn(no_such_method_mock_test.main, VoidTovoid());
+ // Exports:
+ exports.no_such_method_mock_test = no_such_method_mock_test;
+});

Powered by Google App Engine
This is Rietveld 408576698