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

Unified Diff: sdk/lib/_internal/pub/test/utils_test.dart

Issue 15777002: Use indentation for maps in lockfile. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Revise. Created 7 years, 7 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
Index: sdk/lib/_internal/pub/test/utils_test.dart
diff --git a/sdk/lib/_internal/pub/test/utils_test.dart b/sdk/lib/_internal/pub/test/utils_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..c1c29a811c73e894f7ef9fa3ca36525bfdf93036
--- /dev/null
+++ b/sdk/lib/_internal/pub/test/utils_test.dart
@@ -0,0 +1,84 @@
+// Copyright (c) 2012, 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.
+
+library utils_test;
+
+import 'package:unittest/unittest.dart';
+import 'test_pub.dart';
+import '../lib/src/utils.dart';
+
+main() {
+ initConfig();
+
+ group('yamlToString()', () {
+ test('null', () {
+ expect(yamlToString(null), equals('null'));
+ });
+
+ test('numbers', () {
+ expect(yamlToString(123), equals('123'));
+ expect(yamlToString(12.34), equals('12.34'));
+ });
+
+ test('does not quote strings that do not need it', () {
+ expect(yamlToString('a'), equals('a'));
+ expect(yamlToString('some-string'), equals('some-string'));
+ expect(yamlToString('hey123CAPS'), equals('hey123CAPS'));
+ expect(yamlToString("_under_score"), equals('_under_score'));
+ });
+
+ test('quotes other strings', () {
+ expect(yamlToString(''), equals('""'));
+ expect(yamlToString('123'), equals('"123"'));
+ expect(yamlToString('white space'), equals('"white space"'));
+ expect(yamlToString('"quote"'), equals(r'"\"quote\""'));
+ expect(yamlToString("apostrophe'"), equals('"apostrophe\'"'));
+ expect(yamlToString("new\nline"), equals(r'"new\nline"'));
+ expect(yamlToString("?unctu@t!on"), equals(r'"?unctu@t!on"'));
+ });
+
+ test('lists use JSON style', () {
+ expect(yamlToString([1, 2, 3]), equals('[1,2,3]'));
+ });
+
+ test('uses indentation for maps', () {
+ expect(yamlToString({'a': {'b': 1, 'c': 2}, 'd': 3}),
+ equals("""
+a:
+ b: 1
+ c: 2
+d: 3"""));
+ });
+
+ test('sorts map keys', () {
+ expect(yamlToString({'a': 1, 'c': 2, 'b': 3, 'd': 4}),
+ equals("""
+a: 1
+b: 3
+c: 2
+d: 4"""));
+ });
+
+ test('quotes map keys as needed', () {
+ expect(yamlToString({'no': 1, 'yes!': 2, '123': 3}),
+ equals("""
+"123": 3
+no: 1
+"yes!": 2"""));
+ });
+
+ test('handles non-string map keys', () {
+ var map = new Map();
+ map[null] = "null";
+ map[123] = "num";
+ map[true] = "bool";
+
+ expect(yamlToString(map),
+ equals("""
+123: num
+null: null
+true: bool"""));
+ });
+ });
+}
« sdk/lib/_internal/pub/lib/src/utils.dart ('K') | « sdk/lib/_internal/pub/test/lock_file_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698