Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 1 | // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Ralph Bergmann | c65e9d1 | 2018-05-30 16:51:25 +0200 | [diff] [blame] | 5 | import 'dart:async'; |
| 6 | |
fmatosqg | 197d431 | 2018-05-21 10:52:33 +1000 | [diff] [blame] | 7 | import 'package:file/file.dart'; |
| 8 | import 'package:file/memory.dart'; |
| 9 | import 'package:flutter_tools/src/base/file_system.dart'; |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 10 | import 'package:flutter_tools/src/cache.dart'; |
| 11 | import 'package:flutter_tools/src/flutter_manifest.dart'; |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 12 | |
| 13 | import 'src/common.dart'; |
| 14 | import 'src/context.dart'; |
Danny Tuppeny | a74f591 | 2018-09-04 17:12:24 +0100 | [diff] [blame] | 15 | import 'src/pubspec_schema.dart'; |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 16 | |
| 17 | void main() { |
| 18 | setUpAll(() { |
| 19 | Cache.flutterRoot = getFlutterRoot(); |
| 20 | }); |
| 21 | |
| 22 | group('FlutterManifest', () { |
Sarah Zakarias | 3cbbbf0 | 2017-09-26 23:14:20 +0200 | [diff] [blame] | 23 | testUsingContext('is empty when the pubspec.yaml file is empty', () async { |
Jonah Williams | 4ff4671 | 2019-04-29 08:21:32 -0700 | [diff] [blame^] | 24 | final FlutterManifest flutterManifest = FlutterManifest.createFromString(''); |
Sarah Zakarias | 3cbbbf0 | 2017-09-26 23:14:20 +0200 | [diff] [blame] | 25 | expect(flutterManifest.isEmpty, true); |
| 26 | expect(flutterManifest.appName, ''); |
| 27 | expect(flutterManifest.usesMaterialDesign, false); |
| 28 | expect(flutterManifest.fontsDescriptor, isEmpty); |
| 29 | expect(flutterManifest.fonts, isEmpty); |
| 30 | expect(flutterManifest.assets, isEmpty); |
| 31 | }); |
| 32 | |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 33 | test('has no fonts or assets when the "flutter" section is empty', () async { |
Alexandre Ardhuin | 841d5d7 | 2018-02-01 07:51:26 +0100 | [diff] [blame] | 34 | const String manifest = ''' |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 35 | name: test |
| 36 | dependencies: |
| 37 | flutter: |
| 38 | sdk: flutter |
| 39 | '''; |
Jonah Williams | 4ff4671 | 2019-04-29 08:21:32 -0700 | [diff] [blame^] | 40 | final FlutterManifest flutterManifest = FlutterManifest.createFromString(manifest); |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 41 | expect(flutterManifest, isNotNull); |
Sarah Zakarias | 3cbbbf0 | 2017-09-26 23:14:20 +0200 | [diff] [blame] | 42 | expect(flutterManifest.isEmpty, false); |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 43 | expect(flutterManifest.appName, 'test'); |
| 44 | expect(flutterManifest.usesMaterialDesign, false); |
| 45 | expect(flutterManifest.fontsDescriptor, isEmpty); |
| 46 | expect(flutterManifest.fonts, isEmpty); |
| 47 | expect(flutterManifest.assets, isEmpty); |
| 48 | }); |
| 49 | |
| 50 | test('knows if material design is used', () async { |
Alexandre Ardhuin | 841d5d7 | 2018-02-01 07:51:26 +0100 | [diff] [blame] | 51 | const String manifest = ''' |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 52 | name: test |
| 53 | dependencies: |
| 54 | flutter: |
| 55 | sdk: flutter |
| 56 | flutter: |
| 57 | uses-material-design: true |
| 58 | '''; |
Jonah Williams | 4ff4671 | 2019-04-29 08:21:32 -0700 | [diff] [blame^] | 59 | final FlutterManifest flutterManifest = FlutterManifest.createFromString(manifest); |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 60 | expect(flutterManifest.usesMaterialDesign, true); |
| 61 | }); |
| 62 | |
| 63 | test('has two assets', () async { |
Alexandre Ardhuin | 841d5d7 | 2018-02-01 07:51:26 +0100 | [diff] [blame] | 64 | const String manifest = ''' |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 65 | name: test |
| 66 | dependencies: |
| 67 | flutter: |
| 68 | sdk: flutter |
| 69 | flutter: |
| 70 | uses-material-design: true |
| 71 | assets: |
| 72 | - a/foo |
| 73 | - a/bar |
| 74 | '''; |
Jonah Williams | 4ff4671 | 2019-04-29 08:21:32 -0700 | [diff] [blame^] | 75 | final FlutterManifest flutterManifest = FlutterManifest.createFromString(manifest); |
Michael Goderbauer | 84580b5 | 2018-01-24 13:16:23 -0800 | [diff] [blame] | 76 | expect(flutterManifest.assets.length, 2); |
| 77 | expect(flutterManifest.assets[0], Uri.parse('a/foo')); |
| 78 | expect(flutterManifest.assets[1], Uri.parse('a/bar')); |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 79 | }); |
| 80 | |
| 81 | test('has one font family with one asset', () async { |
Alexandre Ardhuin | 841d5d7 | 2018-02-01 07:51:26 +0100 | [diff] [blame] | 82 | const String manifest = ''' |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 83 | name: test |
| 84 | dependencies: |
| 85 | flutter: |
| 86 | sdk: flutter |
| 87 | flutter: |
| 88 | uses-material-design: true |
| 89 | fonts: |
| 90 | - family: foo |
| 91 | fonts: |
| 92 | - asset: a/bar |
| 93 | '''; |
Jonah Williams | 4ff4671 | 2019-04-29 08:21:32 -0700 | [diff] [blame^] | 94 | final FlutterManifest flutterManifest = FlutterManifest.createFromString(manifest); |
Jason Simmons | 3581b3a | 2018-10-01 14:14:48 -0700 | [diff] [blame] | 95 | final dynamic expectedFontsDescriptor = [{'fonts': [{'asset': 'a/bar'}], 'family': 'foo'}]; // ignore: always_specify_types |
| 96 | expect(flutterManifest.fontsDescriptor, expectedFontsDescriptor); |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 97 | final List<Font> fonts = flutterManifest.fonts; |
| 98 | expect(fonts.length, 1); |
| 99 | final Font font = fonts[0]; |
Jason Simmons | 3581b3a | 2018-10-01 14:14:48 -0700 | [diff] [blame] | 100 | final dynamic fooFontDescriptor = {'family': 'foo', 'fonts': [{'asset': 'a/bar'}]}; // ignore: always_specify_types |
| 101 | expect(font.descriptor, fooFontDescriptor); |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 102 | expect(font.familyName, 'foo'); |
| 103 | final List<FontAsset> assets = font.fontAssets; |
| 104 | expect(assets.length, 1); |
| 105 | final FontAsset fontAsset = assets[0]; |
Michael Goderbauer | 84580b5 | 2018-01-24 13:16:23 -0800 | [diff] [blame] | 106 | expect(fontAsset.assetUri.path, 'a/bar'); |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 107 | expect(fontAsset.weight, isNull); |
| 108 | expect(fontAsset.style, isNull); |
| 109 | }); |
| 110 | |
| 111 | test('has one font family with a simple asset and one with weight', () async { |
Alexandre Ardhuin | 841d5d7 | 2018-02-01 07:51:26 +0100 | [diff] [blame] | 112 | const String manifest = ''' |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 113 | name: test |
| 114 | dependencies: |
| 115 | flutter: |
| 116 | sdk: flutter |
| 117 | flutter: |
| 118 | uses-material-design: true |
| 119 | fonts: |
| 120 | - family: foo |
| 121 | fonts: |
| 122 | - asset: a/bar |
| 123 | - asset: a/bar |
| 124 | weight: 400 |
| 125 | '''; |
Jonah Williams | 4ff4671 | 2019-04-29 08:21:32 -0700 | [diff] [blame^] | 126 | final FlutterManifest flutterManifest = FlutterManifest.createFromString(manifest); |
Jason Simmons | 3581b3a | 2018-10-01 14:14:48 -0700 | [diff] [blame] | 127 | final dynamic expectedFontsDescriptor = [{'fonts': [{'asset': 'a/bar'}, {'weight': 400, 'asset': 'a/bar'}], 'family': 'foo'}]; // ignore: always_specify_types |
| 128 | expect(flutterManifest.fontsDescriptor, expectedFontsDescriptor); |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 129 | final List<Font> fonts = flutterManifest.fonts; |
| 130 | expect(fonts.length, 1); |
| 131 | final Font font = fonts[0]; |
Jason Simmons | 3581b3a | 2018-10-01 14:14:48 -0700 | [diff] [blame] | 132 | final dynamic fooFontDescriptor = {'family': 'foo', 'fonts': [{'asset': 'a/bar'}, {'weight': 400, 'asset': 'a/bar'}]}; // ignore: always_specify_types |
| 133 | expect(font.descriptor, fooFontDescriptor); |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 134 | expect(font.familyName, 'foo'); |
| 135 | final List<FontAsset> assets = font.fontAssets; |
| 136 | expect(assets.length, 2); |
| 137 | final FontAsset fontAsset0 = assets[0]; |
Michael Goderbauer | 84580b5 | 2018-01-24 13:16:23 -0800 | [diff] [blame] | 138 | expect(fontAsset0.assetUri.path, 'a/bar'); |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 139 | expect(fontAsset0.weight, isNull); |
| 140 | expect(fontAsset0.style, isNull); |
| 141 | final FontAsset fontAsset1 = assets[1]; |
Michael Goderbauer | 84580b5 | 2018-01-24 13:16:23 -0800 | [diff] [blame] | 142 | expect(fontAsset1.assetUri.path, 'a/bar'); |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 143 | expect(fontAsset1.weight, 400); |
| 144 | expect(fontAsset1.style, isNull); |
| 145 | }); |
| 146 | |
| 147 | test('has one font family with a simple asset and one with weight and style', () async { |
Alexandre Ardhuin | 841d5d7 | 2018-02-01 07:51:26 +0100 | [diff] [blame] | 148 | const String manifest = ''' |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 149 | name: test |
| 150 | dependencies: |
| 151 | flutter: |
| 152 | sdk: flutter |
| 153 | flutter: |
| 154 | uses-material-design: true |
| 155 | fonts: |
| 156 | - family: foo |
| 157 | fonts: |
| 158 | - asset: a/bar |
| 159 | - asset: a/bar |
| 160 | weight: 400 |
| 161 | style: italic |
| 162 | '''; |
Jonah Williams | 4ff4671 | 2019-04-29 08:21:32 -0700 | [diff] [blame^] | 163 | final FlutterManifest flutterManifest = FlutterManifest.createFromString(manifest); |
Jason Simmons | 3581b3a | 2018-10-01 14:14:48 -0700 | [diff] [blame] | 164 | final dynamic expectedFontsDescriptor = [{'fonts': [{'asset': 'a/bar'}, {'style': 'italic', 'weight': 400, 'asset': 'a/bar'}], 'family': 'foo'}]; // ignore: always_specify_types |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 165 | |
Jason Simmons | 3581b3a | 2018-10-01 14:14:48 -0700 | [diff] [blame] | 166 | expect(flutterManifest.fontsDescriptor, expectedFontsDescriptor); |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 167 | final List<Font> fonts = flutterManifest.fonts; |
| 168 | expect(fonts.length, 1); |
| 169 | final Font font = fonts[0]; |
Jason Simmons | 3581b3a | 2018-10-01 14:14:48 -0700 | [diff] [blame] | 170 | final dynamic fooFontDescriptor = {'family': 'foo', 'fonts': [{'asset': 'a/bar'}, {'weight': 400, 'style': 'italic', 'asset': 'a/bar'}]}; // ignore: always_specify_types |
| 171 | expect(font.descriptor, fooFontDescriptor); |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 172 | expect(font.familyName, 'foo'); |
| 173 | final List<FontAsset> assets = font.fontAssets; |
| 174 | expect(assets.length, 2); |
| 175 | final FontAsset fontAsset0 = assets[0]; |
Michael Goderbauer | 84580b5 | 2018-01-24 13:16:23 -0800 | [diff] [blame] | 176 | expect(fontAsset0.assetUri.path, 'a/bar'); |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 177 | expect(fontAsset0.weight, isNull); |
| 178 | expect(fontAsset0.style, isNull); |
| 179 | final FontAsset fontAsset1 = assets[1]; |
Michael Goderbauer | 84580b5 | 2018-01-24 13:16:23 -0800 | [diff] [blame] | 180 | expect(fontAsset1.assetUri.path, 'a/bar'); |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 181 | expect(fontAsset1.weight, 400); |
| 182 | expect(fontAsset1.style, 'italic'); |
| 183 | }); |
| 184 | |
| 185 | test('has two font families, each with one simple asset and one with weight and style', () async { |
Alexandre Ardhuin | 841d5d7 | 2018-02-01 07:51:26 +0100 | [diff] [blame] | 186 | const String manifest = ''' |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 187 | name: test |
| 188 | dependencies: |
| 189 | flutter: |
| 190 | sdk: flutter |
| 191 | flutter: |
| 192 | uses-material-design: true |
| 193 | fonts: |
| 194 | - family: foo |
| 195 | fonts: |
| 196 | - asset: a/bar |
| 197 | - asset: a/bar |
| 198 | weight: 400 |
| 199 | style: italic |
| 200 | - family: bar |
| 201 | fonts: |
| 202 | - asset: a/baz |
| 203 | - weight: 400 |
| 204 | asset: a/baz |
| 205 | style: italic |
| 206 | '''; |
Jonah Williams | 4ff4671 | 2019-04-29 08:21:32 -0700 | [diff] [blame^] | 207 | final FlutterManifest flutterManifest = FlutterManifest.createFromString(manifest); |
Jason Simmons | 3581b3a | 2018-10-01 14:14:48 -0700 | [diff] [blame] | 208 | final dynamic expectedFontsDescriptor = <dynamic>[ |
| 209 | {'fonts': [{'asset': 'a/bar'}, {'style': 'italic', 'weight': 400, 'asset': 'a/bar'}], 'family': 'foo'}, // ignore: always_specify_types |
| 210 | {'fonts': [{'asset': 'a/baz'}, {'style': 'italic', 'weight': 400, 'asset': 'a/baz'}], 'family': 'bar'}, // ignore: always_specify_types |
| 211 | ]; |
| 212 | expect(flutterManifest.fontsDescriptor, expectedFontsDescriptor); |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 213 | final List<Font> fonts = flutterManifest.fonts; |
| 214 | expect(fonts.length, 2); |
| 215 | |
| 216 | final Font fooFont = fonts[0]; |
Jason Simmons | 3581b3a | 2018-10-01 14:14:48 -0700 | [diff] [blame] | 217 | final dynamic fooFontDescriptor = {'family': 'foo', 'fonts': [{'asset': 'a/bar'}, {'weight': 400, 'style': 'italic', 'asset': 'a/bar'}]}; // ignore: always_specify_types |
| 218 | expect(fooFont.descriptor, fooFontDescriptor); |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 219 | expect(fooFont.familyName, 'foo'); |
| 220 | final List<FontAsset> fooAassets = fooFont.fontAssets; |
| 221 | expect(fooAassets.length, 2); |
| 222 | final FontAsset fooFontAsset0 = fooAassets[0]; |
Michael Goderbauer | 84580b5 | 2018-01-24 13:16:23 -0800 | [diff] [blame] | 223 | expect(fooFontAsset0.assetUri.path, 'a/bar'); |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 224 | expect(fooFontAsset0.weight, isNull); |
| 225 | expect(fooFontAsset0.style, isNull); |
| 226 | final FontAsset fooFontAsset1 = fooAassets[1]; |
Michael Goderbauer | 84580b5 | 2018-01-24 13:16:23 -0800 | [diff] [blame] | 227 | expect(fooFontAsset1.assetUri.path, 'a/bar'); |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 228 | expect(fooFontAsset1.weight, 400); |
| 229 | expect(fooFontAsset1.style, 'italic'); |
| 230 | |
| 231 | final Font barFont = fonts[1]; |
Jason Simmons | 3581b3a | 2018-10-01 14:14:48 -0700 | [diff] [blame] | 232 | const String fontDescriptor = '{family: bar, fonts: [{asset: a/baz}, {weight: 400, style: italic, asset: a/baz}]}'; // ignore: always_specify_types |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 233 | expect(barFont.descriptor.toString(), fontDescriptor); |
| 234 | expect(barFont.familyName, 'bar'); |
| 235 | final List<FontAsset> barAssets = barFont.fontAssets; |
| 236 | expect(barAssets.length, 2); |
| 237 | final FontAsset barFontAsset0 = barAssets[0]; |
Michael Goderbauer | 84580b5 | 2018-01-24 13:16:23 -0800 | [diff] [blame] | 238 | expect(barFontAsset0.assetUri.path, 'a/baz'); |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 239 | expect(barFontAsset0.weight, isNull); |
| 240 | expect(barFontAsset0.style, isNull); |
| 241 | final FontAsset barFontAsset1 = barAssets[1]; |
Michael Goderbauer | 84580b5 | 2018-01-24 13:16:23 -0800 | [diff] [blame] | 242 | expect(barFontAsset1.assetUri.path, 'a/baz'); |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 243 | expect(barFontAsset1.weight, 400); |
| 244 | expect(barFontAsset1.style, 'italic'); |
| 245 | }); |
| 246 | |
Josh Soref | c5a5945 | 2018-03-07 00:36:03 -0500 | [diff] [blame] | 247 | testUsingContext('has only one of two font families when one declaration is missing the "family" option', () async { |
Alexandre Ardhuin | 841d5d7 | 2018-02-01 07:51:26 +0100 | [diff] [blame] | 248 | const String manifest = ''' |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 249 | name: test |
| 250 | dependencies: |
| 251 | flutter: |
| 252 | sdk: flutter |
| 253 | flutter: |
| 254 | uses-material-design: true |
| 255 | fonts: |
| 256 | - family: foo |
| 257 | fonts: |
| 258 | - asset: a/bar |
| 259 | - asset: a/bar |
| 260 | weight: 400 |
| 261 | style: italic |
| 262 | - fonts: |
| 263 | - asset: a/baz |
| 264 | - asset: a/baz |
| 265 | weight: 400 |
| 266 | style: italic |
| 267 | '''; |
Jonah Williams | 4ff4671 | 2019-04-29 08:21:32 -0700 | [diff] [blame^] | 268 | final FlutterManifest flutterManifest = FlutterManifest.createFromString(manifest); |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 269 | |
Jason Simmons | 3581b3a | 2018-10-01 14:14:48 -0700 | [diff] [blame] | 270 | final dynamic expectedFontsDescriptor = [{'fonts': [{'asset': 'a/bar'}, {'style': 'italic', 'weight': 400, 'asset': 'a/bar'}], 'family': 'foo'}]; // ignore: always_specify_types |
| 271 | expect(flutterManifest.fontsDescriptor, expectedFontsDescriptor); |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 272 | final List<Font> fonts = flutterManifest.fonts; |
| 273 | expect(fonts.length, 1); |
| 274 | final Font fooFont = fonts[0]; |
Jason Simmons | 3581b3a | 2018-10-01 14:14:48 -0700 | [diff] [blame] | 275 | final dynamic fooFontDescriptor = {'family': 'foo', 'fonts': [{'asset': 'a/bar'}, {'weight': 400, 'style': 'italic', 'asset': 'a/bar'}]}; // ignore: always_specify_types |
| 276 | expect(fooFont.descriptor, fooFontDescriptor); |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 277 | expect(fooFont.familyName, 'foo'); |
| 278 | final List<FontAsset> fooAassets = fooFont.fontAssets; |
| 279 | expect(fooAassets.length, 2); |
| 280 | final FontAsset fooFontAsset0 = fooAassets[0]; |
Michael Goderbauer | 84580b5 | 2018-01-24 13:16:23 -0800 | [diff] [blame] | 281 | expect(fooFontAsset0.assetUri.path, 'a/bar'); |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 282 | expect(fooFontAsset0.weight, isNull); |
| 283 | expect(fooFontAsset0.style, isNull); |
| 284 | final FontAsset fooFontAsset1 = fooAassets[1]; |
Michael Goderbauer | 84580b5 | 2018-01-24 13:16:23 -0800 | [diff] [blame] | 285 | expect(fooFontAsset1.assetUri.path, 'a/bar'); |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 286 | expect(fooFontAsset1.weight, 400); |
| 287 | expect(fooFontAsset1.style, 'italic'); |
| 288 | }); |
| 289 | |
Josh Soref | c5a5945 | 2018-03-07 00:36:03 -0500 | [diff] [blame] | 290 | testUsingContext('has only one of two font families when one declaration is missing the "fonts" option', () async { |
Alexandre Ardhuin | 841d5d7 | 2018-02-01 07:51:26 +0100 | [diff] [blame] | 291 | const String manifest = ''' |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 292 | name: test |
| 293 | dependencies: |
| 294 | flutter: |
| 295 | sdk: flutter |
| 296 | flutter: |
| 297 | uses-material-design: true |
| 298 | fonts: |
| 299 | - family: foo |
| 300 | fonts: |
| 301 | - asset: a/bar |
| 302 | - asset: a/bar |
| 303 | weight: 400 |
| 304 | style: italic |
| 305 | - family: bar |
| 306 | '''; |
Jonah Williams | 4ff4671 | 2019-04-29 08:21:32 -0700 | [diff] [blame^] | 307 | final FlutterManifest flutterManifest = FlutterManifest.createFromString(manifest); |
Jason Simmons | 3581b3a | 2018-10-01 14:14:48 -0700 | [diff] [blame] | 308 | final dynamic expectedFontsDescriptor = [{'fonts': [{'asset': 'a/bar'}, {'style': 'italic', 'weight': 400, 'asset': 'a/bar'}], 'family': 'foo'}]; // ignore: always_specify_types |
| 309 | expect(flutterManifest.fontsDescriptor, expectedFontsDescriptor); |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 310 | final List<Font> fonts = flutterManifest.fonts; |
| 311 | expect(fonts.length, 1); |
| 312 | final Font fooFont = fonts[0]; |
Jason Simmons | 3581b3a | 2018-10-01 14:14:48 -0700 | [diff] [blame] | 313 | final dynamic fooFontDescriptor = {'family': 'foo', 'fonts': [{'asset': 'a/bar'}, {'weight': 400, 'style': 'italic', 'asset': 'a/bar'}]}; // ignore: always_specify_types |
| 314 | expect(fooFont.descriptor, fooFontDescriptor); |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 315 | expect(fooFont.familyName, 'foo'); |
| 316 | final List<FontAsset> fooAassets = fooFont.fontAssets; |
| 317 | expect(fooAassets.length, 2); |
| 318 | final FontAsset fooFontAsset0 = fooAassets[0]; |
Michael Goderbauer | 84580b5 | 2018-01-24 13:16:23 -0800 | [diff] [blame] | 319 | expect(fooFontAsset0.assetUri.path, 'a/bar'); |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 320 | expect(fooFontAsset0.weight, isNull); |
| 321 | expect(fooFontAsset0.style, isNull); |
| 322 | final FontAsset fooFontAsset1 = fooAassets[1]; |
Michael Goderbauer | 84580b5 | 2018-01-24 13:16:23 -0800 | [diff] [blame] | 323 | expect(fooFontAsset1.assetUri.path, 'a/bar'); |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 324 | expect(fooFontAsset1.weight, 400); |
| 325 | expect(fooFontAsset1.style, 'italic'); |
| 326 | }); |
| 327 | |
| 328 | testUsingContext('has no font family when declaration is missing the "asset" option', () async { |
Alexandre Ardhuin | 841d5d7 | 2018-02-01 07:51:26 +0100 | [diff] [blame] | 329 | const String manifest = ''' |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 330 | name: test |
| 331 | dependencies: |
| 332 | flutter: |
| 333 | sdk: flutter |
| 334 | flutter: |
| 335 | uses-material-design: true |
| 336 | fonts: |
| 337 | - family: foo |
| 338 | fonts: |
| 339 | - weight: 400 |
| 340 | '''; |
Jonah Williams | 4ff4671 | 2019-04-29 08:21:32 -0700 | [diff] [blame^] | 341 | final FlutterManifest flutterManifest = FlutterManifest.createFromString(manifest); |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 342 | |
Jason Simmons | 3581b3a | 2018-10-01 14:14:48 -0700 | [diff] [blame] | 343 | expect(flutterManifest.fontsDescriptor, <dynamic>[]); |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 344 | final List<Font> fonts = flutterManifest.fonts; |
| 345 | expect(fonts.length, 0); |
| 346 | }); |
Victor Choueiri | 7edd5c8 | 2018-03-19 23:55:54 +0200 | [diff] [blame] | 347 | |
| 348 | test('allows a blank flutter section', () async { |
| 349 | const String manifest = ''' |
| 350 | name: test |
| 351 | dependencies: |
| 352 | flutter: |
| 353 | sdk: flutter |
| 354 | flutter: |
| 355 | '''; |
Jonah Williams | 4ff4671 | 2019-04-29 08:21:32 -0700 | [diff] [blame^] | 356 | final FlutterManifest flutterManifest = FlutterManifest.createFromString(manifest); |
Victor Choueiri | 7edd5c8 | 2018-03-19 23:55:54 +0200 | [diff] [blame] | 357 | expect(flutterManifest.isEmpty, false); |
Greg Spencer | 0ff9e8a | 2018-10-10 11:01:40 -0700 | [diff] [blame] | 358 | expect(flutterManifest.isModule, false); |
Mikkel Nygaard Ravn | 651c5ab | 2018-08-02 19:16:32 +0200 | [diff] [blame] | 359 | expect(flutterManifest.isPlugin, false); |
| 360 | expect(flutterManifest.androidPackage, null); |
| 361 | }); |
| 362 | |
Greg Spencer | 0ff9e8a | 2018-10-10 11:01:40 -0700 | [diff] [blame] | 363 | test('allows a module declaration', () async { |
Mikkel Nygaard Ravn | 651c5ab | 2018-08-02 19:16:32 +0200 | [diff] [blame] | 364 | const String manifest = ''' |
| 365 | name: test |
| 366 | flutter: |
Greg Spencer | 0ff9e8a | 2018-10-10 11:01:40 -0700 | [diff] [blame] | 367 | module: |
Mikkel Nygaard Ravn | 651c5ab | 2018-08-02 19:16:32 +0200 | [diff] [blame] | 368 | androidPackage: com.example |
| 369 | '''; |
Jonah Williams | 4ff4671 | 2019-04-29 08:21:32 -0700 | [diff] [blame^] | 370 | final FlutterManifest flutterManifest = FlutterManifest.createFromString(manifest); |
Greg Spencer | 0ff9e8a | 2018-10-10 11:01:40 -0700 | [diff] [blame] | 371 | expect(flutterManifest.isModule, true); |
Mikkel Nygaard Ravn | 651c5ab | 2018-08-02 19:16:32 +0200 | [diff] [blame] | 372 | expect(flutterManifest.androidPackage, 'com.example'); |
| 373 | }); |
| 374 | |
| 375 | test('allows a plugin declaration', () async { |
| 376 | const String manifest = ''' |
| 377 | name: test |
| 378 | flutter: |
| 379 | plugin: |
| 380 | androidPackage: com.example |
| 381 | '''; |
Jonah Williams | 4ff4671 | 2019-04-29 08:21:32 -0700 | [diff] [blame^] | 382 | final FlutterManifest flutterManifest = FlutterManifest.createFromString(manifest); |
Mikkel Nygaard Ravn | 651c5ab | 2018-08-02 19:16:32 +0200 | [diff] [blame] | 383 | expect(flutterManifest.isPlugin, true); |
| 384 | expect(flutterManifest.androidPackage, 'com.example'); |
Victor Choueiri | 7edd5c8 | 2018-03-19 23:55:54 +0200 | [diff] [blame] | 385 | }); |
Ralph Bergmann | c65e9d1 | 2018-05-30 16:51:25 +0200 | [diff] [blame] | 386 | |
| 387 | Future<void> checkManifestVersion({ |
| 388 | String manifest, |
| 389 | String expectedAppVersion, |
| 390 | String expectedBuildName, |
KyleWong | 4b4a9400 | 2019-02-13 23:48:03 +0800 | [diff] [blame] | 391 | String expectedBuildNumber, |
Ralph Bergmann | c65e9d1 | 2018-05-30 16:51:25 +0200 | [diff] [blame] | 392 | }) async { |
Jonah Williams | 4ff4671 | 2019-04-29 08:21:32 -0700 | [diff] [blame^] | 393 | final FlutterManifest flutterManifest = FlutterManifest.createFromString(manifest); |
Ralph Bergmann | c65e9d1 | 2018-05-30 16:51:25 +0200 | [diff] [blame] | 394 | expect(flutterManifest.appVersion, expectedAppVersion); |
| 395 | expect(flutterManifest.buildName, expectedBuildName); |
| 396 | expect(flutterManifest.buildNumber, expectedBuildNumber); |
| 397 | } |
| 398 | |
KyleWong | 4b4a9400 | 2019-02-13 23:48:03 +0800 | [diff] [blame] | 399 | test('parses major.minor.patch+build version clause 1', () async { |
Ralph Bergmann | c65e9d1 | 2018-05-30 16:51:25 +0200 | [diff] [blame] | 400 | const String manifest = ''' |
| 401 | name: test |
| 402 | version: 1.0.0+2 |
| 403 | dependencies: |
| 404 | flutter: |
| 405 | sdk: flutter |
| 406 | flutter: |
| 407 | '''; |
| 408 | await checkManifestVersion( |
| 409 | manifest: manifest, |
| 410 | expectedAppVersion: '1.0.0+2', |
| 411 | expectedBuildName: '1.0.0', |
KyleWong | 4b4a9400 | 2019-02-13 23:48:03 +0800 | [diff] [blame] | 412 | expectedBuildNumber: '2', |
| 413 | ); |
| 414 | }); |
| 415 | |
| 416 | test('parses major.minor.patch+build version clause 2', () async { |
| 417 | const String manifest = ''' |
| 418 | name: test |
| 419 | version: 1.0.0-beta+exp.sha.5114f85 |
| 420 | dependencies: |
| 421 | flutter: |
| 422 | sdk: flutter |
| 423 | flutter: |
| 424 | '''; |
| 425 | await checkManifestVersion( |
| 426 | manifest: manifest, |
| 427 | expectedAppVersion: '1.0.0-beta+exp.sha.5114f85', |
| 428 | expectedBuildName: '1.0.0-beta', |
| 429 | expectedBuildNumber: 'exp.sha.5114f85', |
Ralph Bergmann | c65e9d1 | 2018-05-30 16:51:25 +0200 | [diff] [blame] | 430 | ); |
| 431 | }); |
| 432 | |
| 433 | test('parses major.minor+build version clause', () async { |
| 434 | const String manifest = ''' |
| 435 | name: test |
| 436 | version: 1.0+2 |
| 437 | dependencies: |
| 438 | flutter: |
| 439 | sdk: flutter |
| 440 | flutter: |
| 441 | '''; |
| 442 | await checkManifestVersion( |
| 443 | manifest: manifest, |
| 444 | expectedAppVersion: '1.0+2', |
| 445 | expectedBuildName: '1.0', |
KyleWong | 4b4a9400 | 2019-02-13 23:48:03 +0800 | [diff] [blame] | 446 | expectedBuildNumber: '2', |
Ralph Bergmann | c65e9d1 | 2018-05-30 16:51:25 +0200 | [diff] [blame] | 447 | ); |
| 448 | }); |
| 449 | |
| 450 | test('parses empty version clause', () async { |
| 451 | const String manifest = ''' |
| 452 | name: test |
| 453 | version: |
| 454 | dependencies: |
| 455 | flutter: |
| 456 | sdk: flutter |
| 457 | flutter: |
| 458 | '''; |
| 459 | await checkManifestVersion( |
| 460 | manifest: manifest, |
| 461 | expectedAppVersion: null, |
| 462 | expectedBuildName: null, |
| 463 | expectedBuildNumber: null, |
| 464 | ); |
| 465 | }); |
| 466 | test('parses no version clause', () async { |
| 467 | const String manifest = ''' |
| 468 | name: test |
| 469 | dependencies: |
| 470 | flutter: |
| 471 | sdk: flutter |
| 472 | flutter: |
| 473 | '''; |
| 474 | await checkManifestVersion( |
| 475 | manifest: manifest, |
| 476 | expectedAppVersion: null, |
| 477 | expectedBuildName: null, |
| 478 | expectedBuildNumber: null, |
| 479 | ); |
| 480 | }); |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 481 | }); |
fmatosqg | 197d431 | 2018-05-21 10:52:33 +1000 | [diff] [blame] | 482 | |
| 483 | group('FlutterManifest with MemoryFileSystem', () { |
Alexandre Ardhuin | 774ca2f | 2018-09-11 07:14:04 +0200 | [diff] [blame] | 484 | Future<void> assertSchemaIsReadable() async { |
fmatosqg | 197d431 | 2018-05-21 10:52:33 +1000 | [diff] [blame] | 485 | const String manifest = ''' |
| 486 | name: test |
| 487 | dependencies: |
| 488 | flutter: |
| 489 | sdk: flutter |
| 490 | flutter: |
| 491 | '''; |
| 492 | |
Jonah Williams | 4ff4671 | 2019-04-29 08:21:32 -0700 | [diff] [blame^] | 493 | final FlutterManifest flutterManifest = FlutterManifest.createFromString(manifest); |
fmatosqg | 197d431 | 2018-05-21 10:52:33 +1000 | [diff] [blame] | 494 | expect(flutterManifest.isEmpty, false); |
| 495 | } |
| 496 | |
Alexandre Ardhuin | 5169ab5 | 2019-02-21 09:27:07 +0100 | [diff] [blame] | 497 | void testUsingContextAndFs( |
| 498 | String description, |
| 499 | FileSystem filesystem, |
| 500 | dynamic testMethod(), |
| 501 | ) { |
Alexandre Ardhuin | 440ce8f | 2019-03-07 21:09:28 +0100 | [diff] [blame] | 502 | testUsingContext( |
| 503 | description, |
| 504 | () async { |
| 505 | writeEmptySchemaFile(filesystem); |
| 506 | testMethod(); |
| 507 | }, |
| 508 | overrides: <Type, Generator>{ |
| 509 | FileSystem: () => filesystem, |
| 510 | }, |
fmatosqg | 197d431 | 2018-05-21 10:52:33 +1000 | [diff] [blame] | 511 | ); |
| 512 | } |
| 513 | |
Alexandre Ardhuin | 774ca2f | 2018-09-11 07:14:04 +0200 | [diff] [blame] | 514 | testUsingContext('Validate manifest on original fs', () { |
fmatosqg | 197d431 | 2018-05-21 10:52:33 +1000 | [diff] [blame] | 515 | assertSchemaIsReadable(); |
| 516 | }); |
| 517 | |
Alexandre Ardhuin | 440ce8f | 2019-03-07 21:09:28 +0100 | [diff] [blame] | 518 | testUsingContextAndFs( |
| 519 | 'Validate manifest on Posix FS', |
| 520 | MemoryFileSystem(style: FileSystemStyle.posix), |
| 521 | () { |
| 522 | assertSchemaIsReadable(); |
| 523 | }, |
fmatosqg | 197d431 | 2018-05-21 10:52:33 +1000 | [diff] [blame] | 524 | ); |
| 525 | |
Alexandre Ardhuin | 440ce8f | 2019-03-07 21:09:28 +0100 | [diff] [blame] | 526 | testUsingContextAndFs( |
| 527 | 'Validate manifest on Windows FS', |
| 528 | MemoryFileSystem(style: FileSystemStyle.windows), |
| 529 | () { |
| 530 | assertSchemaIsReadable(); |
| 531 | }, |
fmatosqg | 197d431 | 2018-05-21 10:52:33 +1000 | [diff] [blame] | 532 | ); |
| 533 | |
| 534 | }); |
| 535 | |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 536 | } |
fmatosqg | 197d431 | 2018-05-21 10:52:33 +1000 | [diff] [blame] | 537 | |