|
| 1 | +import 'package:pana/src/platform.dart'; |
| 2 | +import 'package:test/test.dart'; |
| 3 | + |
| 4 | +import 'pubspec_test.dart'; |
| 5 | + |
| 6 | +void main() { |
| 7 | + group('Platform', () { |
| 8 | + test('no libraries', () { |
| 9 | + Platform p = classifyPlatform([]); |
| 10 | + expect(p.hasConflict, isFalse); |
| 11 | + expect(p.worksAnywhere, isTrue); |
| 12 | + expect(p.worksEverywhere, isTrue); |
| 13 | + expect(p.worksInBrowser, isTrue); |
| 14 | + expect(p.worksInConsole, isTrue); |
| 15 | + expect(p.worksInFlutter, isTrue); |
| 16 | + }); |
| 17 | + |
| 18 | + test('unknown library', () { |
| 19 | + Platform p = classifyPlatform(['package:_unknown/_unknown.dart']); |
| 20 | + expect(p.hasConflict, isFalse); |
| 21 | + expect(p.worksAnywhere, isTrue); |
| 22 | + expect(p.worksEverywhere, isTrue); |
| 23 | + expect(p.worksInBrowser, isTrue); |
| 24 | + expect(p.worksInConsole, isTrue); |
| 25 | + expect(p.worksInFlutter, isTrue); |
| 26 | + }); |
| 27 | + |
| 28 | + test('dart:io', () { |
| 29 | + Platform p = classifyPlatform(['dart:io']); |
| 30 | + expect(p.hasConflict, isFalse); |
| 31 | + expect(p.worksAnywhere, isTrue); |
| 32 | + expect(p.worksEverywhere, isFalse); |
| 33 | + expect(p.worksInBrowser, isFalse); |
| 34 | + expect(p.worksInConsole, isTrue); |
| 35 | + expect(p.worksInFlutter, isTrue); |
| 36 | + }); |
| 37 | + |
| 38 | + test('dart:html', () { |
| 39 | + Platform p = classifyPlatform(['dart:html']); |
| 40 | + expect(p.hasConflict, isFalse); |
| 41 | + expect(p.worksAnywhere, isTrue); |
| 42 | + expect(p.worksEverywhere, isFalse); |
| 43 | + expect(p.worksInBrowser, isTrue); |
| 44 | + expect(p.worksInConsole, isFalse); |
| 45 | + expect(p.worksInFlutter, isFalse); |
| 46 | + |
| 47 | + p = classifyPlatform(['dart:svg']); |
| 48 | + expect(p.hasConflict, isFalse); |
| 49 | + expect(p.worksAnywhere, isTrue); |
| 50 | + expect(p.worksEverywhere, isFalse); |
| 51 | + expect(p.worksInBrowser, isTrue); |
| 52 | + expect(p.worksInConsole, isFalse); |
| 53 | + expect(p.worksInFlutter, isFalse); |
| 54 | + }); |
| 55 | + |
| 56 | + test('dart:ui', () { |
| 57 | + Platform p = classifyPlatform(['dart:ui']); |
| 58 | + expect(p.hasConflict, isFalse); |
| 59 | + expect(p.worksAnywhere, isTrue); |
| 60 | + expect(p.worksEverywhere, isFalse); |
| 61 | + expect(p.worksInBrowser, isFalse); |
| 62 | + expect(p.worksInConsole, isFalse); |
| 63 | + expect(p.worksInFlutter, isTrue); |
| 64 | + }); |
| 65 | + |
| 66 | + test('dart:mirrors', () { |
| 67 | + Platform p = classifyPlatform(['dart:mirrors']); |
| 68 | + expect(p.hasConflict, isFalse); |
| 69 | + expect(p.worksAnywhere, isTrue); |
| 70 | + expect(p.worksEverywhere, isFalse); |
| 71 | + expect(p.worksInBrowser, isTrue); |
| 72 | + expect(p.worksInConsole, isTrue); |
| 73 | + expect(p.worksInFlutter, isFalse); |
| 74 | + }); |
| 75 | + |
| 76 | + test('http package: both html and io', () { |
| 77 | + Platform p = classifyPlatform(['dart:html', 'dart:io']); |
| 78 | + expect(p.hasConflict, isFalse); |
| 79 | + expect(p.worksAnywhere, isTrue); |
| 80 | + expect(p.worksEverywhere, isFalse); |
| 81 | + expect(p.worksInBrowser, isTrue); |
| 82 | + expect(p.worksInConsole, isFalse); |
| 83 | + expect(p.worksInFlutter, isFalse); |
| 84 | + }); |
| 85 | + |
| 86 | + test('detect angular', () { |
| 87 | + Platform p = |
| 88 | + classifyPlatform(['dart:html', 'package:angular2/angular2.dart']); |
| 89 | + expect(p.hasConflict, isFalse); |
| 90 | + expect(p.worksAnywhere, isTrue); |
| 91 | + expect(p.worksEverywhere, isFalse); |
| 92 | + expect(p.worksInBrowser, isTrue); |
| 93 | + expect(p.worksInConsole, isFalse); |
| 94 | + expect(p.worksInFlutter, isFalse); |
| 95 | + expect(p.uses, [KnownPlatforms.angular, KnownPlatforms.browser]); |
| 96 | + }); |
| 97 | + }); |
| 98 | + |
| 99 | + group('Conflicting Platform', () { |
| 100 | + test('dart:html + dart:ui', () { |
| 101 | + Platform p = classifyPlatform(['dart:html', 'dart:ui']); |
| 102 | + expect(p.hasConflict, isTrue); |
| 103 | + expect(p.worksAnywhere, isFalse); |
| 104 | + expect(p.worksEverywhere, isFalse); |
| 105 | + expect(p.worksInBrowser, isFalse); |
| 106 | + expect(p.worksInConsole, isFalse); |
| 107 | + expect(p.worksInFlutter, isFalse); |
| 108 | + }); |
| 109 | + |
| 110 | + test('dart:mirrors + dart:ui', () { |
| 111 | + Platform p = classifyPlatform(['dart:mirrors', 'dart:ui']); |
| 112 | + expect(p.hasConflict, isTrue); |
| 113 | + expect(p.worksAnywhere, isFalse); |
| 114 | + expect(p.worksEverywhere, isFalse); |
| 115 | + expect(p.worksInBrowser, isFalse); |
| 116 | + expect(p.worksInConsole, isFalse); |
| 117 | + expect(p.worksInFlutter, isFalse); |
| 118 | + }); |
| 119 | + }); |
| 120 | + |
| 121 | + group('PlatformSummary', () { |
| 122 | + test('handles multiple libraries', () { |
| 123 | + PlatformSummary sum = classifyPlatforms(emptyPubspec, { |
| 124 | + 'package:_example/a.dart': ['dart:html'], |
| 125 | + 'package:_example/b.dart': ['dart:io'], |
| 126 | + }); |
| 127 | + expect(sum.hasConflict, isFalse); |
| 128 | + expect(sum.package.worksEverywhere, isTrue); |
| 129 | + expect(sum.libraries.length, 2); |
| 130 | + Platform pa = sum.libraries['package:_example/a.dart']; |
| 131 | + Platform pb = sum.libraries['package:_example/b.dart']; |
| 132 | + expect(pa.worksInBrowser, isTrue); |
| 133 | + expect(pa.worksInConsole, isFalse); |
| 134 | + expect(pb.worksInBrowser, isFalse); |
| 135 | + expect(pb.worksInConsole, isTrue); |
| 136 | + }); |
| 137 | + |
| 138 | + test('detects flutter in pubspec', () { |
| 139 | + PlatformSummary sum = classifyPlatforms(flutterPluginPubspec, {}); |
| 140 | + expect(sum.hasConflict, isFalse); |
| 141 | + expect(sum.package.worksInFlutter, isTrue); |
| 142 | + expect(sum.package.worksInConsole, isFalse); |
| 143 | + expect(sum.package.worksInBrowser, isFalse); |
| 144 | + }); |
| 145 | + |
| 146 | + test('detects flutter in dependencies', () { |
| 147 | + PlatformSummary sum = classifyPlatforms(flutterSdkPubspec, {}); |
| 148 | + expect(sum.hasConflict, isFalse); |
| 149 | + expect(sum.package.worksInFlutter, isTrue); |
| 150 | + expect(sum.package.worksInConsole, isFalse); |
| 151 | + expect(sum.package.worksInBrowser, isFalse); |
| 152 | + }); |
| 153 | + }); |
| 154 | + |
| 155 | + group('Conflicting PlatformSummary', () { |
| 156 | + test('Flutter package with mirrors', () { |
| 157 | + PlatformSummary sum = classifyPlatforms(flutterPluginPubspec, { |
| 158 | + 'package:_example/lib.dart': ['dart:mirrors'], |
| 159 | + }); |
| 160 | + expect(sum.hasConflict, isTrue); |
| 161 | + }); |
| 162 | + }); |
| 163 | +} |
0 commit comments