| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 library test.src.summary.api_signature_test; | |
| 6 | |
| 7 import 'package:analyzer/src/summary/api_signature.dart'; | |
| 8 import 'package:analyzer/src/summary/format.dart'; | |
| 9 import 'package:convert/convert.dart'; | |
| 10 import 'package:crypto/crypto.dart'; | |
| 11 import 'package:test/test.dart'; | |
| 12 import 'package:test_reflective_loader/test_reflective_loader.dart'; | |
| 13 | |
| 14 main() { | |
| 15 defineReflectiveSuite(() { | |
| 16 defineReflectiveTests(ApiSignatureTest); | |
| 17 }); | |
| 18 } | |
| 19 | |
| 20 @reflectiveTest | |
| 21 class ApiSignatureTest { | |
| 22 ApiSignature sig = new ApiSignature.unversioned(); | |
| 23 | |
| 24 void checkBytes(List<int> bytes) { | |
| 25 expect(sig.getBytes_forDebug(), bytes); | |
| 26 expect(sig.toHex(), hex.encode(md5.convert(bytes).bytes)); | |
| 27 } | |
| 28 | |
| 29 String signUnlinkedCombinator(UnlinkedCombinatorBuilder combinator) { | |
| 30 ApiSignature sig = new ApiSignature(); | |
| 31 combinator.collectApiSignature(sig); | |
| 32 return sig.toHex(); | |
| 33 } | |
| 34 | |
| 35 void test_addBool() { | |
| 36 sig.addBool(true); | |
| 37 sig.addBool(true); | |
| 38 sig.addBool(false); | |
| 39 sig.addBool(true); | |
| 40 sig.addBool(false); | |
| 41 sig.addBool(false); | |
| 42 sig.addBool(true); | |
| 43 sig.addBool(false); | |
| 44 checkBytes([1, 1, 0, 1, 0, 0, 1, 0]); | |
| 45 } | |
| 46 | |
| 47 void test_addBytes() { | |
| 48 // Check that offset works correctly by adding bytes in 2 chunks. | |
| 49 sig.addBytes([1, 2, 3, 4, 5]); | |
| 50 sig.addBytes([0xff, 0xfe, 0xfd, 0xfc, 0xfb]); | |
| 51 checkBytes([1, 2, 3, 4, 5, 0xff, 0xfe, 0xfd, 0xfc, 0xfb]); | |
| 52 } | |
| 53 | |
| 54 void test_addDouble() { | |
| 55 sig.addDouble(1.0 / 3.0); | |
| 56 sig.addDouble(-1.0); | |
| 57 checkBytes([85, 85, 85, 85, 85, 85, 213, 63, 0, 0, 0, 0, 0, 0, 240, 191]); | |
| 58 } | |
| 59 | |
| 60 void test_addInt() { | |
| 61 sig.addInt(1); | |
| 62 sig.addInt(1000); | |
| 63 sig.addInt(1000000); | |
| 64 sig.addInt(1000000000); | |
| 65 checkBytes( | |
| 66 [1, 0, 0, 0, 0xe8, 3, 0, 0, 0x40, 0x42, 0xf, 0, 0, 0xca, 0x9a, 0x3b]); | |
| 67 } | |
| 68 | |
| 69 void test_addString() { | |
| 70 sig.addString('abc'); | |
| 71 sig.addString('\u00f8'); | |
| 72 checkBytes([3, 0, 0, 0, 0x61, 0x62, 0x63, 2, 0, 0, 0, 0xc3, 0xb8]); | |
| 73 } | |
| 74 | |
| 75 void test_excludesInformative() { | |
| 76 // Verify that API signatures exclude informative data by checking that two | |
| 77 // UnlinkedCombinator instances that differ only in their offset result in | |
| 78 // the same signature. | |
| 79 UnlinkedCombinatorBuilder combinator1 = | |
| 80 new UnlinkedCombinatorBuilder(shows: ['foo'], offset: 1); | |
| 81 UnlinkedCombinatorBuilder combinator2 = | |
| 82 new UnlinkedCombinatorBuilder(shows: ['foo'], offset: 2); | |
| 83 expect(signUnlinkedCombinator(combinator1), | |
| 84 signUnlinkedCombinator(combinator2)); | |
| 85 } | |
| 86 | |
| 87 void test_includesSemantic() { | |
| 88 // Verify that API signatures include semantic data by checking that two | |
| 89 // UnlinkedCombinator instances that differ only in their "shows" lists | |
| 90 // result in different signatures. | |
| 91 UnlinkedCombinatorBuilder combinator1 = | |
| 92 new UnlinkedCombinatorBuilder(shows: ['foo'], offset: 1); | |
| 93 UnlinkedCombinatorBuilder combinator2 = | |
| 94 new UnlinkedCombinatorBuilder(shows: ['bar'], offset: 1); | |
| 95 expect(signUnlinkedCombinator(combinator1), | |
| 96 isNot(signUnlinkedCombinator(combinator2))); | |
| 97 } | |
| 98 | |
| 99 void test_manyInts() { | |
| 100 // This verifies that the logic to extend the internal buffer works | |
| 101 // properly. | |
| 102 List<int> expectedResult = []; | |
| 103 for (int i = 0; i < 100000; i++) { | |
| 104 sig.addInt(i); | |
| 105 expectedResult.add(i % 0x100); | |
| 106 expectedResult.add((i ~/ 0x100) % 0x100); | |
| 107 expectedResult.add((i ~/ 0x10000) % 0x100); | |
| 108 expectedResult.add((i ~/ 0x1000000) % 0x100); | |
| 109 } | |
| 110 checkBytes(expectedResult); | |
| 111 } | |
| 112 } | |
| OLD | NEW |