blob: e31b9045e629b0e71898106cbf68cc10761c00f3 [file] [log] [blame]
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import "native_testing.dart";
// Test that native classes and ordinary Dart classes can both use the same
// ordinary Dart classes as a mixin.
class A {
String get aa native;
foo() => "A-foo $aa";
baz() => "A-baz $aa";
class B extends A with M {
bar() => 'B-bar -> ${baz()}';
get mm => '$aa)';
class M {
foo() => "M-foo ${}";
bar() => "M-bar ${}";
get mm => '';
class C {
final String cc = 'cc';
foo() => 'C-foo $cc';
baz() => 'C-baz $cc';
class D extends C with M {
bar() => 'D-bar -> ${baz()}';
get mm => '$cc)';
makeA() native;
makeB() native;
void setup() {
JS('', r"""
function A() {this.aa = 'aa'}
function B() {this.aa = 'bb'}
self.makeA = function(){return new A()};
self.makeB = function(){return new B()};
applyTestExtensions(['A', 'B']);
main() {
var things = [makeA, makeB, () => new C(), () => new D(), () => new M()]
.map((f) => f())
var a = things[0];
var b = things[1];
var c = things[2];
var d = things[3];
var m = things[4];
Expect.throws(() => m.baz(), (error) => error is NoSuchMethodError);
Expect.isFalse(m is A);
Expect.isFalse(m is B);
Expect.isFalse(m is C);
Expect.isFalse(m is D);
Expect.isTrue(m is M);
Expect.equals("A-foo aa",;
Expect.throws(() =>, (error) => error is NoSuchMethodError);
Expect.equals("A-baz aa", a.baz());
Expect.isTrue(a is A);
Expect.isFalse(a is B);
Expect.isFalse(a is C);
Expect.isFalse(a is D);
Expect.isFalse(a is M);
Expect.equals("B-bar -> A-baz bb",;
Expect.equals("A-baz bb", b.baz());
Expect.isTrue(b is A);
Expect.isTrue(b is B);
Expect.isFalse(b is C);
Expect.isFalse(b is D);
Expect.isTrue(b is M);
Expect.equals("C-foo cc",;
Expect.throws(() =>, (error) => error is NoSuchMethodError);
Expect.equals("C-baz cc", c.baz());
Expect.isFalse(c is A);
Expect.isFalse(c is B);
Expect.isTrue(c is C);
Expect.isFalse(c is D);
Expect.isFalse(c is M);
Expect.equals("D-bar -> C-baz cc",;
Expect.equals("C-baz cc", d.baz());
Expect.isFalse(d is A);
Expect.isFalse(d is B);
Expect.isTrue(d is C);
Expect.isTrue(d is D);
Expect.isTrue(d is M);