LCOV - code coverage report
Current view: top level - path-1.8.0/lib/src/style - posix.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 11 22 50.0 %
Date: 2021-11-28 14:37:50 Functions: 0 0 -

          Line data    Source code
       1             : // Copyright (c) 2013, 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 '../characters.dart' as chars;
       6             : import '../internal_style.dart';
       7             : import '../parsed_path.dart';
       8             : 
       9             : /// The style for POSIX paths.
      10             : class PosixStyle extends InternalStyle {
      11          11 :   PosixStyle();
      12             : 
      13             :   @override
      14             :   final name = 'posix';
      15             :   @override
      16             :   final separator = '/';
      17             :   final separators = const ['/'];
      18             : 
      19             :   // Deprecated properties.
      20             : 
      21             :   @override
      22             :   final separatorPattern = RegExp(r'/');
      23             :   @override
      24             :   final needsSeparatorPattern = RegExp(r'[^/]$');
      25             :   @override
      26             :   final rootPattern = RegExp(r'^/');
      27             :   @override
      28             :   final relativeRootPattern = null;
      29             : 
      30           0 :   @override
      31           0 :   bool containsSeparator(String path) => path.contains('/');
      32             : 
      33          11 :   @override
      34          11 :   bool isSeparator(int codeUnit) => codeUnit == chars.slash;
      35             : 
      36          11 :   @override
      37             :   bool needsSeparator(String path) =>
      38          55 :       path.isNotEmpty && !isSeparator(path.codeUnitAt(path.length - 1));
      39             : 
      40          11 :   @override
      41             :   int rootLength(String path, {bool withDrive = false}) {
      42          33 :     if (path.isNotEmpty && isSeparator(path.codeUnitAt(0))) return 1;
      43             :     return 0;
      44             :   }
      45             : 
      46          11 :   @override
      47             :   bool isRootRelative(String path) => false;
      48             : 
      49           0 :   @override
      50             :   String? getRelativeRoot(String path) => null;
      51             : 
      52          11 :   @override
      53             :   String pathFromUri(Uri uri) {
      54          44 :     if (uri.scheme == '' || uri.scheme == 'file') {
      55          22 :       return Uri.decodeComponent(uri.path);
      56             :     }
      57           0 :     throw ArgumentError("Uri $uri must have scheme 'file:'.");
      58             :   }
      59             : 
      60           0 :   @override
      61             :   Uri absolutePathToUri(String path) {
      62           0 :     final parsed = ParsedPath.parse(path, this);
      63           0 :     if (parsed.parts.isEmpty) {
      64             :       // If the path is a bare root (e.g. "/"), [components] will
      65             :       // currently be empty. We add two empty components so the URL constructor
      66             :       // produces "file:///", with a trailing slash.
      67           0 :       parsed.parts.addAll(['', '']);
      68           0 :     } else if (parsed.hasTrailingSeparator) {
      69             :       // If the path has a trailing slash, add a single empty component so the
      70             :       // URI has a trailing slash as well.
      71           0 :       parsed.parts.add('');
      72             :     }
      73             : 
      74           0 :     return Uri(scheme: 'file', pathSegments: parsed.parts);
      75             :   }
      76             : }

Generated by: LCOV version 1.14