Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(198)

Side by Side Diff: packages/analyzer/test/src/summary/api_signature_test.dart

Issue 2990843002: Removed fixed dependencies (Closed)
Patch Set: Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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_reflective_loader/test_reflective_loader.dart';
12 import 'package:unittest/unittest.dart';
13
14 main() {
15 groupSep = ' | ';
16 defineReflectiveTests(ApiSignatureTest);
17 }
18
19 @reflectiveTest
20 class ApiSignatureTest {
21 ApiSignature sig = new ApiSignature.unversioned();
22
23 void checkBytes(List<int> bytes) {
24 expect(sig.getBytes_forDebug(), bytes);
25 expect(sig.toHex(), hex.encode(md5.convert(bytes).bytes));
26 }
27
28 String signUnlinkedCombinator(UnlinkedCombinatorBuilder combinator) {
29 ApiSignature sig = new ApiSignature();
30 combinator.collectApiSignature(sig);
31 return sig.toHex();
32 }
33
34 void test_addBool() {
35 sig.addBool(true);
36 sig.addBool(true);
37 sig.addBool(false);
38 sig.addBool(true);
39 sig.addBool(false);
40 sig.addBool(false);
41 sig.addBool(true);
42 sig.addBool(false);
43 checkBytes([1, 1, 0, 1, 0, 0, 1, 0]);
44 }
45
46 void test_addBytes() {
47 // Check that offset works correctly by adding bytes in 2 chunks.
48 sig.addBytes([1, 2, 3, 4, 5]);
49 sig.addBytes([0xff, 0xfe, 0xfd, 0xfc, 0xfb]);
50 checkBytes([1, 2, 3, 4, 5, 0xff, 0xfe, 0xfd, 0xfc, 0xfb]);
51 }
52
53 void test_addDouble() {
54 sig.addDouble(1.0 / 3.0);
55 sig.addDouble(-1.0);
56 checkBytes([85, 85, 85, 85, 85, 85, 213, 63, 0, 0, 0, 0, 0, 0, 240, 191]);
57 }
58
59 void test_addInt() {
60 sig.addInt(1);
61 sig.addInt(1000);
62 sig.addInt(1000000);
63 sig.addInt(1000000000);
64 checkBytes(
65 [1, 0, 0, 0, 0xe8, 3, 0, 0, 0x40, 0x42, 0xf, 0, 0, 0xca, 0x9a, 0x3b]);
66 }
67
68 void test_addString() {
69 sig.addString('abc');
70 sig.addString('\u00f8');
71 checkBytes([3, 0, 0, 0, 0x61, 0x62, 0x63, 2, 0, 0, 0, 0xc3, 0xb8]);
72 }
73
74 void test_excludesInformative() {
75 // Verify that API signatures exclude informative data by checking that two
76 // UnlinkedCombinator instances that differ only in their offset result in
77 // the same signature.
78 UnlinkedCombinatorBuilder combinator1 =
79 new UnlinkedCombinatorBuilder(shows: ['foo'], offset: 1);
80 UnlinkedCombinatorBuilder combinator2 =
81 new UnlinkedCombinatorBuilder(shows: ['foo'], offset: 2);
82 expect(signUnlinkedCombinator(combinator1),
83 signUnlinkedCombinator(combinator2));
84 }
85
86 void test_includesSemantic() {
87 // Verify that API signatures include semantic data by checking that two
88 // UnlinkedCombinator instances that differ only in their "shows" lists
89 // result in different signatures.
90 UnlinkedCombinatorBuilder combinator1 =
91 new UnlinkedCombinatorBuilder(shows: ['foo'], offset: 1);
92 UnlinkedCombinatorBuilder combinator2 =
93 new UnlinkedCombinatorBuilder(shows: ['bar'], offset: 1);
94 expect(signUnlinkedCombinator(combinator1),
95 isNot(signUnlinkedCombinator(combinator2)));
96 }
97
98 void test_manyInts() {
99 // This verifies that the logic to extend the internal buffer works
100 // properly.
101 List<int> expectedResult = [];
102 for (int i = 0; i < 100000; i++) {
103 sig.addInt(i);
104 expectedResult.add(i % 0x100);
105 expectedResult.add((i ~/ 0x100) % 0x100);
106 expectedResult.add((i ~/ 0x10000) % 0x100);
107 expectedResult.add((i ~/ 0x1000000) % 0x100);
108 }
109 checkBytes(expectedResult);
110 }
111 }
OLDNEW
« no previous file with comments | « packages/analyzer/test/src/source/test_all.dart ('k') | packages/analyzer/test/src/summary/bazel_summary_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698