| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 library kernel.round_trip; | 4 library kernel.round_trip; |
| 5 | 5 |
| 6 import 'dart:async'; | 6 import 'dart:async'; |
| 7 import 'dart:io'; | 7 import 'dart:io'; |
| 8 import 'package:kernel/binary/ast_from_binary.dart'; | 8 import 'package:kernel/binary/ast_from_binary.dart'; |
| 9 import 'package:kernel/binary/ast_to_binary.dart'; | 9 import 'package:kernel/binary/ast_to_binary.dart'; |
| 10 import 'package:kernel/binary/loader.dart'; | 10 import 'package:kernel/binary/loader.dart'; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 /// trace shows what the serializer was doing when the output started to differ. | 46 /// trace shows what the serializer was doing when the output started to differ. |
| 47 class BinaryPrinterWithExpectedOutput extends BinaryPrinter { | 47 class BinaryPrinterWithExpectedOutput extends BinaryPrinter { |
| 48 final List<int> expectedBytes; | 48 final List<int> expectedBytes; |
| 49 int offset = 0; | 49 int offset = 0; |
| 50 | 50 |
| 51 static const int eof = -1; | 51 static const int eof = -1; |
| 52 | 52 |
| 53 BinaryPrinterWithExpectedOutput(this.expectedBytes) | 53 BinaryPrinterWithExpectedOutput(this.expectedBytes) |
| 54 : super(new IOSink(new DummyStreamConsumer())); | 54 : super(new IOSink(new DummyStreamConsumer())); |
| 55 | 55 |
| 56 | |
| 57 String show(int byte) { | 56 String show(int byte) { |
| 58 if (byte == eof) return 'EOF'; | 57 if (byte == eof) return 'EOF'; |
| 59 return '$byte (0x${byte.toRadixString(16).padLeft(2, "0")})'; | 58 return '$byte (0x${byte.toRadixString(16).padLeft(2, "0")})'; |
| 60 } | 59 } |
| 61 | 60 |
| 62 @override | 61 @override |
| 63 void writeByte(int byte) { | 62 void writeByte(int byte) { |
| 64 if (offset == expectedBytes.length || expectedBytes[offset] != byte) { | 63 if (offset == expectedBytes.length || expectedBytes[offset] != byte) { |
| 65 int expected = | 64 int expected = |
| 66 (offset >= expectedBytes.length) ? eof : expectedBytes[offset]; | 65 (offset >= expectedBytes.length) ? eof : expectedBytes[offset]; |
| 67 throw 'At offset $offset: ' | 66 throw 'At offset $offset: ' |
| 68 'Expected ${show(expected)} but found ${show(byte)}'; | 67 'Expected ${show(expected)} but found ${show(byte)}'; |
| 69 } | 68 } |
| 70 ++offset; | 69 ++offset; |
| 71 } | 70 } |
| 72 | 71 |
| 73 @override | 72 @override |
| 74 void writeBytes(List<int> bytes) { | 73 void writeBytes(List<int> bytes) { |
| 75 bytes.forEach(writeByte); | 74 bytes.forEach(writeByte); |
| 76 } | 75 } |
| 77 } | 76 } |
| OLD | NEW |