Skip to content

Commit

Permalink
add fake class
Browse files Browse the repository at this point in the history
  • Loading branch information
PlugFox committed Nov 20, 2020
1 parent 22e21b2 commit 826c30a
Show file tree
Hide file tree
Showing 5 changed files with 241 additions and 71 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ jobs:
run: dartanalyzer --fatal-infos --fatal-warnings lib example test
- name: Run tests
run: pub run test_coverage
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
- name: Check Code Coverage
uses: ChicagoFlutter/lcov-cop@v1.0.2
with:
path: coverage/lcov.info
min_coverage: 100
exclude: "**/*.g.dart"
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
exclude: "**/*.g.dart"
84 changes: 47 additions & 37 deletions lib/src/methods.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,51 +81,61 @@ mixin PlatformMethods on ExtendedHostPlatform {
PlatformResult Function() debug,
PlatformResult Function() orElse,
}) {
// Operating System
if (fuchsia != null && isFuchsia) {
return fuchsia();
} else if (windows != null && isWindows) {
return windows();
} else if (android != null && isAndroid) {
return android();
} else if (iOS != null && isIOS) {
return iOS();
} else if (macOS != null && isMacOS) {
return macOS();
} else if (linux != null && isLinux) {
return linux();
} else if (unknown != null && !isOperatingSystemKnown) {
return unknown();
{
// Operating System
if (fuchsia != null && isFuchsia) {
return fuchsia();
} else if (windows != null && isWindows) {
return windows();
} else if (android != null && isAndroid) {
return android();
} else if (iOS != null && isIOS) {
return iOS();
} else if (macOS != null && isMacOS) {
return macOS();
} else if (linux != null && isLinux) {
return linux();
} else if (unknown != null && !isOperatingSystemKnown) {
return unknown();
}
}

// Design
if (material != null && isMaterial) {
return material();
} else if (cupertino != null && isCupertino) {
return cupertino();
{
// Design
if (material != null && isMaterial) {
return material();
} else if (cupertino != null && isCupertino) {
return cupertino();
}
}

// Mobile/Desktop
if (mobile != null && isMobile) {
return mobile();
} else if (desktop != null && isDesktop) {
return desktop();
{
// Mobile/Desktop
if (mobile != null && isMobile) {
return mobile();
} else if (desktop != null && isDesktop) {
return desktop();
}
}

// IO/Web
if (io != null && isIO) {
return io();
} else if (web != null && isWeb) {
return web();
{
// IO/Web
if (io != null && isIO) {
return io();
} else if (web != null && isWeb) {
return web();
}
}

// Build mode
if (debug != null && buildMode == BuildMode.debug) {
return debug();
} else if (profile != null && buildMode == BuildMode.profile) {
return profile();
} else if (release != null && buildMode == BuildMode.release) {
return release();
{
// Build mode
if (debug != null && buildMode == BuildMode.debug) {
return debug();
} else if (profile != null && buildMode == BuildMode.profile) {
return profile();
} else if (release != null && buildMode == BuildMode.release) {
return release();
}
}

// Any callback was not called
Expand Down
95 changes: 93 additions & 2 deletions lib/src/platform.dart
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ class Platform extends ExtendedHostPlatform with PlatformMethods {
bool get isWindows => operatingSystem == OperatingSystem.windows;

@override
final BuildMode buildMode;
BuildMode get buildMode => _buildMode;
BuildMode _buildMode;

/// Host platform
/// contain info about host device
Expand Down Expand Up @@ -138,14 +139,16 @@ class Platform extends ExtendedHostPlatform with PlatformMethods {
static final Platform _this = Platform._internal();
Platform._internal()
: _hostPlatform = _getHostPlatform(),
buildMode = _getCurrentBuildMode() {
_buildMode = _getCurrentBuildMode() {
_isOperatingSystemKnown = operatingSystem != OperatingSystem.unknown;
_isMobile = kListOSForMobile.contains(operatingSystem);
_isDesktop = kListOSForDesktop.contains(operatingSystem);
_isMaterial = kListOSWithMaterialDesign.contains(operatingSystem);
_isCupertino = kListOSWithCupertinoDesign.contains(operatingSystem);
}

Platform._emptyForTest() : _hostPlatform = _getHostPlatform();

@override
int get hashCode => 0;

Expand All @@ -155,3 +158,91 @@ class Platform extends ExtendedHostPlatform with PlatformMethods {
@override
String toString() => version;
}

/// Fake platform for test
class FakePlatform extends Platform with PlatformMethods {
/// @nodoc
FakePlatform() : super._emptyForTest() {
reset();
}

@override
BuildMode buildMode;

@override
bool isAndroid;

@override
bool isCupertino;

@override
bool isDesktop;

@override
bool isFuchsia;

@override
bool isIO;

@override
bool isIOS;

@override
bool isLinux;

@override
bool isMacOS;

@override
bool isMaterial;

@override
bool isMobile;

@override
bool isOperatingSystemKnown;

@override
bool isWeb;

@override
bool isWindows;

@override
String locale;

@override
int numberOfProcessors;

@override
OperatingSystem operatingSystem;

@override
HostPlatformType type;

@override
String version;

/// @nodoc
void reset() {
buildMode = BuildMode.debug;
isFuchsia = false;
isWindows = false;
isAndroid = false;
isIOS = false;
isMacOS = false;
isLinux = true;
isMaterial = false;
isCupertino = false;
isMobile = false;
isDesktop = true;
locale = 'en';
numberOfProcessors = 1;
operatingSystem = OperatingSystem.linux;
isOperatingSystemKnown = true;
isIO = true;
isWeb = false;
type = HostPlatformType.io;
version = '1';
}
}
3 changes: 1 addition & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@ environment:

dev_dependencies:
test_coverage: ^0.4.3
test: ^1.15.3

test: ^1.15.3
Loading

1 comment on commit 826c30a

@vercel
Copy link

@vercel vercel bot commented on 826c30a Nov 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.