| 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 // Tests of operators. | 5 // Tests of operators. |
| 6 | 6 |
| 7 library operators_tests; | 7 library operators_tests; |
| 8 | 8 |
| 9 import 'js_backend_cps_ir.dart'; | 9 import 'js_backend_cps_ir.dart'; |
| 10 | 10 |
| 11 const List<TestEntry> tests = const [ | 11 const List<TestEntry> tests = const [ |
| 12 | 12 |
| 13 const TestEntry.forMethod('function(foo)', | 13 const TestEntry(r""" |
| 14 r""" | |
| 15 foo(a, b) => ((a & 0xff0000) >> 1) & b; | 14 foo(a, b) => ((a & 0xff0000) >> 1) & b; |
| 16 main() { | 15 main() { |
| 17 print(foo(123, 234)); | 16 print(foo(123, 234)); |
| 18 print(foo(0, 2)); | 17 print(foo(0, 2)); |
| 19 }""", r""" | 18 }""", r""" |
| 20 function(a, b) { | 19 function() { |
| 21 return (a & 16711680) >>> 1 & b; | 20 P.print((123 & 16711680) >>> 1 & 234); |
| 21 P.print((0 & 16711680) >>> 1 & 2); |
| 22 }"""), | 22 }"""), |
| 23 | 23 |
| 24 const TestEntry.forMethod('function(foo)', | 24 const TestEntry(r""" |
| 25 r""" | |
| 26 foo(a) => ~a; | 25 foo(a) => ~a; |
| 27 main() { | 26 main() { |
| 28 print(foo(1)); | 27 print(foo(1)); |
| 29 print(foo(10)); | 28 print(foo(10)); |
| 30 }""", r""" | 29 }""", r""" |
| 31 function(a) { | 30 function() { |
| 32 return ~a >>> 0; | 31 P.print(~1 >>> 0); |
| 32 P.print(~10 >>> 0); |
| 33 }"""), | 33 }"""), |
| 34 | 34 |
| 35 const TestEntry.forMethod('function(foo)', | 35 const TestEntry.forMethod('function(foo)', |
| 36 r""" | 36 r""" |
| 37 foo(a) => a % 13; | 37 foo(a) => a % 13; |
| 38 main() { | 38 main() { |
| 39 print(foo(5)); | 39 print(foo(5)); |
| 40 print(foo(-100)); | 40 print(foo(-100)); |
| 41 }""", r""" | 41 }""", r""" |
| 42 function(a) { | 42 function(a) { |
| 43 return C.JSInt_methods.$mod(a, 13); | 43 var result = a % 13; |
| 44 return result === 0 ? 0 : result > 0 ? result : 13 < 0 ? result - 13 : result
+ 13; |
| 44 }"""), | 45 }"""), |
| 45 | 46 |
| 46 const TestEntry.forMethod('function(foo)', | 47 const TestEntry(r""" |
| 47 r""" | |
| 48 foo(a) => a % 13; | 48 foo(a) => a % 13; |
| 49 main() { | 49 main() { |
| 50 print(foo(5)); | 50 print(foo(5)); |
| 51 print(foo(100)); | 51 print(foo(100)); |
| 52 }""", r""" | 52 }""", r""" |
| 53 function(a) { | 53 function() { |
| 54 return a % 13; | 54 P.print(5 % 13); |
| 55 P.print(100 % 13); |
| 55 }"""), | 56 }"""), |
| 56 | 57 |
| 57 const TestEntry.forMethod('function(foo)', | 58 const TestEntry(r""" |
| 58 r""" | |
| 59 foo(a) => a.remainder(13); | 59 foo(a) => a.remainder(13); |
| 60 main() { | 60 main() { |
| 61 print(foo(5)); | 61 print(foo(5)); |
| 62 print(foo(-100)); | 62 print(foo(-100)); |
| 63 }""", r""" | 63 }""", r""" |
| 64 function(a) { | 64 function() { |
| 65 return a % 13; | 65 P.print(5 % 13); |
| 66 P.print(-100 % 13); |
| 66 }"""), | 67 }"""), |
| 67 | 68 |
| 68 const TestEntry.forMethod('function(foo)', | 69 const TestEntry.forMethod('function(foo)', |
| 69 r""" | 70 r""" |
| 70 foo(a) => a ~/ 13; | 71 foo(a) => a ~/ 13; |
| 71 main() { | 72 main() { |
| 72 print(foo(5)); | 73 print(foo(5)); |
| 73 print(foo(-100)); | 74 print(foo(-100)); |
| 74 }""", r""" | 75 }""", r""" |
| 75 function(a) { | 76 function(a) { |
| 76 return C.JSInt_methods.$tdiv(a, 13); | 77 var v0; |
| 78 return (a | 0) === a && (13 | 0) === 13 ? a / 13 | 0 : J.getInterceptor$n(v0 =
a / 13).toInt$0(v0); |
| 77 }"""), | 79 }"""), |
| 78 | 80 |
| 79 const TestEntry.forMethod('function(foo)', | 81 const TestEntry(r""" |
| 80 r""" | |
| 81 foo(a) => a ~/ 13; | 82 foo(a) => a ~/ 13; |
| 82 main() { | 83 main() { |
| 83 print(foo(5)); | 84 print(foo(5)); |
| 84 print(foo(100)); | 85 print(foo(100)); |
| 85 }""", r""" | 86 }""", r""" |
| 86 function(a) { | 87 function() { |
| 87 return a / 13 | 0; | 88 P.print(5 / 13 | 0); |
| 89 P.print(100 / 13 | 0); |
| 88 }"""), | 90 }"""), |
| 89 | 91 |
| 90 const TestEntry.forMethod('function(foo)', | 92 const TestEntry.forMethod('function(foo)', |
| 91 r""" | 93 r""" |
| 92 foo(a) => a ~/ 13; | 94 foo(a) => a ~/ 13; |
| 93 main() { | 95 main() { |
| 94 print(foo(5)); | 96 print(foo(5)); |
| 95 print(foo(8000000000)); | 97 print(foo(8000000000)); |
| 96 }""", r""" | 98 }""", r""" |
| 97 function(a) { | 99 function(a) { |
| 98 return C.JSInt_methods.$tdiv(a, 13); | 100 var v0; |
| 101 return (a | 0) === a && (13 | 0) === 13 ? a / 13 | 0 : J.getInterceptor$n(v0 =
a / 13).toInt$0(v0); |
| 99 }"""), | 102 }"""), |
| 100 | 103 |
| 101 ]; | 104 ]; |
| 102 | 105 |
| 103 void main() { | 106 void main() { |
| 104 runTests(tests); | 107 runTests(tests); |
| 105 } | 108 } |
| OLD | NEW |