Chromium Code Reviews| 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 define(['dart_sdk'], function(dart_sdk) { | 5 define(['dart_sdk'], function(dart_sdk) { |
| 6 const assert = chai.assert; | 6 const assert = chai.assert; |
| 7 const async = dart_sdk.async; | |
| 7 const core = dart_sdk.core; | 8 const core = dart_sdk.core; |
| 8 const collection = dart_sdk.collection; | 9 const collection = dart_sdk.collection; |
| 9 const dart = dart_sdk.dart; | 10 const dart = dart_sdk.dart; |
| 10 const dartx = dart.dartx; | 11 const dartx = dart.dartx; |
| 11 | 12 |
| 12 | 13 |
| 13 suite('generic', () => { | 14 suite('generic', () => { |
| 14 "use strict"; | 15 "use strict"; |
| 15 | 16 |
| 16 let generic = dart.generic; | 17 let generic = dart.generic; |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 204 | 205 |
| 205 let cls7 = dart.fn((b, s, o) => { return null; }, | 206 let cls7 = dart.fn((b, s, o) => { return null; }, |
| 206 dart.definiteFunctionType(B, [B, String], [Object])); | 207 dart.definiteFunctionType(B, [B, String], [Object])); |
| 207 | 208 |
| 208 let cls8 = | 209 let cls8 = |
| 209 dart.fn((b, s, o) => { return null; }, | 210 dart.fn((b, s, o) => { return null; }, |
| 210 dart.definiteFunctionType(B, [B, String], {p: Object})); | 211 dart.definiteFunctionType(B, [B, String], {p: Object})); |
| 211 | 212 |
| 212 function checkType(x, type, expectedTrue, strongOnly) { | 213 function checkType(x, type, expectedTrue, strongOnly) { |
| 213 if (expectedTrue === undefined) expectedTrue = true; | 214 if (expectedTrue === undefined) expectedTrue = true; |
| 214 if (strongOnly == undefined) strongOnly = false; | 215 if (strongOnly === undefined) strongOnly = false; |
| 215 if (!strongOnly) { | 216 if (!strongOnly) { |
| 216 assert.doesNotThrow(() => instanceOf(x, type)); | 217 assert.doesNotThrow(() => instanceOf(x, type)); |
| 217 expect(instanceOf(x, type), expectedTrue); | 218 expect(instanceOf(x, type), expectedTrue, |
| 219 '"' + x + '" ' + | |
| 220 (expectedTrue ? 'should' : 'should not') + | |
| 221 ' be an instance of "' + dart.typeName(type) + '"'); | |
| 218 } else { | 222 } else { |
| 219 assert.throws(() => instanceOf(x, type), dart.StrongModeError); | 223 assert.throws(() => instanceOf(x, type), dart.StrongModeError); |
| 220 expect(expectedTrue, false); | 224 expect(expectedTrue, false); |
| 221 expect(strongInstanceOf(x, type), null); | 225 expect(strongInstanceOf(x, type), null); |
| 222 } | 226 } |
| 223 } | 227 } |
| 224 | 228 |
| 225 test('int', () => { | 229 test('int', () => { |
| 226 expect(isGroundType(int), true); | 230 expect(isGroundType(int), true); |
| 227 expect(isGroundType(getReifiedType(5)), true); | 231 expect(isGroundType(getReifiedType(5)), true); |
| (...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 794 | 798 |
| 795 let functionType = dart.functionType; | 799 let functionType = dart.functionType; |
| 796 let definiteFunctionType = dart.definiteFunctionType; | 800 let definiteFunctionType = dart.definiteFunctionType; |
| 797 let typedef = dart.typedef; | 801 let typedef = dart.typedef; |
| 798 let isSubtype = dart.isSubtype; | 802 let isSubtype = dart.isSubtype; |
| 799 let int = core.int; | 803 let int = core.int; |
| 800 let num = core.num; | 804 let num = core.num; |
| 801 let dyn = dart.dynamic; | 805 let dyn = dart.dynamic; |
| 802 | 806 |
| 803 function always(t1, t2) { | 807 function always(t1, t2) { |
| 804 assert.equal(isSubtype(t1, t2), true); | 808 assert.equal(isSubtype(t1, t2), true, |
| 809 dart.toString(t1) + | |
| 810 " should always be a subtype of " + | |
| 811 dart.toString(t2)); | |
| 805 } | 812 } |
| 806 function never(t1, t2) { | 813 function never(t1, t2) { |
| 807 assert.equal(isSubtype(t1, t2), false); | 814 assert.equal(isSubtype(t1, t2), false, |
| 815 dart.toString(t1) + | |
| 816 " should never be a subtype of " + | |
| 817 dart.toString(t2)); | |
| 808 } | 818 } |
| 809 function maybe(t1, t2) { | 819 function maybe(t1, t2) { |
| 810 assert.equal(isSubtype(t1, t2), null); | 820 assert.equal(isSubtype(t1, t2), null, |
| 821 dart.toString(t1) + | |
| 822 " should maybe be a subtype of " + | |
| 823 dart.toString(t2)); | |
| 811 } | 824 } |
| 812 | 825 |
| 813 function always2(t1, t2) { | 826 function always2(t1, t2) { |
| 814 assert.equal(isSubtype(t1, t2), true); | 827 always(t1, t2); |
| 815 always(functionType(t1, [t2]), functionType(t2, [t1])); | 828 always(functionType(t1, [t2]), functionType(t2, [t1])); |
| 816 } | 829 } |
| 817 function never2(t1, t2) { | 830 function never2(t1, t2) { |
| 818 assert.equal(isSubtype(t1, t2), false); | 831 never(t1, t2); |
| 819 maybe(functionType(t1, [t2]), functionType(t2, [t1])); | 832 maybe(functionType(t1, [t2]), functionType(t2, [t1])); |
| 820 } | 833 } |
| 821 function maybe2(t1, t2) { | 834 function maybe2(t1, t2) { |
| 822 assert.equal(isSubtype(t1, t2), null); | 835 maybe(t1, t2); |
| 823 maybe(functionType(t1, [t2]), functionType(t2, [t1])); | 836 maybe(functionType(t1, [t2]), functionType(t2, [t1])); |
| 824 } | 837 } |
| 825 | 838 |
| 826 function run_test(func1, func2, func2opt, func1extra, func2extra) { | 839 function run_test(func1, func2, func2opt, func1extra, func2extra) { |
| 827 always2(func2(int, int), func2(int, int)); | 840 always2(func2(int, int), func2(int, int)); |
| 828 always2(func2(int, num), func2(int, int)); | 841 always2(func2(int, num), func2(int, int)); |
| 829 always2(func2(int, int), func2(num, int)); | 842 always2(func2(int, int), func2(num, int)); |
| 830 | 843 |
| 831 always2(func2opt(int, int), func2opt(int, int)); | 844 always2(func2opt(int, int), func2opt(int, int)); |
| 832 always2(func2opt(int, num), func2opt(int, int)); | 845 always2(func2opt(int, num), func2opt(int, int)); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 912 return functionType(S, [], {extra: int}); | 925 return functionType(S, [], {extra: int}); |
| 913 } | 926 } |
| 914 | 927 |
| 915 function func2extra(S, T) { | 928 function func2extra(S, T) { |
| 916 return functionType(S, [T], {extra: int}); | 929 return functionType(S, [T], {extra: int}); |
| 917 } | 930 } |
| 918 | 931 |
| 919 run_test(func1, func2, func2opt, func1extra, func2extra); | 932 run_test(func1, func2, func2opt, func1extra, func2extra); |
| 920 }); | 933 }); |
| 921 | 934 |
| 935 test('top and bottom types', () => { | |
| 936 let FutureOr = async.FutureOr$; | |
| 937 let tops = [ | |
| 938 dart.dynamic, | |
| 939 core.Object, | |
| 940 dart.void, | |
| 941 FutureOr(dart.dynamic), | |
| 942 FutureOr(core.Object), | |
| 943 FutureOr(dart.void), | |
| 944 FutureOr(FutureOr(core.Object)), | |
| 945 // ... skip the (infinite) rest of the top types :D | |
|
Leaf
2017/02/06 21:11:59
Probably for the best...
| |
| 946 ]; | |
| 947 let bottoms = [dart.bottom, core.Null]; | |
| 948 | |
| 949 for (let top of tops) { | |
| 950 for (let bottom of bottoms) { | |
| 951 always(bottom, top); | |
| 952 always( | |
| 953 definiteFunctionType(bottom, [top]), | |
| 954 definiteFunctionType(top, [bottom])); | |
| 955 } | |
| 956 } | |
| 957 | |
| 958 for (let equalTypes of [tops, bottoms]) { | |
| 959 for (let t1 of equalTypes) { | |
| 960 for (let t2 of equalTypes) { | |
| 961 always(t1, t2); | |
| 962 always(t2, t1); | |
| 963 | |
| 964 let t11 = definiteFunctionType(t1, [t1]); | |
| 965 let t22 = definiteFunctionType(t2, [t2]); | |
| 966 always(t11, t22); | |
| 967 always(t22, t11); | |
| 968 } | |
| 969 } | |
| 970 } | |
| 971 }); | |
| 972 | |
| 922 test('basic typedefs', () => { | 973 test('basic typedefs', () => { |
| 923 function func1(S) { | 974 function func1(S) { |
| 924 return dart.typedef('Func1', () => functionType(S, [])) | 975 return dart.typedef('Func1', () => functionType(S, [])) |
| 925 } | 976 } |
| 926 | 977 |
| 927 function func2(S, T) { | 978 function func2(S, T) { |
| 928 return dart.typedef('Func2', () => functionType(S, [T])) | 979 return dart.typedef('Func2', () => functionType(S, [T])) |
| 929 } | 980 } |
| 930 | 981 |
| 931 function func2opt(S, T) { | 982 function func2opt(S, T) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 968 always(functionType(int, [], [int]), functionType(dyn, [], [dyn])); | 1019 always(functionType(int, [], [int]), functionType(dyn, [], [dyn])); |
| 969 always(functionType(int, [], [int]), functionType(dyn, [dyn])); | 1020 always(functionType(int, [], [int]), functionType(dyn, [dyn])); |
| 970 always(functionType(int, [], [int]), functionType(dyn, [])); | 1021 always(functionType(int, [], [int]), functionType(dyn, [])); |
| 971 always(functionType(int, [int], {extra: int}), functionType(dyn, [dyn])); | 1022 always(functionType(int, [int], {extra: int}), functionType(dyn, [dyn])); |
| 972 | 1023 |
| 973 always(functionType(dyn, [dyn]), functionType(dyn, [dyn])); | 1024 always(functionType(dyn, [dyn]), functionType(dyn, [dyn])); |
| 974 always(functionType(dyn, [], [dyn]), functionType(dyn, [], [dyn])); | 1025 always(functionType(dyn, [], [dyn]), functionType(dyn, [], [dyn])); |
| 975 always(functionType(dyn, [], [dyn]), functionType(dyn, [dyn])); | 1026 always(functionType(dyn, [], [dyn]), functionType(dyn, [dyn])); |
| 976 always(functionType(dyn, [], [dyn]), functionType(dyn, [])); | 1027 always(functionType(dyn, [], [dyn]), functionType(dyn, [])); |
| 977 always(functionType(dyn, [dyn], {extra: dyn}), functionType(dyn, [dyn])); | 1028 always(functionType(dyn, [dyn], {extra: dyn}), functionType(dyn, [dyn])); |
| 978 | |
| 979 }); | 1029 }); |
| 980 | 1030 |
| 981 test('void function types', () => { | 1031 test('void function types', () => { |
| 982 always(functionType(int, [int]), functionType(dart.void, [dyn])); | 1032 always(functionType(int, [int]), functionType(dart.void, [dyn])); |
| 983 always(functionType(int, [], [int]), functionType(dart.void, [], [dyn])); | 1033 always(functionType(int, [], [int]), functionType(dart.void, [], [dyn])); |
| 984 always(functionType(int, [], [int]), functionType(dart.void, [dyn])); | 1034 always(functionType(int, [], [int]), functionType(dart.void, [dyn])); |
| 985 always(functionType(int, [], [int]), functionType(dart.void, [])); | 1035 always(functionType(int, [], [int]), functionType(dart.void, [])); |
| 986 always(functionType(int, [int], {extra: int}), functionType(dart.void, [dy n])); | 1036 always(functionType(int, [int], {extra: int}), functionType(dart.void, [dy n])); |
| 987 | 1037 |
| 988 always(functionType(dart.void, [int]), functionType(dart.void, [dyn])); | 1038 always(functionType(dart.void, [int]), functionType(dart.void, [dyn])); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 1002 always(functionType(dart.void, [], [dyn]), functionType(dart.void, [dyn])) ; | 1052 always(functionType(dart.void, [], [dyn]), functionType(dart.void, [dyn])) ; |
| 1003 always(functionType(dart.void, [], [dyn]), functionType(dart.void, [])); | 1053 always(functionType(dart.void, [], [dyn]), functionType(dart.void, [])); |
| 1004 always(functionType(dart.void, [dyn], {extra: dyn}), functionType(dart.voi d, [dyn])); | 1054 always(functionType(dart.void, [dyn], {extra: dyn}), functionType(dart.voi d, [dyn])); |
| 1005 | 1055 |
| 1006 always(functionType(dart.void, [int]), functionType(dyn, [dyn])); | 1056 always(functionType(dart.void, [int]), functionType(dyn, [dyn])); |
| 1007 always(functionType(dart.void, [], [int]), functionType(dyn, [], [dyn])); | 1057 always(functionType(dart.void, [], [int]), functionType(dyn, [], [dyn])); |
| 1008 always(functionType(dart.void, [], [int]), functionType(dyn, [dyn])); | 1058 always(functionType(dart.void, [], [int]), functionType(dyn, [dyn])); |
| 1009 always(functionType(dart.void, [], [int]), functionType(dyn, [])); | 1059 always(functionType(dart.void, [], [int]), functionType(dyn, [])); |
| 1010 always(functionType(dart.void, [int], {extra: int}), functionType(dyn, [dy n])); | 1060 always(functionType(dart.void, [int], {extra: int}), functionType(dyn, [dy n])); |
| 1011 | 1061 |
| 1012 never(functionType(dart.void, [int]), functionType(int, [dyn])); | 1062 maybe(functionType(dart.void, [int]), functionType(int, [dyn])); |
|
Leaf
2017/02/06 21:11:59
I'm worried about these changes, this could break
| |
| 1013 never(functionType(dart.void, [], [int]), functionType(int, [], [dyn])); | 1063 maybe(functionType(dart.void, [], [int]), functionType(int, [], [dyn])); |
| 1014 never(functionType(dart.void, [], [int]), functionType(int, [dyn])); | 1064 maybe(functionType(dart.void, [], [int]), functionType(int, [dyn])); |
| 1015 never(functionType(dart.void, [], [int]), functionType(int, [])); | 1065 maybe(functionType(dart.void, [], [int]), functionType(int, [])); |
| 1016 never(functionType(dart.void, [int], {extra: int}), functionType(int, [dyn ])); | 1066 maybe(functionType(dart.void, [int], {extra: int}), functionType(int, [dyn ])); |
| 1017 | 1067 |
| 1018 never(functionType(dart.void, [int]), functionType(int, [int])); | 1068 maybe(functionType(dart.void, [int]), functionType(int, [int])); |
| 1019 never(functionType(dart.void, [], [int]), functionType(int, [], [int])); | 1069 maybe(functionType(dart.void, [], [int]), functionType(int, [], [int])); |
| 1020 never(functionType(dart.void, [], [int]), functionType(int, [int])); | 1070 maybe(functionType(dart.void, [], [int]), functionType(int, [int])); |
| 1021 never(functionType(dart.void, [], [int]), functionType(int, [])); | 1071 maybe(functionType(dart.void, [], [int]), functionType(int, [])); |
| 1022 never(functionType(dart.void, [int], {extra: int}), functionType(int, [int ])); | 1072 maybe(functionType(dart.void, [int], {extra: int}), functionType(int, [int ])); |
| 1023 | |
| 1024 }); | 1073 }); |
| 1025 | 1074 |
| 1026 test('higher-order typedef', () => { | 1075 test('higher-order typedef', () => { |
| 1027 let Func$ = dart.generic((S, T) => | 1076 let Func$ = dart.generic((S, T) => |
| 1028 dart.typedef('Func', () => | 1077 dart.typedef('Func', () => |
| 1029 functionType(T, [S]))); | 1078 functionType(T, [S]))); |
| 1030 let Func2$ = dart.generic((R, S, T) => | 1079 let Func2$ = dart.generic((R, S, T) => |
| 1031 dart.typedef('Func2', () => | 1080 dart.typedef('Func2', () => |
| 1032 functionType(T, [Func$(R, S)]))); | 1081 functionType(T, [Func$(R, S)]))); |
| 1033 | 1082 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 1053 never(AA$(core.Object), AA$(int)); | 1102 never(AA$(core.Object), AA$(int)); |
| 1054 | 1103 |
| 1055 always(AA$(functionType(int, [int])), AA$(dyn)); | 1104 always(AA$(functionType(int, [int])), AA$(dyn)); |
| 1056 maybe(AA$(dyn), AA$(functionType(int, [int]))); | 1105 maybe(AA$(dyn), AA$(functionType(int, [int]))); |
| 1057 never(AA$(core.Object), AA$(functionType(int, [int]))); | 1106 never(AA$(core.Object), AA$(functionType(int, [int]))); |
| 1058 | 1107 |
| 1059 always(AA$(functionType(int, [int])), AA$(functionType(dyn, [dyn]))); | 1108 always(AA$(functionType(int, [int])), AA$(functionType(dyn, [dyn]))); |
| 1060 maybe(AA$(functionType(dyn, [dyn])), AA$(functionType(int, [int]))); | 1109 maybe(AA$(functionType(dyn, [dyn])), AA$(functionType(int, [int]))); |
| 1061 maybe(AA$(functionType(core.Object, [core.Object])), | 1110 maybe(AA$(functionType(core.Object, [core.Object])), |
| 1062 AA$(functionType(int, [int]))); | 1111 AA$(functionType(int, [int]))); |
| 1063 | |
| 1064 | |
| 1065 }); | 1112 }); |
| 1066 | |
| 1067 }); | 1113 }); |
| 1068 | 1114 |
| 1069 suite('canonicalization', function() { | 1115 suite('canonicalization', function() { |
| 1070 'use strict'; | 1116 'use strict'; |
| 1071 let functionType = dart.functionType; | 1117 let functionType = dart.functionType; |
| 1072 let definiteFunctionType = dart.definiteFunctionType; | 1118 let definiteFunctionType = dart.definiteFunctionType; |
| 1073 let typedef = dart.typedef; | 1119 let typedef = dart.typedef; |
| 1074 let generic = dart.generic; | 1120 let generic = dart.generic; |
| 1075 | 1121 |
| 1076 let Object = core.Object; | 1122 let Object = core.Object; |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1177 list[0] = 42; | 1223 list[0] = 42; |
| 1178 assert.throws(() => list.add(42)); | 1224 assert.throws(() => list.add(42)); |
| 1179 }); | 1225 }); |
| 1180 | 1226 |
| 1181 test('toString on ES Symbol', () => { | 1227 test('toString on ES Symbol', () => { |
| 1182 let sym = Symbol('_foobar'); | 1228 let sym = Symbol('_foobar'); |
| 1183 assert.equal(dart.toString(sym), 'Symbol(_foobar)'); | 1229 assert.equal(dart.toString(sym), 'Symbol(_foobar)'); |
| 1184 }); | 1230 }); |
| 1185 }); | 1231 }); |
| 1186 }); | 1232 }); |
| OLD | NEW |