| OLD | NEW |
| 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.import('dart/core'); | 6 var core = loader.import('dart/core'); |
| 7 var collection = dart.import('dart/collection'); | 7 var collection = loader.import('dart/collection'); |
| 8 var dart = loader.import('dart/dart_runtime'); |
| 9 var dartx = loader.import('dart/dartx'); |
| 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 = loader.import('dart/classes'); |
| 15 var types = loader.import('dart/types'); |
| 8 | 16 |
| 9 suite('generic', () => { | 17 suite('generic', () => { |
| 10 "use strict"; | 18 "use strict"; |
| 11 | 19 |
| 12 let generic = dart.generic; | 20 let generic = dart.generic; |
| 13 | 21 |
| 14 test('zero arguments is not allowed', () => { | 22 test('zero arguments is not allowed', () => { |
| 15 assert.throws(() => { generic(function(){}); }); | 23 assert.throws(() => { generic(function(){}); }); |
| 16 }); | 24 }); |
| 17 | 25 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 count = 0; | 72 count = 0; |
| 65 | 73 |
| 66 // Nothing has been stored on the object | 74 // Nothing has been stored on the object |
| 67 assert.strictEqual(Object.keys(t1).length, 0); | 75 assert.strictEqual(Object.keys(t1).length, 0); |
| 68 assert.strictEqual(Object.keys(t2).length, 0); | 76 assert.strictEqual(Object.keys(t2).length, 0); |
| 69 }); | 77 }); |
| 70 | 78 |
| 71 test('type constructor is reflectable', () => { | 79 test('type constructor is reflectable', () => { |
| 72 let SomeType = generic(function(x, y) { return Object.create(null); }); | 80 let SomeType = generic(function(x, y) { return Object.create(null); }); |
| 73 let someValue = SomeType('hi', 123); | 81 let someValue = SomeType('hi', 123); |
| 74 assert.equal(someValue[dart.originalDeclaration], SomeType); | 82 assert.equal(classes.getGenericClass(someValue), SomeType); |
| 75 assert.deepEqual(someValue[dart.typeArguments], ['hi', 123]); | 83 assert.deepEqual(classes.getGenericArgs(someValue), ['hi', 123]); |
| 76 }); | 84 }); |
| 77 | 85 |
| 78 test('proper type constructor is called', () => { | 86 test('proper type constructor is called', () => { |
| 79 // This tests https://github.com/dart-lang/dev_compiler/issues/178 | 87 // This tests https://github.com/dart-lang/dev_compiler/issues/178 |
| 80 let l = dart.list([1, 2, 3], core.int); | 88 let l = dart.list([1, 2, 3], core.int); |
| 81 let s = l[dartx.join](); | 89 let s = l[dartx.join](); |
| 82 assert.equal(s, '123'); | 90 assert.equal(s, '123'); |
| 83 }); | 91 }); |
| 84 }); | 92 }); |
| 85 | 93 |
| 86 | 94 |
| 87 suite('instanceOf', () => { | 95 suite('instanceOf', () => { |
| 88 "use strict"; | 96 "use strict"; |
| 89 | 97 |
| 90 let expect = assert.equal; | 98 let expect = assert.equal; |
| 91 let isGroundType = dart.isGroundType; | 99 let isGroundType = types.isGroundType; |
| 92 let generic = dart.generic; | 100 let generic = dart.generic; |
| 93 let intIsNonNullable = false; | 101 let intIsNonNullable = false; |
| 94 let cast = dart.as; | 102 let cast = dart.as; |
| 95 let instanceOf = dart.is; | 103 let instanceOf = dart.is; |
| 96 let runtimeType = dart.realRuntimeType; | 104 let runtimeType = dart.realRuntimeType; |
| 97 let functionType = dart.functionType; | 105 let functionType = dart.functionType; |
| 98 let typedef = dart.typedef; | 106 let typedef = dart.typedef; |
| 99 let isSubtype = dart.isSubtype; | 107 let isSubtype = types.isSubtype; |
| 100 | 108 |
| 101 let Object = core.Object; | 109 let Object = core.Object; |
| 102 let String = core.String; | 110 let String = core.String; |
| 103 let dynamic = dart.dynamic; | 111 let dynamic = dart.dynamic; |
| 104 let List = core.List; | 112 let List = core.List; |
| 105 let Map = core.Map; | 113 let Map = core.Map; |
| 106 let Map$ = core.Map$; | 114 let Map$ = core.Map$; |
| 107 let int = core.int; | 115 let int = core.int; |
| 108 let num = core.num; | 116 let num = core.num; |
| 109 let bool = core.bool; | 117 let bool = core.bool; |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 | 366 |
| 359 checkType(s1, c.IterableMixin); | 367 checkType(s1, c.IterableMixin); |
| 360 checkType(s1, c.IterableMixin$(String)); | 368 checkType(s1, c.IterableMixin$(String)); |
| 361 checkType(s1, c.IterableMixin$(int), false); | 369 checkType(s1, c.IterableMixin$(int), false); |
| 362 | 370 |
| 363 checkType(s1, c.SetMixin); | 371 checkType(s1, c.SetMixin); |
| 364 checkType(s1, c.SetMixin$(String)); | 372 checkType(s1, c.SetMixin$(String)); |
| 365 checkType(s1, c.SetMixin$(int), false); | 373 checkType(s1, c.SetMixin$(int), false); |
| 366 }); | 374 }); |
| 367 | 375 |
| 376 test('Type', () => { |
| 377 checkType(int, core.Type, true); |
| 378 checkType(num, core.Type, true); |
| 379 checkType(bool, core.Type, true); |
| 380 checkType(String, core.Type, true); |
| 381 checkType(dynamic, core.Type, true); |
| 382 checkType(Object, core.Type, true); |
| 383 checkType(List, core.Type, true); |
| 384 checkType(Map, core.Type, true); |
| 385 checkType(Map$(int, String), core.Type, true); |
| 386 checkType(Func2, core.Type, true); |
| 387 checkType(functionType(dynamic, [dynamic]), core.Type, true); |
| 388 checkType(core.Type, core.Type, true); |
| 389 |
| 390 checkType(3, core.Type, false); |
| 391 checkType("hello", core.Type, false); |
| 392 }) |
| 393 |
| 368 test('Functions', () => { | 394 test('Functions', () => { |
| 369 // - return type: Dart is bivariant. We're covariant. | 395 // - return type: Dart is bivariant. We're covariant. |
| 370 // - param types: Dart is bivariant. We're contravariant. | 396 // - param types: Dart is bivariant. We're contravariant. |
| 371 expect(isGroundType(Func2), true); | 397 expect(isGroundType(Func2), true); |
| 372 expect(isGroundType(Foo), false); | 398 expect(isGroundType(Foo), false); |
| 373 expect(isGroundType(functionType(B, [B, String])), false); | 399 expect(isGroundType(functionType(B, [B, String])), false); |
| 374 checkType(bar1, Foo, false); | 400 checkType(bar1, Foo, false); |
| 375 checkType(cls1, Foo, false); | 401 checkType(cls1, Foo, false); |
| 376 checkType(bar1, functionType(B, [B, String]), false); | 402 checkType(bar1, functionType(B, [B, String]), false); |
| 377 checkType(cls1, functionType(B, [B, String]), false); | 403 checkType(cls1, functionType(B, [B, String]), false); |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 704 | 730 |
| 705 suite('primitives', function() { | 731 suite('primitives', function() { |
| 706 'use strict'; | 732 'use strict'; |
| 707 | 733 |
| 708 test('fixed length list', () => { | 734 test('fixed length list', () => { |
| 709 let list = new core.List(10); | 735 let list = new core.List(10); |
| 710 list[0] = 42; | 736 list[0] = 42; |
| 711 assert.throws(() => list.add(42)); | 737 assert.throws(() => list.add(42)); |
| 712 }); | 738 }); |
| 713 }); | 739 }); |
| OLD | NEW |