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

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 'dart:convert';
9 import 'package:unittest/unittest.dart';
10 import 'package:code_transformers/messages/messages.dart';
11 import 'package:source_span/source_span.dart';
12
13 main() {
14 group('snippet', () {
15 test('template with no-args works', () {
16 expect(new MessageTemplate(_id('code_transformers', 1),
17 'this message has no args', '', '').snippet,
18 'this message has no args');
19 });
20
21 test('template with args throws', () {
22 expect(() => new MessageTemplate(_id('code_transformers', 1),
23 'this message has %-args-%', '', '')
24 .snippet,
25 throws);
26 });
27
28 test('can pass arguments to create snippet', () {
29 expect(new MessageTemplate(_id('code_transformers', 1),
30 'a %-b-% c something %-name-% too', '', '')
31 .create({'b': "1", 'name': 'foo'}).snippet,
32 'a 1 c something foo too');
33 });
34 });
35
36 test('equals', () {
37 expect(new MessageId('hi', 23) == new MessageId('hi', 23), isTrue);
38 expect(new MessageId('foo', 23) != new MessageId('bar', 23), isTrue);
39 expect(new MessageId('foo', 22) != new MessageId('foo', 23), isTrue);
40 });
41
42 for (var encode in [true, false]) {
43 var toJson = encode
44 ? (o) => o.toJson()
45 : (o) => JSON.decode(JSON.encode(o));
46 group('serialize/deserialize ${encode ? "and stringify": ""}', () {
47 test('message id', () {
48 _eq(msg) {
49 expect(new MessageId.fromJson(toJson(msg)) == msg, isTrue);
50 }
51 _eq(const MessageId('hi', 23));
52 _eq(new MessageId('hi', 23));
53 _eq(new MessageId('a_b', 23));
54 _eq(new MessageId('a-b', 23));
55 _eq(new MessageId('a-b-', 3));
56 _eq(new MessageId('a', 21));
57 });
58
59 test('message', () {
60 _eq(msg) {
61 var parsed = new Message.fromJson(toJson(msg));
62 expect(msg.id, parsed.id);
63 expect(msg.snippet, parsed.snippet);
64 }
65 _eq(new Message(_id('hi', 33), 'snippet here'));
66 _eq(new MessageTemplate(_id('hi', 33), 'snippet', 'ignored', 'ignored')) ;
67 });
68
69 test('log entry', () {
70 _eq(entry) {
71 var parsed = new BuildLogEntry.fromJson(toJson(entry));
72 expect(entry.message.id, parsed.message.id);
73 expect(entry.message.snippet, entry.message.snippet);
74 expect(entry.level, parsed.level);
75 expect(entry.span, parsed.span);
76 }
77 _eq(_entry(33, 'hi there', 12));
78 _eq(_entry(33, 'hi there-', 11));
79 });
80
81 test('log entry table', () {
82 var table = new LogEntryTable();
83 table.add(_entry(11, 'hi there', 23));
84 table.add(_entry(13, 'hi there', 21));
85 table.add(_entry(11, 'hi there', 26));
86 expect(table.entries.length, 2);
87 expect(table.entries[_id('hi', 11)].length, 2);
88 expect(table.entries[_id('hi', 13)].length, 1);
89
90 var table2 = new LogEntryTable.fromJson(toJson(table));
91 expect(table2.entries.length, 2);
92 expect(table2.entries[_id('hi', 11)].length, 2);
93 expect(table2.entries[_id('hi', 13)].length, 1);
94 expect(table2.entries[_id('hi', 11)][0].span,
95 table.entries[_id('hi', 11)][0].span);
96 expect(table2.entries[_id('hi', 11)][1].span,
97 table.entries[_id('hi', 11)][1].span);
98 expect(table2.entries[_id('hi', 13)][0].span,
99 table.entries[_id('hi', 13)][0].span);
100 });
101 });
102 }
103 }
104 _id(s, i) => new MessageId(s, i);
105 _entry(id, snippet, offset) => new BuildLogEntry(
106 new Message(_id('hi', id), snippet),
107 new SourceSpan(
108 new SourceLocation(offset, sourceUrl: 'a', line: 1, column: 3),
109 new SourceLocation(offset + 2, sourceUrl: 'a', line: 1, column: 5),
110 'hi'),
111 'Warning');
OLDNEW
« no previous file with comments | « pkg/code_transformers/test/assets_test.dart ('k') | pkg/code_transformers/test/unique_message_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698