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

Unified 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/code_transformers/test/messages_test.dart
diff --git a/pkg/code_transformers/test/messages_test.dart b/pkg/code_transformers/test/messages_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..b03ca1c24a7ab2b4e6dc62a27848669dd9a2af66
--- /dev/null
+++ b/pkg/code_transformers/test/messages_test.dart
@@ -0,0 +1,111 @@
+// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+/// Tests for some of the utility helper functions used by the compiler.
+library polymer.test.build.messages_test;
+
+import 'dart:convert';
+import 'package:unittest/unittest.dart';
+import 'package:code_transformers/messages/messages.dart';
+import 'package:source_span/source_span.dart';
+
+main() {
+ group('snippet', () {
+ test('template with no-args works', () {
+ expect(new MessageTemplate(_id('code_transformers', 1),
+ 'this message has no args', '', '').snippet,
+ 'this message has no args');
+ });
+
+ test('template with args throws', () {
+ expect(() => new MessageTemplate(_id('code_transformers', 1),
+ 'this message has %-args-%', '', '')
+ .snippet,
+ throws);
+ });
+
+ test('can pass arguments to create snippet', () {
+ expect(new MessageTemplate(_id('code_transformers', 1),
+ 'a %-b-% c something %-name-% too', '', '')
+ .create({'b': "1", 'name': 'foo'}).snippet,
+ 'a 1 c something foo too');
+ });
+ });
+
+ test('equals', () {
+ expect(new MessageId('hi', 23) == new MessageId('hi', 23), isTrue);
+ expect(new MessageId('foo', 23) != new MessageId('bar', 23), isTrue);
+ expect(new MessageId('foo', 22) != new MessageId('foo', 23), isTrue);
+ });
+
+ for (var encode in [true, false]) {
+ var toJson = encode
+ ? (o) => o.toJson()
+ : (o) => JSON.decode(JSON.encode(o));
+ group('serialize/deserialize ${encode ? "and stringify": ""}', () {
+ test('message id', () {
+ _eq(msg) {
+ expect(new MessageId.fromJson(toJson(msg)) == msg, isTrue);
+ }
+ _eq(const MessageId('hi', 23));
+ _eq(new MessageId('hi', 23));
+ _eq(new MessageId('a_b', 23));
+ _eq(new MessageId('a-b', 23));
+ _eq(new MessageId('a-b-', 3));
+ _eq(new MessageId('a', 21));
+ });
+
+ test('message', () {
+ _eq(msg) {
+ var parsed = new Message.fromJson(toJson(msg));
+ expect(msg.id, parsed.id);
+ expect(msg.snippet, parsed.snippet);
+ }
+ _eq(new Message(_id('hi', 33), 'snippet here'));
+ _eq(new MessageTemplate(_id('hi', 33), 'snippet', 'ignored', 'ignored'));
+ });
+
+ test('log entry', () {
+ _eq(entry) {
+ var parsed = new BuildLogEntry.fromJson(toJson(entry));
+ expect(entry.message.id, parsed.message.id);
+ expect(entry.message.snippet, entry.message.snippet);
+ expect(entry.level, parsed.level);
+ expect(entry.span, parsed.span);
+ }
+ _eq(_entry(33, 'hi there', 12));
+ _eq(_entry(33, 'hi there-', 11));
+ });
+
+ test('log entry table', () {
+ var table = new LogEntryTable();
+ table.add(_entry(11, 'hi there', 23));
+ table.add(_entry(13, 'hi there', 21));
+ table.add(_entry(11, 'hi there', 26));
+ expect(table.entries.length, 2);
+ expect(table.entries[_id('hi', 11)].length, 2);
+ expect(table.entries[_id('hi', 13)].length, 1);
+
+ var table2 = new LogEntryTable.fromJson(toJson(table));
+ expect(table2.entries.length, 2);
+ expect(table2.entries[_id('hi', 11)].length, 2);
+ expect(table2.entries[_id('hi', 13)].length, 1);
+ expect(table2.entries[_id('hi', 11)][0].span,
+ table.entries[_id('hi', 11)][0].span);
+ expect(table2.entries[_id('hi', 11)][1].span,
+ table.entries[_id('hi', 11)][1].span);
+ expect(table2.entries[_id('hi', 13)][0].span,
+ table.entries[_id('hi', 13)][0].span);
+ });
+ });
+ }
+}
+_id(s, i) => new MessageId(s, i);
+_entry(id, snippet, offset) => new BuildLogEntry(
+ new Message(_id('hi', id), snippet),
+ new SourceSpan(
+ new SourceLocation(offset, sourceUrl: 'a', line: 1, column: 3),
+ new SourceLocation(offset + 2, sourceUrl: 'a', line: 1, column: 5),
+ 'hi'),
+ 'Warning');
« 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