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

Side by Side Diff: sdk/lib/_internal/pub/test/utils_test.dart

Issue 1165473002: Start pulling pub from its own repo. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Code review changes Created 5 years, 6 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) 2012, 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 library utils_test;
6
7 import 'package:unittest/unittest.dart';
8 import 'test_pub.dart';
9 import '../lib/src/utils.dart';
10
11 main() {
12 initConfig();
13
14 group('yamlToString()', () {
15 test('null', () {
16 expect(yamlToString(null), equals('null'));
17 });
18
19 test('numbers', () {
20 expect(yamlToString(123), equals('123'));
21 expect(yamlToString(12.34), equals('12.34'));
22 });
23
24 test('does not quote strings that do not need it', () {
25 expect(yamlToString('a'), equals('a'));
26 expect(yamlToString('some-string'), equals('some-string'));
27 expect(yamlToString('hey123CAPS'), equals('hey123CAPS'));
28 expect(yamlToString("_under_score"), equals('_under_score'));
29 });
30
31 test('quotes other strings', () {
32 expect(yamlToString(''), equals('""'));
33 expect(yamlToString('123'), equals('"123"'));
34 expect(yamlToString('white space'), equals('"white space"'));
35 expect(yamlToString('"quote"'), equals(r'"\"quote\""'));
36 expect(yamlToString("apostrophe'"), equals('"apostrophe\'"'));
37 expect(yamlToString("new\nline"), equals(r'"new\nline"'));
38 expect(yamlToString("?unctu@t!on"), equals(r'"?unctu@t!on"'));
39 });
40
41 test('lists use JSON style', () {
42 expect(yamlToString([1, 2, 3]), equals('[1,2,3]'));
43 });
44
45 test('uses indentation for maps', () {
46 expect(yamlToString({'a': {'b': 1, 'c': 2}, 'd': 3}),
47 equals("""
48 a:
49 b: 1
50 c: 2
51 d: 3"""));
52 });
53
54 test('sorts map keys', () {
55 expect(yamlToString({'a': 1, 'c': 2, 'b': 3, 'd': 4}),
56 equals("""
57 a: 1
58 b: 3
59 c: 2
60 d: 4"""));
61 });
62
63 test('quotes map keys as needed', () {
64 expect(yamlToString({'no': 1, 'yes!': 2, '123': 3}),
65 equals("""
66 "123": 3
67 no: 1
68 "yes!": 2"""));
69 });
70
71 test('handles non-string map keys', () {
72 var map = new Map();
73 map[null] = "null";
74 map[123] = "num";
75 map[true] = "bool";
76
77 expect(yamlToString(map),
78 equals("""
79 123: num
80 null: null
81 true: bool"""));
82 });
83
84 test('handles empty maps', () {
85 expect(yamlToString({}), equals("{}"));
86 expect(yamlToString({'a': {}, 'b': {}}), equals("""
87 a: {}
88 b: {}"""));
89 });
90 });
91 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698