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

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

Issue 1400473008: Roll Observatory packages and add a roll script (Closed) Base URL: git@github.com:dart-lang/observatory_pub_packages.git@master
Patch Set: Created 5 years, 2 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) 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-%', '', '').snippet, throws);
24 });
25
26 test('can pass arguments to create snippet', () {
27 expect(new MessageTemplate(_id('code_transformers', 1),
28 'a %-b-% c something %-name-% too', '', '')
29 .create({'b': "1", 'name': 'foo'}).snippet,
30 'a 1 c something foo too');
31 });
32 });
33
34 test('equals', () {
35 expect(new MessageId('hi', 23) == new MessageId('hi', 23), isTrue);
36 expect(new MessageId('foo', 23) != new MessageId('bar', 23), isTrue);
37 expect(new MessageId('foo', 22) != new MessageId('foo', 23), isTrue);
38 });
39
40 for (var encode in [true, false]) {
41 var toJson =
42 encode ? (o) => o.toJson() : (o) => JSON.decode(JSON.encode(o));
43 group('serialize/deserialize ${encode ? "and stringify": ""}', () {
44 test('message id', () {
45 _eq(msg) {
46 expect(new MessageId.fromJson(toJson(msg)) == msg, isTrue);
47 }
48 _eq(const MessageId('hi', 23));
49 _eq(new MessageId('hi', 23));
50 _eq(new MessageId('a_b', 23));
51 _eq(new MessageId('a-b', 23));
52 _eq(new MessageId('a-b-', 3));
53 _eq(new MessageId('a', 21));
54 });
55
56 test('message', () {
57 _eq(msg) {
58 var parsed = new Message.fromJson(toJson(msg));
59 expect(msg.id, parsed.id);
60 expect(msg.snippet, parsed.snippet);
61 }
62 _eq(new Message(_id('hi', 33), 'snippet here'));
63 _eq(new MessageTemplate(
64 _id('hi', 33), 'snippet', 'ignored', 'ignored'));
65 });
66
67 test('log entry', () {
68 _eq(entry) {
69 var parsed = new BuildLogEntry.fromJson(toJson(entry));
70 expect(entry.message.id, parsed.message.id);
71 expect(entry.message.snippet, entry.message.snippet);
72 expect(entry.level, parsed.level);
73 expect(entry.span, parsed.span);
74 }
75 _eq(_entry(33, 'hi there', 12));
76 _eq(_entry(33, 'hi there-', 11));
77 });
78
79 test('log entry table', () {
80 var table = new LogEntryTable();
81 table.add(_entry(11, 'hi there', 23));
82 table.add(_entry(13, 'hi there', 21));
83 table.add(_entry(11, 'hi there', 26));
84 expect(table.entries.length, 2);
85 expect(table.entries[_id('hi', 11)].length, 2);
86 expect(table.entries[_id('hi', 13)].length, 1);
87
88 var table2 = new LogEntryTable.fromJson(toJson(table));
89 expect(table2.entries.length, 2);
90 expect(table2.entries[_id('hi', 11)].length, 2);
91 expect(table2.entries[_id('hi', 13)].length, 1);
92 expect(table2.entries[_id('hi', 11)][0].span,
93 table.entries[_id('hi', 11)][0].span);
94 expect(table2.entries[_id('hi', 11)][1].span,
95 table.entries[_id('hi', 11)][1].span);
96 expect(table2.entries[_id('hi', 13)][0].span,
97 table.entries[_id('hi', 13)][0].span);
98 });
99 });
100 }
101 }
102 _id(s, i) => new MessageId(s, i);
103 _entry(id, snippet, offset) => new BuildLogEntry(
104 new Message(_id('hi', id), snippet), new SourceSpan(
105 new SourceLocation(offset, sourceUrl: 'a', line: 1, column: 3),
106 new SourceLocation(offset + 2, sourceUrl: 'a', line: 1, column: 5),
107 'hi'), 'Warning');
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698