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

Side by Side Diff: tests/compiler/dart2js_native/static_methods_test.dart

Issue 2379173002: Add native_testing library to mock @Native classes (Closed)
Patch Set: xxx Created 4 years, 1 month 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
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 // Accessing static native methods names: 5 // Accessing static native methods names:
6 // plain declaration -> use @Native tag as 'scope' for declared name. 6 // plain declaration -> use @Native tag as 'scope' for declared name.
7 // identifier @JSName -> use @Native tag as 'scope' for @JSName. 7 // identifier @JSName -> use @Native tag as 'scope' for @JSName.
8 // other @JSName -> use @JSName as an expression. 8 // other @JSName -> use @JSName as an expression.
9 9
10 import "package:expect/expect.dart"; 10 import 'native_testing.dart';
11 import 'dart:_js_helper' show Native, JSName, convertDartClosureToJS; 11 import 'dart:_js_helper' show convertDartClosureToJS;
12 12
13 typedef int Callback(String s); 13 typedef int Callback(String s);
14 14
15 @Native("CC") // Tag can be different to class name. 15 @Native("CC") // Tag can be different to class name.
16 class AA { 16 class AA {
17 // This name is not an identifier, so completely defines how to access method. 17 // This name is not an identifier, so completely defines how to access method.
18 @JSName('CC.foo') 18 @JSName('CC.foo')
19 static int foo(String s) native ; 19 static int foo(String s) native ;
20 20
21 // This name is not an identifier, so completely defines how to access method. 21 // This name is not an identifier, so completely defines how to access method.
(...skipping 22 matching lines...) Expand all
44 44
45 CC.foo = function(s) { return s.length; } 45 CC.foo = function(s) { return s.length; }
46 CC.bar = function(f) { return f("Bye"); } 46 CC.bar = function(f) { return f("Bye"); }
47 CC.lepton = function(f) { return f("Lepton"); } 47 CC.lepton = function(f) { return f("Lepton"); }
48 CC.baryon = function(f) { return f("three quarks"); } 48 CC.baryon = function(f) { return f("three quarks"); }
49 49
50 self.CC = CC; 50 self.CC = CC;
51 """; 51 """;
52 52
53 main() { 53 main() {
54 nativeTesting();
54 setup(); 55 setup();
55 56
56 // TODO(sra): Investigate why this line is necessary to get a correctly 57 // TODO(sra): Investigate why this line is necessary to get a correctly
57 // compiled convertDartClosureToJS. Without this line, the compiler crashes. 58 // compiled convertDartClosureToJS. Without this line, the compiler crashes.
58 convertDartClosureToJS(main, 1); 59 convertDartClosureToJS(main, 1);
59 60
60 Expect.equals(5, AA.foo("Hello")); 61 Expect.equals(5, AA.foo("Hello"));
61 62
62 Expect.equals(3, AA.bar((s) => s.length)); 63 Expect.equals(3, AA.bar((s) => s.length));
63 Expect.equals(3, AA.baz((s) => s.length)); 64 Expect.equals(3, AA.baz((s) => s.length));
64 65
65 Expect.equals(6, AA.lepton((s) => s.length)); 66 Expect.equals(6, AA.lepton((s) => s.length));
66 Expect.equals(6, AA.electron((s) => s.length)); 67 Expect.equals(6, AA.electron((s) => s.length));
67 68
68 Expect.equals(12, AA._baryon((s) => s.length)); 69 Expect.equals(12, AA._baryon((s) => s.length));
69 Expect.equals(12, AA.proton((s) => s.length)); 70 Expect.equals(12, AA.proton((s) => s.length));
70 Expect.throws(() => AA.baryon((s) => s.length)); // Not defined on AA. 71 Expect.throws(() => AA.baryon((s) => s.length)); // Not defined on AA.
71 } 72 }
OLDNEW
« no previous file with comments | « tests/compiler/dart2js_native/runtimetype_test.dart ('k') | tests/compiler/dart2js_native/subclassing_1_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698