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

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

Issue 513023002: Step one towards stable error messages with details: (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 3 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 /// Tests for some of the utility helper functions used by the compiler.
6 library polymer.test.build.messages_test;
7
8 import 'package:unittest/unittest.dart';
9 import 'package:code_transformers/messages/messages.dart';
10 import 'package:source_span/source_span.dart';
11
12 main() {
13 group('snippet', () {
14 test('template with no-args works', () {
15 expect(new MessageTemplate(_id('code_transformers', 1),
16 'this message has no args', '', '').snippet,
17 'this message has no args');
18 });
19
20 test('template with args throws', () {
21 expect(() => new MessageTemplate(_id('code_transformers', 1),
22 'this message has %-args-%', '', '')
23 .snippet,
24 throws);
25 });
26
27 test('can pass arguments to create snippet', () {
28 expect(new MessageTemplate(_id('code_transformers', 1),
29 'a %-b-% c something %-name-% too', '', '')
30 .create({'b': "1", 'name': 'foo'}).snippet,
31 'a 1 c something foo too');
32 });
33 });
34
35 test('equals', () {
36 expect(new MessageId('hi', 23) == new MessageId('hi', 23), isTrue);
37 expect(new MessageId('foo', 23) != new MessageId('bar', 23), isTrue);
38 expect(new MessageId('foo', 22) != new MessageId('foo', 23), isTrue);
39 });
40
41 group('serialize/deserialize', () {
42 test('message id', () {
43 _eq(msg) {
44 expect(new MessageId.fromJson(msg.toJson()) == msg, isTrue);
45 }
46 _eq(const MessageId('hi', 23));
47 _eq(new MessageId('hi', 23));
48 _eq(new MessageId('a_b', 23));
49 _eq(new MessageId('a-b', 23));
50 _eq(new MessageId('a-b-', 3));
51 _eq(new MessageId('a', 21));
52 });
53
54 test('message', () {
55 _eq(msg) {
56 var parsed = new Message.fromJson(msg.toJson());
57 expect(msg.id, parsed.id);
58 expect(msg.snippet, parsed.snippet);
59 }
60 _eq(new Message(_id('hi', 33), 'snippet here'));
61 _eq(new MessageTemplate(_id('hi', 33), 'snippet', 'ignored', 'ignored'));
62 });
63
64 test('log entry', () {
65 _eq(entry) {
66 var parsed = new BuildLogEntry.fromJson(entry.toJson());
67 expect(entry.message.id, parsed.message.id);
68 expect(entry.message.snippet, entry.message.snippet);
69 expect(entry.level, parsed.level);
70 expect(entry.span, parsed.span);
71 }
72 _eq(_entry(33, 'hi there', 12));
73 _eq(_entry(33, 'hi there-', 11));
74 });
75
76 test('log entry table', () {
77 var table = new LogEntryTable();
78 table.add(_entry(11, 'hi there', 23));
79 table.add(_entry(13, 'hi there', 21));
80 table.add(_entry(11, 'hi there', 26));
81 expect(table.entries.length, 2);
82 expect(table.entries[_id('hi', 11)].length, 2);
83 expect(table.entries[_id('hi', 13)].length, 1);
84
85 var table2 = new LogEntryTable.fromJson(table.toJson());
86 expect(table2.entries.length, 2);
87 expect(table2.entries[_id('hi', 11)].length, 2);
88 expect(table2.entries[_id('hi', 13)].length, 1);
89 expect(table2.entries[_id('hi', 11)][0].span.start.offset,
90 table.entries[_id('hi', 11)][0].span.start.offset);
91 expect(table2.entries[_id('hi', 11)][1].span.start.offset,
92 table.entries[_id('hi', 11)][1].span.start.offset);
93 expect(table2.entries[_id('hi', 13)][0].span.start.offset,
94 table.entries[_id('hi', 13)][0].span.start.offset);
95 });
96 });
97 }
98 _id(s, i) => new MessageId(s, i);
99 _entry(id, snippet, offset) => new BuildLogEntry(
100 new Message(_id('hi', id), snippet),
101 new SourceSpan(
102 new SourceLocation(offset, sourceUrl: 'a', line: 1, column: 3),
103 new SourceLocation(offset + 2, sourceUrl: 'a', line: 1, column: 5),
104 'hi'),
105 'Warning');
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698