OLD | NEW |
(Empty) | |
| 1 dart_library.library('language/statement_test', null, /* Imports */[ |
| 2 'dart_sdk', |
| 3 'expect' |
| 4 ], function load__statement_test(exports, dart_sdk, expect) { |
| 5 'use strict'; |
| 6 const core = dart_sdk.core; |
| 7 const _interceptors = dart_sdk._interceptors; |
| 8 const dart = dart_sdk.dart; |
| 9 const dartx = dart_sdk.dartx; |
| 10 const expect$ = expect.expect; |
| 11 const statement_test = Object.create(null); |
| 12 let JSArrayOfString = () => (JSArrayOfString = dart.constFn(_interceptors.JSAr
ray$(core.String)))(); |
| 13 let JSArrayOfint = () => (JSArrayOfint = dart.constFn(_interceptors.JSArray$(c
ore.int)))(); |
| 14 let ListOfint = () => (ListOfint = dart.constFn(core.List$(core.int)))(); |
| 15 let JSArrayOfListOfint = () => (JSArrayOfListOfint = dart.constFn(_interceptor
s.JSArray$(ListOfint())))(); |
| 16 let VoidToint = () => (VoidToint = dart.constFn(dart.definiteFunctionType(core
.int, [])))(); |
| 17 let VoidTodynamic = () => (VoidTodynamic = dart.constFn(dart.definiteFunctionT
ype(dart.dynamic, [])))(); |
| 18 statement_test.StatementTest = class StatementTest extends core.Object { |
| 19 new() { |
| 20 } |
| 21 static testMain() { |
| 22 let test = new statement_test.StatementTest(); |
| 23 test.testIfStatement(); |
| 24 test.testForLoop(); |
| 25 test.testWhileLoops(); |
| 26 test.testSwitch(); |
| 27 test.testExceptions(); |
| 28 test.testBreak(); |
| 29 test.testContinue(); |
| 30 test.testFunction(); |
| 31 test.testReturn(); |
| 32 } |
| 33 testIfStatement() { |
| 34 if (true) { |
| 35 expect$.Expect.equals(true, true); |
| 36 } else { |
| 37 expect$.Expect.equals(false, true); |
| 38 } |
| 39 if (false) { |
| 40 expect$.Expect.equals(false, true); |
| 41 } else { |
| 42 expect$.Expect.equals(true, true); |
| 43 } |
| 44 } |
| 45 testForLoop() { |
| 46 let count = 0, count2 = null; |
| 47 for (let i = 0; i < 10; ++i) { |
| 48 count = dart.notNull(count) + 1; |
| 49 } |
| 50 expect$.Expect.equals(10, count); |
| 51 count2 = 0; |
| 52 for (count = 0; dart.notNull(count) < 5; count = dart.notNull(count) + 1)
{ |
| 53 count2 = dart.notNull(count2) + 1; |
| 54 } |
| 55 expect$.Expect.equals(5, count); |
| 56 expect$.Expect.equals(5, count2); |
| 57 count = count2 = 0; |
| 58 for (; dart.notNull(count) < 10; count = dart.notNull(count) + 1) { |
| 59 count2 = dart.notNull(count2) + 1; |
| 60 } |
| 61 expect$.Expect.equals(10, count); |
| 62 expect$.Expect.equals(10, count2); |
| 63 for (count = 0; dart.notNull(count) < 5;) { |
| 64 count = dart.notNull(count) + 1; |
| 65 } |
| 66 expect$.Expect.equals(5, count); |
| 67 for (count = 0;; count = dart.notNull(count) + 1) { |
| 68 if (count == 10) { |
| 69 break; |
| 70 } |
| 71 } |
| 72 expect$.Expect.equals(10, count); |
| 73 count = 0; |
| 74 for (;;) { |
| 75 if (count == 5) { |
| 76 break; |
| 77 } |
| 78 count = dart.notNull(count) + 1; |
| 79 } |
| 80 expect$.Expect.equals(5, count); |
| 81 } |
| 82 testWhileLoops() { |
| 83 let count = 0; |
| 84 while (count < 10) { |
| 85 ++count; |
| 86 } |
| 87 expect$.Expect.equals(10, count); |
| 88 count = 0; |
| 89 do { |
| 90 ++count; |
| 91 } while (count < 5); |
| 92 expect$.Expect.equals(5, count); |
| 93 } |
| 94 testSwitch() { |
| 95 let hit0 = null, hit1 = null, hitDefault = null; |
| 96 for (let x = 0; x < 3; ++x) { |
| 97 switch (x) { |
| 98 case 0: |
| 99 { |
| 100 hit0 = true; |
| 101 break; |
| 102 } |
| 103 case 1: |
| 104 { |
| 105 hit1 = true; |
| 106 break; |
| 107 } |
| 108 default: |
| 109 { |
| 110 hitDefault = true; |
| 111 break; |
| 112 } |
| 113 } |
| 114 } |
| 115 expect$.Expect.equals(true, hit0); |
| 116 expect$.Expect.equals(true, hit1); |
| 117 expect$.Expect.equals(true, hitDefault); |
| 118 let strings = JSArrayOfString().of(['a', 'b', 'c']); |
| 119 let hitA = null, hitB = null; |
| 120 hitDefault = false; |
| 121 for (let x = 0; x < 3; ++x) { |
| 122 switch (strings[dartx.get](x)) { |
| 123 case 'a': |
| 124 { |
| 125 hitA = true; |
| 126 break; |
| 127 } |
| 128 case 'b': |
| 129 { |
| 130 hitB = true; |
| 131 break; |
| 132 } |
| 133 default: |
| 134 { |
| 135 hitDefault = true; |
| 136 break; |
| 137 } |
| 138 } |
| 139 } |
| 140 expect$.Expect.equals(true, hitA); |
| 141 expect$.Expect.equals(true, hitB); |
| 142 expect$.Expect.equals(true, hitDefault); |
| 143 } |
| 144 testExceptions() { |
| 145 let hitCatch = null, hitFinally = null; |
| 146 try { |
| 147 dart.throw("foo"); |
| 148 } catch (e) { |
| 149 expect$.Expect.equals(true, dart.equals(e, "foo")); |
| 150 hitCatch = true; |
| 151 } |
| 152 finally { |
| 153 hitFinally = true; |
| 154 } |
| 155 expect$.Expect.equals(true, hitCatch); |
| 156 expect$.Expect.equals(true, hitFinally); |
| 157 } |
| 158 testBreak() { |
| 159 let ints = JSArrayOfListOfint().of([JSArrayOfint().of([32, 87, 3, 589]), J
SArrayOfint().of([12, 1076, 2000, 8]), JSArrayOfint().of([622, 127, 77, 955])]); |
| 160 let i = null, j = 0; |
| 161 let foundIt = false; |
| 162 search: |
| 163 for (i = 0; dart.notNull(i) < dart.notNull(ints[dartx.length]); i = dart
.notNull(i) + 1) { |
| 164 for (j = 0; j < dart.notNull(ints[dartx.get](i)[dartx.length]); j++) { |
| 165 if (ints[dartx.get](i)[dartx.get](j) == 12) { |
| 166 foundIt = true; |
| 167 break search; |
| 168 } |
| 169 } |
| 170 } |
| 171 expect$.Expect.equals(true, foundIt); |
| 172 } |
| 173 testContinue() { |
| 174 let searchMe = "Look for a substring in me"; |
| 175 let substring = "sub"; |
| 176 let foundIt = false; |
| 177 let max = dart.notNull(searchMe[dartx.length]) - dart.notNull(substring[da
rtx.length]); |
| 178 test: |
| 179 for (let i = 0; i <= max; i++) { |
| 180 let n = substring[dartx.length]; |
| 181 let j = i; |
| 182 let k = 0; |
| 183 while ((() => { |
| 184 let x = n; |
| 185 n = dart.notNull(x) - 1; |
| 186 return x; |
| 187 })() != 0) { |
| 188 if (searchMe[dartx.get](j++) != substring[dartx.get](k++)) { |
| 189 continue test; |
| 190 } |
| 191 } |
| 192 foundIt = true; |
| 193 break test; |
| 194 } |
| 195 } |
| 196 testFunction() { |
| 197 function foo() { |
| 198 return 42; |
| 199 } |
| 200 dart.fn(foo, VoidToint()); |
| 201 expect$.Expect.equals(42, foo()); |
| 202 } |
| 203 testReturn() { |
| 204 if (true) { |
| 205 return; |
| 206 } |
| 207 expect$.Expect.equals(true, false); |
| 208 } |
| 209 }; |
| 210 dart.setSignature(statement_test.StatementTest, { |
| 211 constructors: () => ({new: dart.definiteFunctionType(statement_test.Statemen
tTest, [])}), |
| 212 methods: () => ({ |
| 213 testIfStatement: dart.definiteFunctionType(dart.dynamic, []), |
| 214 testForLoop: dart.definiteFunctionType(dart.dynamic, []), |
| 215 testWhileLoops: dart.definiteFunctionType(dart.dynamic, []), |
| 216 testSwitch: dart.definiteFunctionType(dart.dynamic, []), |
| 217 testExceptions: dart.definiteFunctionType(dart.dynamic, []), |
| 218 testBreak: dart.definiteFunctionType(dart.dynamic, []), |
| 219 testContinue: dart.definiteFunctionType(dart.dynamic, []), |
| 220 testFunction: dart.definiteFunctionType(dart.dynamic, []), |
| 221 testReturn: dart.definiteFunctionType(dart.void, []) |
| 222 }), |
| 223 statics: () => ({testMain: dart.definiteFunctionType(dart.dynamic, [])}), |
| 224 names: ['testMain'] |
| 225 }); |
| 226 statement_test.main = function() { |
| 227 statement_test.StatementTest.testMain(); |
| 228 }; |
| 229 dart.fn(statement_test.main, VoidTodynamic()); |
| 230 // Exports: |
| 231 exports.statement_test = statement_test; |
| 232 }); |
OLD | NEW |