| 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 import "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
| 6 import "package:async_helper/async_helper.dart"; | 6 import "package:async_helper/async_helper.dart"; |
| 7 import 'memory_compiler.dart'; | 7 import 'memory_compiler.dart'; |
| 8 | 8 |
| 9 const MEMORY_SOURCE_FILES = const { | 9 const MEMORY_SOURCE_FILES = const { |
| 10 'main.dart': ''' | 10 'main.dart': ''' |
| 11 main() { | 11 main() { |
| 12 print(12300000); | 12 print(12300000); |
| 13 print(1234567890123456789012345); | 13 print(1234567890123456789012345); |
| 14 print(double.MAX_FINITE); | 14 print(double.MAX_FINITE); |
| 15 print(-22230000); |
| 15 }'''}; | 16 }'''}; |
| 16 | 17 |
| 17 void test({bool minify}) { | 18 void test({bool minify}) { |
| 18 OutputCollector collector = new OutputCollector(); | 19 OutputCollector collector = new OutputCollector(); |
| 19 var compiler = compilerFor(MEMORY_SOURCE_FILES, | 20 var compiler = compilerFor(MEMORY_SOURCE_FILES, |
| 20 outputProvider: collector, | 21 outputProvider: collector, |
| 21 options: minify ? ['--minify'] : []); | 22 options: minify ? ['--minify'] : []); |
| 22 asyncTest(() => compiler.run(Uri.parse('memory:main.dart')).then((_) { | 23 asyncTest(() => compiler.run(Uri.parse('memory:main.dart')).then((_) { |
| 23 // Check that we use the shorter exponential representations. | 24 // Check that we use the shorter exponential representations. |
| 24 String jsOutput = collector.getOutput('', 'js'); | 25 String jsOutput = collector.getOutput('', 'js'); |
| 26 print(jsOutput); |
| 25 | 27 |
| 26 if (minify) { | 28 if (minify) { |
| 27 Expect.isTrue(jsOutput.contains('123e5')); // Shorter than 12300000. | 29 Expect.isTrue(jsOutput.contains('123e5')); // Shorter than 12300000. |
| 28 Expect.isFalse(jsOutput.contains('12300000')); | 30 Expect.isFalse(jsOutput.contains('12300000')); |
| 31 Expect.isTrue(jsOutput.contains('-2223e4')); // Shorter than -22230000. |
| 32 Expect.isFalse(jsOutput.contains('-22230000')); |
| 29 } else { | 33 } else { |
| 30 Expect.isTrue(jsOutput.contains('12300000')); | 34 Expect.isTrue(jsOutput.contains('12300000')); |
| 35 Expect.isTrue(jsOutput.contains('-22230000')); |
| 31 } | 36 } |
| 32 Expect.isTrue(jsOutput.contains('12345678901234568e8')); | 37 Expect.isTrue(jsOutput.contains('12345678901234568e8')); |
| 33 Expect.isTrue(jsOutput.contains('17976931348623157e292')); | 38 Expect.isTrue(jsOutput.contains('17976931348623157e292')); |
| 34 Expect.isFalse(jsOutput.contains('1234567890123456789012345')); | 39 Expect.isFalse(jsOutput.contains('1234567890123456789012345')); |
| 35 // The decimal expansion of double.MAX_FINITE has 308 digits. We only check | 40 // The decimal expansion of double.MAX_FINITE has 308 digits. We only check |
| 36 // for its prefix. | 41 // for its prefix. |
| 37 Expect.isFalse(jsOutput.contains('179769313486231570814527423731')); | 42 Expect.isFalse(jsOutput.contains('179769313486231570814527423731')); |
| 38 })); | 43 })); |
| 39 } | 44 } |
| 40 | 45 |
| 41 main() { | 46 main() { |
| 42 test(minify: true); | 47 test(minify: true); |
| 43 test(minify: false); | 48 test(minify: false); |
| 44 } | 49 } |
| OLD | NEW |