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

Side by Side Diff: packages/code_transformers/test/messages_test.dart

Issue 2989763002: Update charted to 0.4.8 and roll (Closed)
Patch Set: Removed Cutch from list of reviewers 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
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 for some of the utility helper functions used by the compiler. 5 /// Tests for some of the utility helper functions used by the compiler.
6 @TestOn('vm')
6 library polymer.test.build.messages_test; 7 library polymer.test.build.messages_test;
7 8
8 import 'dart:convert'; 9 import 'dart:convert';
9 import 'package:unittest/unittest.dart'; 10 import 'package:test/test.dart';
10 import 'package:code_transformers/messages/messages.dart'; 11 import 'package:code_transformers/messages/messages.dart';
11 import 'package:source_span/source_span.dart'; 12 import 'package:source_span/source_span.dart';
12 13
13 main() { 14 main() {
14 group('snippet', () { 15 group('snippet', () {
15 test('template with no-args works', () { 16 test('template with no-args works', () {
16 expect(new MessageTemplate(_id('code_transformers', 1), 17 expect(
17 'this message has no args', '', '').snippet, 18 new MessageTemplate(_id('code_transformers', 1),
19 'this message has no args', '', '')
20 .snippet,
18 'this message has no args'); 21 'this message has no args');
19 }); 22 });
20 23
21 test('template with args throws', () { 24 test('template with args throws', () {
22 expect(() => new MessageTemplate(_id('code_transformers', 1), 25 expect(
23 'this message has %-args-%', '', '').snippet, throws); 26 () => new MessageTemplate(_id('code_transformers', 1),
27 'this message has %-args-%', '', '')
28 .snippet,
29 throwsA(contains("missing argument args")));
24 }); 30 });
25 31
26 test('can pass arguments to create snippet', () { 32 test('can pass arguments to create snippet', () {
27 expect(new MessageTemplate(_id('code_transformers', 1), 33 expect(
28 'a %-b-% c something %-name-% too', '', '') 34 new MessageTemplate(
29 .create({'b': "1", 'name': 'foo'}).snippet, 35 _id('code_transformers', 1),
36 'a %-b-% c something %-name-% too',
37 '',
38 '').create({'b': "1", 'name': 'foo'}).snippet,
30 'a 1 c something foo too'); 39 'a 1 c something foo too');
31 }); 40 });
32 }); 41 });
33 42
34 test('equals', () { 43 test('equals', () {
35 expect(new MessageId('hi', 23) == new MessageId('hi', 23), isTrue); 44 expect(new MessageId('hi', 23) == new MessageId('hi', 23), isTrue);
36 expect(new MessageId('foo', 23) != new MessageId('bar', 23), isTrue); 45 expect(new MessageId('foo', 23) != new MessageId('bar', 23), isTrue);
37 expect(new MessageId('foo', 22) != new MessageId('foo', 23), isTrue); 46 expect(new MessageId('foo', 22) != new MessageId('foo', 23), isTrue);
38 }); 47 });
39 48
40 for (var encode in [true, false]) { 49 for (var encode in [true, false]) {
41 var toJson = 50 var toJson =
42 encode ? (o) => o.toJson() : (o) => JSON.decode(JSON.encode(o)); 51 encode ? (o) => o.toJson() : (o) => JSON.decode(JSON.encode(o));
43 group('serialize/deserialize ${encode ? "and stringify": ""}', () { 52 group('serialize/deserialize ${encode ? "and stringify": ""}', () {
44 test('message id', () { 53 test('message id', () {
45 _eq(msg) { 54 _eq(msg) {
46 expect(new MessageId.fromJson(toJson(msg)) == msg, isTrue); 55 expect(new MessageId.fromJson(toJson(msg)) == msg, isTrue);
47 } 56 }
57
48 _eq(const MessageId('hi', 23)); 58 _eq(const MessageId('hi', 23));
49 _eq(new MessageId('hi', 23)); 59 _eq(new MessageId('hi', 23));
50 _eq(new MessageId('a_b', 23)); 60 _eq(new MessageId('a_b', 23));
51 _eq(new MessageId('a-b', 23)); 61 _eq(new MessageId('a-b', 23));
52 _eq(new MessageId('a-b-', 3)); 62 _eq(new MessageId('a-b-', 3));
53 _eq(new MessageId('a', 21)); 63 _eq(new MessageId('a', 21));
54 }); 64 });
55 65
56 test('message', () { 66 test('message', () {
57 _eq(msg) { 67 _eq(msg) {
58 var parsed = new Message.fromJson(toJson(msg)); 68 var parsed = new Message.fromJson(toJson(msg));
59 expect(msg.id, parsed.id); 69 expect(msg.id, parsed.id);
60 expect(msg.snippet, parsed.snippet); 70 expect(msg.snippet, parsed.snippet);
61 } 71 }
72
62 _eq(new Message(_id('hi', 33), 'snippet here')); 73 _eq(new Message(_id('hi', 33), 'snippet here'));
63 _eq(new MessageTemplate( 74 _eq(new MessageTemplate(
64 _id('hi', 33), 'snippet', 'ignored', 'ignored')); 75 _id('hi', 33), 'snippet', 'ignored', 'ignored'));
65 }); 76 });
66 77
67 test('log entry', () { 78 test('log entry', () {
68 _eq(entry) { 79 _eq(entry) {
69 var parsed = new BuildLogEntry.fromJson(toJson(entry)); 80 var parsed = new BuildLogEntry.fromJson(toJson(entry));
70 expect(entry.message.id, parsed.message.id); 81 expect(entry.message.id, parsed.message.id);
71 expect(entry.message.snippet, entry.message.snippet); 82 expect(entry.message.snippet, entry.message.snippet);
72 expect(entry.level, parsed.level); 83 expect(entry.level, parsed.level);
73 expect(entry.span, parsed.span); 84 expect(entry.span, parsed.span);
74 } 85 }
86
75 _eq(_entry(33, 'hi there', 12)); 87 _eq(_entry(33, 'hi there', 12));
76 _eq(_entry(33, 'hi there-', 11)); 88 _eq(_entry(33, 'hi there-', 11));
77 }); 89 });
78 90
79 test('log entry table', () { 91 test('log entry table', () {
80 var table = new LogEntryTable(); 92 var table = new LogEntryTable();
81 table.add(_entry(11, 'hi there', 23)); 93 table.add(_entry(11, 'hi there', 23));
82 table.add(_entry(13, 'hi there', 21)); 94 table.add(_entry(13, 'hi there', 21));
83 table.add(_entry(11, 'hi there', 26)); 95 table.add(_entry(11, 'hi there', 26));
84 expect(table.entries.length, 2); 96 expect(table.entries.length, 2);
85 expect(table.entries[_id('hi', 11)].length, 2); 97 expect(table.entries[_id('hi', 11)].length, 2);
86 expect(table.entries[_id('hi', 13)].length, 1); 98 expect(table.entries[_id('hi', 13)].length, 1);
87 99
88 var table2 = new LogEntryTable.fromJson(toJson(table)); 100 var table2 =
101 new LogEntryTable.fromJson(toJson(table) as Map<String, Iterable>);
89 expect(table2.entries.length, 2); 102 expect(table2.entries.length, 2);
90 expect(table2.entries[_id('hi', 11)].length, 2); 103 expect(table2.entries[_id('hi', 11)].length, 2);
91 expect(table2.entries[_id('hi', 13)].length, 1); 104 expect(table2.entries[_id('hi', 13)].length, 1);
92 expect(table2.entries[_id('hi', 11)][0].span, 105 expect(table2.entries[_id('hi', 11)][0].span,
93 table.entries[_id('hi', 11)][0].span); 106 table.entries[_id('hi', 11)][0].span);
94 expect(table2.entries[_id('hi', 11)][1].span, 107 expect(table2.entries[_id('hi', 11)][1].span,
95 table.entries[_id('hi', 11)][1].span); 108 table.entries[_id('hi', 11)][1].span);
96 expect(table2.entries[_id('hi', 13)][0].span, 109 expect(table2.entries[_id('hi', 13)][0].span,
97 table.entries[_id('hi', 13)][0].span); 110 table.entries[_id('hi', 13)][0].span);
98 }); 111 });
99 }); 112 });
100 } 113 }
101 } 114 }
115
102 _id(s, i) => new MessageId(s, i); 116 _id(s, i) => new MessageId(s, i);
103 _entry(id, snippet, offset) => new BuildLogEntry( 117 _entry(id, snippet, offset) => new BuildLogEntry(
104 new Message(_id('hi', id), snippet), new SourceSpan( 118 new Message(_id('hi', id), snippet),
119 new SourceSpan(
105 new SourceLocation(offset, sourceUrl: 'a', line: 1, column: 3), 120 new SourceLocation(offset, sourceUrl: 'a', line: 1, column: 3),
106 new SourceLocation(offset + 2, sourceUrl: 'a', line: 1, column: 5), 121 new SourceLocation(offset + 2, sourceUrl: 'a', line: 1, column: 5),
107 'hi'), 'Warning'); 122 'hi'),
123 'Warning');
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698