|
| 1 | +// Copyright 2014 The Flutter 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 | + |
| 5 | +import 'package:flutter_tools_core/flutter_tools_core.dart'; |
| 6 | +import 'package:test/test.dart'; |
| 7 | + |
| 8 | +void main() { |
| 9 | + group('CleanEnvironment', () { |
| 10 | + test('serializes and deserializes correctly', () { |
| 11 | + final env = CleanEnvironment( |
| 12 | + buildDir: Uri.directory('/path/to/project/build'), |
| 13 | + projectRoot: Uri.directory('/path/to/project'), |
| 14 | + ); |
| 15 | + |
| 16 | + final Map<String, Object?> json = env.toMap(); |
| 17 | + expect(json, <String, Object?>{ |
| 18 | + 'projectRoot': 'file:///path/to/project/', |
| 19 | + 'buildDir': 'file:///path/to/project/build/', |
| 20 | + }); |
| 21 | + |
| 22 | + final deserialized = CleanEnvironment.fromJson(json); |
| 23 | + expect(deserialized, equals(env)); |
| 24 | + expect(deserialized.hashCode, equals(env.hashCode)); |
| 25 | + expect( |
| 26 | + deserialized.toString(), |
| 27 | + 'CleanEnvironment(projectRoot: file:///path/to/project/, ' |
| 28 | + 'buildDir: file:///path/to/project/build/)', |
| 29 | + ); |
| 30 | + }); |
| 31 | + |
| 32 | + test('equality respects all fields', () { |
| 33 | + final a = CleanEnvironment( |
| 34 | + buildDir: Uri.directory('/path/to/project/build'), |
| 35 | + projectRoot: Uri.directory('/path/to/project'), |
| 36 | + ); |
| 37 | + final b = CleanEnvironment( |
| 38 | + buildDir: Uri.directory('/path/to/project/build'), |
| 39 | + projectRoot: Uri.directory('/path/to/project'), |
| 40 | + ); |
| 41 | + final c = CleanEnvironment( |
| 42 | + buildDir: Uri.directory('/path/to/other/build'), |
| 43 | + projectRoot: Uri.directory('/path/to/project'), |
| 44 | + ); |
| 45 | + final d = CleanEnvironment( |
| 46 | + buildDir: Uri.directory('/path/to/project/build'), |
| 47 | + projectRoot: Uri.directory('/path/to/other'), |
| 48 | + ); |
| 49 | + |
| 50 | + expect(a, equals(b)); |
| 51 | + expect(a, isNot(equals(c))); |
| 52 | + expect(a, isNot(equals(d))); |
| 53 | + }); |
| 54 | + |
| 55 | + test('throws FormatException on missing or relative paths', () { |
| 56 | + expect(() => CleanEnvironment.fromJson(const <String, Object?>{}), throwsFormatException); |
| 57 | + expect( |
| 58 | + () => |
| 59 | + CleanEnvironment.fromJson(const <String, Object?>{'projectRoot': 'file:///only/root'}), |
| 60 | + throwsFormatException, |
| 61 | + ); |
| 62 | + expect( |
| 63 | + () => CleanEnvironment.fromJson(const <String, Object?>{ |
| 64 | + 'projectRoot': 'relative/path', |
| 65 | + 'buildDir': 'file:///path/to/project/build/', |
| 66 | + }), |
| 67 | + throwsFormatException, |
| 68 | + ); |
| 69 | + expect( |
| 70 | + () => CleanEnvironment.fromJson(const <String, Object?>{ |
| 71 | + 'projectRoot': 'file:///path/to/project/', |
| 72 | + 'buildDir': 'relative/build', |
| 73 | + }), |
| 74 | + throwsFormatException, |
| 75 | + ); |
| 76 | + expect( |
| 77 | + () => CleanEnvironment.fromJson(const <String, Object?>{ |
| 78 | + 'projectRoot': 'file:///path/to/project/', |
| 79 | + 'buildDir': 'file:///path/to/project/build', |
| 80 | + }), |
| 81 | + throwsFormatException, |
| 82 | + ); |
| 83 | + expect( |
| 84 | + () => CleanEnvironment.fromJson(const <String, Object?>{ |
| 85 | + 'projectRoot': 'file:///path/to/project', |
| 86 | + 'buildDir': 'file:///path/to/project/build/', |
| 87 | + }), |
| 88 | + throwsFormatException, |
| 89 | + ); |
| 90 | + expect( |
| 91 | + () => CleanEnvironment.fromJson(const <String, Object?>{ |
| 92 | + 'projectRoot': 'http://example.com/dir/', |
| 93 | + 'buildDir': 'file:///path/to/project/build/', |
| 94 | + }), |
| 95 | + throwsFormatException, |
| 96 | + ); |
| 97 | + expect( |
| 98 | + () => CleanEnvironment.fromJson(const <String, Object?>{ |
| 99 | + 'projectRoot': 'file:///path/to/project/', |
| 100 | + 'buildDir': 'http://example.com/dir/', |
| 101 | + }), |
| 102 | + throwsFormatException, |
| 103 | + ); |
| 104 | + }); |
| 105 | + }); |
| 106 | +} |
0 commit comments