Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2017, 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 import 'package:front_end/src/base/libraries_spec.dart'; | |
| 6 import 'package:test/test.dart'; | |
| 7 | |
| 8 main() { | |
| 9 group('parse', () { | |
| 10 test('patches are optional in the format', () async { | |
| 11 var jsonString = ''' | |
| 12 { "none": { "libraries": {"c" : { "path": "c/main.dart" }}}} | |
| 13 '''; | |
| 14 var spec = LibrariesSpecification.parse( | |
| 15 Uri.parse('org-dartlang-custom://one/two/f.json'), jsonString); | |
|
ahe
2017/08/03 11:58:16
YAY!!! \o/ :-D
Use three slashes so "one" isn't i
Siggi Cherem (dart-lang)
2017/08/05 00:41:02
Done.
| |
| 16 expect(spec, isNotNull); | |
| 17 expect( | |
| 18 spec.specificationFor('none').libraryInfoFor('c').patches, isEmpty); | |
| 19 }); | |
| 20 | |
| 21 test('library paths are resolved from spec uri', () async { | |
| 22 var jsonString = ''' | |
| 23 { "none": { "libraries": {"c" : { "path": "c/main.dart" }}}} | |
| 24 '''; | |
| 25 | |
| 26 var spec = LibrariesSpecification.parse( | |
| 27 Uri.parse('org-dartlang-custom://one/two/f.json'), jsonString); | |
| 28 expect(spec.specificationFor('none').libraryInfoFor('c').uri, | |
| 29 Uri.parse('org-dartlang-custom://one/two/c/main.dart')); | |
| 30 }); | |
| 31 | |
| 32 test('patches paths are resolved from spec uri', () async { | |
| 33 var jsonString = ''' | |
| 34 { | |
| 35 "none": { | |
| 36 "libraries": { | |
| 37 "c" : { | |
| 38 "path": "c/main.dart", | |
| 39 "patches": [ | |
| 40 "../a/p1.dart", | |
| 41 "../a/p2.dart" | |
| 42 ] | |
| 43 } | |
| 44 } | |
| 45 } | |
| 46 } | |
| 47 '''; | |
| 48 | |
| 49 var spec = LibrariesSpecification.parse( | |
| 50 Uri.parse('org-dartlang-custom://one/two/f.json'), jsonString); | |
| 51 expect(spec.specificationFor('none').libraryInfoFor('c').patches[0], | |
| 52 Uri.parse('org-dartlang-custom://one/a/p1.dart')); | |
| 53 expect(spec.specificationFor('none').libraryInfoFor('c').patches[1], | |
| 54 Uri.parse('org-dartlang-custom://one/a/p2.dart')); | |
| 55 }); | |
| 56 | |
| 57 test('multiple targets are supported', () async { | |
| 58 var jsonString = ''' | |
| 59 { | |
| 60 "vm": { | |
| 61 "libraries": { | |
| 62 "foo" : { | |
| 63 "path": "a/main.dart", | |
| 64 "patches": [ | |
| 65 "a/p1.dart", | |
| 66 "a/p2.dart" | |
| 67 ] | |
| 68 }, | |
| 69 "bar" : { | |
| 70 "path": "b/main.dart", | |
| 71 "patches": [ | |
| 72 "b/p3.dart" | |
| 73 ] | |
| 74 } | |
| 75 } | |
| 76 }, | |
| 77 "none": { | |
| 78 "libraries": { | |
| 79 "c" : { | |
| 80 "path": "c/main.dart" | |
| 81 } | |
| 82 } | |
| 83 } | |
| 84 } | |
| 85 '''; | |
| 86 | |
| 87 var spec = LibrariesSpecification.parse( | |
| 88 Uri.parse('org-dartlang-custom://one/two/f.json'), jsonString); | |
| 89 | |
| 90 expect(spec.specificationFor('vm').libraryInfoFor('foo').uri, | |
| 91 Uri.parse('org-dartlang-custom://one/two/a/main.dart')); | |
| 92 expect(spec.specificationFor('vm').libraryInfoFor('bar').uri, | |
| 93 Uri.parse('org-dartlang-custom://one/two/b/main.dart')); | |
| 94 expect(spec.specificationFor('none').libraryInfoFor('c').uri, | |
| 95 Uri.parse('org-dartlang-custom://one/two/c/main.dart')); | |
| 96 }); | |
| 97 }); | |
| 98 | |
| 99 group('toJson', () { | |
| 100 test('serialization produces same data that was parsed', () async { | |
| 101 var jsonString = ''' | |
| 102 { | |
| 103 "vm": { | |
| 104 "libraries": { | |
| 105 "foo" : { | |
| 106 "path": "a/main.dart", | |
| 107 "patches": [ | |
| 108 "a/p1.dart", | |
| 109 "a/p2.dart" | |
| 110 ] | |
| 111 }, | |
| 112 "bar" : { | |
| 113 "path": "b/main.dart", | |
| 114 "patches": [ | |
| 115 "b/p3.dart" | |
| 116 ] | |
| 117 } | |
| 118 } | |
| 119 }, | |
| 120 "none": { | |
| 121 "libraries": { | |
| 122 "c" : { | |
| 123 "path": "c/main.dart", | |
| 124 "patches": [] | |
| 125 } | |
| 126 } | |
| 127 } | |
| 128 } | |
| 129 '''; | |
| 130 | |
| 131 var spec = LibrariesSpecification.parse( | |
| 132 Uri.parse('org-dartlang-custom://one/two/f.json'), jsonString); | |
| 133 var newJson = | |
| 134 spec.toJsonString(Uri.parse('org-dartlang-custom://one/two/g.json')); | |
| 135 expect(jsonString.replaceAll(new RegExp('\\s'), ''), newJson); | |
| 136 }); | |
| 137 | |
| 138 test('serialization can adapt to new file location', () async { | |
| 139 var jsonString = ''' | |
| 140 { | |
| 141 "vm": { | |
| 142 "libraries": { | |
| 143 "foo" : { | |
| 144 "path": "a/main.dart", | |
| 145 "patches": [ | |
| 146 "a/p1.dart", | |
| 147 "a/p2.dart" | |
| 148 ] | |
| 149 }, | |
| 150 "bar" : { | |
| 151 "path": "b/main.dart", | |
| 152 "patches": [ | |
| 153 "b/p3.dart" | |
| 154 ] | |
| 155 } | |
| 156 } | |
| 157 }, | |
| 158 "none": { | |
| 159 "libraries": { | |
| 160 "c" : { | |
| 161 "path": "c/main.dart" | |
| 162 } | |
| 163 } | |
| 164 } | |
| 165 } | |
| 166 '''; | |
| 167 | |
| 168 var spec = LibrariesSpecification.parse( | |
| 169 Uri.parse('org-dartlang-custom://one/two/f.json'), jsonString); | |
| 170 var newJson = | |
| 171 spec.toJsonString(Uri.parse('org-dartlang-custom://one/g.json')); | |
| 172 | |
| 173 var expected = ''' | |
| 174 { | |
| 175 "vm": { | |
| 176 "libraries": { | |
| 177 "foo" : { | |
| 178 "path": "two/a/main.dart", | |
| 179 "patches": [ | |
| 180 "two/a/p1.dart", | |
| 181 "two/a/p2.dart" | |
| 182 ] | |
| 183 }, | |
| 184 "bar" : { | |
| 185 "path": "two/b/main.dart", | |
| 186 "patches": [ | |
| 187 "two/b/p3.dart" | |
| 188 ] | |
| 189 } | |
| 190 } | |
| 191 }, | |
| 192 "none": { | |
| 193 "libraries": { | |
| 194 "c" : { | |
| 195 "path": "two/c/main.dart", | |
| 196 "patches": [] | |
| 197 } | |
| 198 } | |
| 199 } | |
| 200 } | |
| 201 '''; | |
| 202 | |
| 203 expect(expected.replaceAll(new RegExp('\\s'), ''), newJson); | |
| 204 }); | |
| 205 }); | |
| 206 } | |
| OLD | NEW |