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

Side by Side Diff: test/browser/runtime_tests.js

Issue 1530563003: Generate all runtime files from dart. (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: simplify diff in js_codegen.dart Created 4 years, 11 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
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 var assert = chai.assert; 5 var assert = chai.assert;
6 var core = dart_library.import('dart/core'); 6 var core = dart_library.import('dart/core');
7 var collection = dart_library.import('dart/collection'); 7 var collection = dart_library.import('dart/collection');
8 var dart = dart_library.import('dart/_runtime'); 8 var dart = dart_library.import('dart/_runtime');
9 var dartx = dart.dartx; 9 var dartx = dart.dartx;
10 10
11 // TODO(leafp): These are here to test some things not
12 // currently exposed through the main dart entry point.
13 // If we decide to expose them, this can go away.
14 var classes = dart_library.import('dart/_classes');
15 var types = dart_library.import('dart/_types');
16 var dart_utils = dart_library.import('dart/_utils');
17
18 suite('generic', () => { 11 suite('generic', () => {
19 "use strict"; 12 "use strict";
20 13
21 let generic = dart.generic; 14 let generic = dart.generic;
22 15
23 test('zero arguments is not allowed', () => { 16 test('zero arguments is not allowed', () => {
24 assert.throws(() => { generic(function(){}); }); 17 assert.throws(() => { generic(function(){}); });
25 }); 18 });
26 19
27 test('can throw number', () => { 20 test('can throw number', () => {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 count = 0; 74 count = 0;
82 75
83 // Nothing has been stored on the object 76 // Nothing has been stored on the object
84 assert.strictEqual(Object.keys(t1).length, 0); 77 assert.strictEqual(Object.keys(t1).length, 0);
85 assert.strictEqual(Object.keys(t2).length, 0); 78 assert.strictEqual(Object.keys(t2).length, 0);
86 }); 79 });
87 80
88 test('type constructor is reflectable', () => { 81 test('type constructor is reflectable', () => {
89 let SomeType = generic(function(x, y) { return Object.create(null); }); 82 let SomeType = generic(function(x, y) { return Object.create(null); });
90 let someValue = SomeType('hi', 123); 83 let someValue = SomeType('hi', 123);
91 assert.equal(classes.getGenericClass(someValue), SomeType); 84 assert.equal(dart.getGenericClass(someValue), SomeType);
92 assert.deepEqual(classes.getGenericArgs(someValue), ['hi', 123]); 85 assert.deepEqual(dart.getGenericArgs(someValue), ['hi', 123]);
93 }); 86 });
94 87
95 test('proper type constructor is called', () => { 88 test('proper type constructor is called', () => {
96 // This tests https://github.com/dart-lang/dev_compiler/issues/178 89 // This tests https://github.com/dart-lang/dev_compiler/issues/178
97 let l = dart.list([1, 2, 3], core.int); 90 let l = dart.list([1, 2, 3], core.int);
98 let s = l[dartx.join](); 91 let s = l[dartx.join]();
99 assert.equal(s, '123'); 92 assert.equal(s, '123');
100 }); 93 });
101 }); 94 });
102 95
103 96
104 suite('instanceOf', () => { 97 suite('instanceOf', () => {
105 "use strict"; 98 "use strict";
106 99
107 let expect = assert.equal; 100 let expect = assert.equal;
108 let isGroundType = types.isGroundType; 101 let isGroundType = dart.isGroundType;
109 let generic = dart.generic; 102 let generic = dart.generic;
110 let intIsNonNullable = false; 103 let intIsNonNullable = false;
111 let cast = dart.as; 104 let cast = dart.as;
112 let instanceOf = dart.is; 105 let instanceOf = dart.is;
113 let strongInstanceOf = dart.strongInstanceOf; 106 let strongInstanceOf = dart.strongInstanceOf;
114 let runtimeType = dart.realRuntimeType; 107 let runtimeType = dart.realRuntimeType;
115 let functionType = dart.functionType; 108 let functionType = dart.functionType;
116 let typedef = dart.typedef; 109 let typedef = dart.typedef;
117 let isSubtype = types.isSubtype; 110 let isSubtype = dart.isSubtype;
118 111
119 let Object = core.Object; 112 let Object = core.Object;
120 let String = core.String; 113 let String = core.String;
121 let dynamic = dart.dynamic; 114 let dynamic = dart.dynamic;
122 let List = core.List; 115 let List = core.List;
123 let Map = core.Map; 116 let Map = core.Map;
124 let Map$ = core.Map$; 117 let Map$ = core.Map$;
125 let int = core.int; 118 let int = core.int;
126 let num = core.num; 119 let num = core.num;
127 let bool = core.bool; 120 let bool = core.bool;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 184
192 let cls8 = 185 let cls8 =
193 dart.fn((b, s, o) => { return null; }, B, [B, String], {p: Object}); 186 dart.fn((b, s, o) => { return null; }, B, [B, String], {p: Object});
194 187
195 function checkType(x, type, expectedTrue, strongOnly) { 188 function checkType(x, type, expectedTrue, strongOnly) {
196 if (expectedTrue === undefined) expectedTrue = true; 189 if (expectedTrue === undefined) expectedTrue = true;
197 if (strongOnly == undefined) strongOnly = false; 190 if (strongOnly == undefined) strongOnly = false;
198 if (!strongOnly) { 191 if (!strongOnly) {
199 expect(instanceOf(x, type), expectedTrue); 192 expect(instanceOf(x, type), expectedTrue);
200 } else { 193 } else {
201 assert.throws(() => instanceOf(x, type), dart_utils.StrongModeError); 194 assert.throws(() => instanceOf(x, type), dart.StrongModeError);
202 expect(strongInstanceOf(x, type), expectedTrue); 195 expect(strongInstanceOf(x, type), expectedTrue);
203 } 196 }
204 } 197 }
205 198
206 test('int', () => { 199 test('int', () => {
207 expect(isGroundType(int), true); 200 expect(isGroundType(int), true);
208 expect(isGroundType(runtimeType(5)), true); 201 expect(isGroundType(runtimeType(5)), true);
209 202
210 checkType(5, int); 203 checkType(5, int);
211 checkType(5, dynamic); 204 checkType(5, dynamic);
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 293
301 // null is! Map 294 // null is! Map
302 checkType(null, Map, false); 295 checkType(null, Map, false);
303 296
304 // Raw generic types 297 // Raw generic types
305 checkType(m5, Map); 298 checkType(m5, Map);
306 checkType(m4, Map); 299 checkType(m4, Map);
307 300
308 // Is checks 301 // Is checks
309 assert.throws(() => dart.is(m3, Map$(String, String)), 302 assert.throws(() => dart.is(m3, Map$(String, String)),
310 dart_utils.StrongModeError); 303 dart.StrongModeError);
311 assert.throws(() => dart.is(m6, Map$(String, String)), 304 assert.throws(() => dart.is(m6, Map$(String, String)),
312 dart_utils.StrongModeError); 305 dart.StrongModeError);
313 assert.isTrue(dart.is(m1, Map$(String, String))); 306 assert.isTrue(dart.is(m1, Map$(String, String)));
314 assert.throws(() => dart.is(m2, Map$(String, String)), 307 assert.throws(() => dart.is(m2, Map$(String, String)),
315 dart_utils.StrongModeError); 308 dart.StrongModeError);
316 309
317 // As checks 310 // As checks
318 // TODO(vsm): Enable these. We're currently only logging warnings on 311 // TODO(vsm): Enable these. We're currently only logging warnings on
319 // StrongModeErrors. 312 // StrongModeErrors.
320 // assert.throws(() => dart.as(m3, Map$(String, String)), 313 // assert.throws(() => dart.as(m3, Map$(String, String)),
321 // dart_utils.StrongModeError); 314 // dart.StrongModeError);
322 // assert.throws(() => dart.as(m6, Map$(String, String)), 315 // assert.throws(() => dart.as(m6, Map$(String, String)),
323 // dart_utils.StrongModeError); 316 // dart.StrongModeError);
324 assert.equal(dart.as(m1, Map$(String, String)), m1); 317 assert.equal(dart.as(m1, Map$(String, String)), m1);
325 // assert.throws(() => dart.as(m2, Map$(String, String)), 318 // assert.throws(() => dart.as(m2, Map$(String, String)),
326 // dart_utils.StrongModeError); 319 // dart.StrongModeError);
327 }); 320 });
328 321
329 test('constructors', () => { 322 test('constructors', () => {
330 class C extends core.Object { 323 class C extends core.Object {
331 C(x) {}; 324 C(x) {};
332 named(x, y) {}; 325 named(x, y) {};
333 } 326 }
334 dart.defineNamedConstructor(C, 'named'); 327 dart.defineNamedConstructor(C, 'named');
335 dart.setSignature(C, { 328 dart.setSignature(C, {
336 constructors: () => ({ 329 constructors: () => ({
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after
777 770
778 suite('primitives', function() { 771 suite('primitives', function() {
779 'use strict'; 772 'use strict';
780 773
781 test('fixed length list', () => { 774 test('fixed length list', () => {
782 let list = new core.List(10); 775 let list = new core.List(10);
783 list[0] = 42; 776 list[0] = 42;
784 assert.throws(() => list.add(42)); 777 assert.throws(() => list.add(42));
785 }); 778 });
786 }); 779 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698