summaryrefslogtreecommitdiff
path: root/cli/fs_util.rs
diff options
context:
space:
mode:
authorRabin Gaire <rabingaire20@gmail.com>2022-01-11 10:09:39 +0545
committerGitHub <noreply@github.com>2022-01-10 23:24:39 -0500
commit605b8db8f61fc4c0c71d11cde873af18d87c49bf (patch)
tree63ecb48a02e2549aa8db941ecdd95147843a7b36 /cli/fs_util.rs
parentb66afa2518042cda239ef07f221722781ca660f6 (diff)
cli(compile): fix output flag behaviour on compile command (#13299)
Diffstat (limited to 'cli/fs_util.rs')
-rw-r--r--cli/fs_util.rs39
1 files changed, 39 insertions, 0 deletions
diff --git a/cli/fs_util.rs b/cli/fs_util.rs
index 06bdb689a..7290d3696 100644
--- a/cli/fs_util.rs
+++ b/cli/fs_util.rs
@@ -376,6 +376,20 @@ pub fn specifier_parent(specifier: &ModuleSpecifier) -> ModuleSpecifier {
specifier
}
+/// This function checks if input path has trailing slash or not. If input path
+/// has trailing slash it will return true else it will return false.
+pub fn path_has_trailing_slash(path: &Path) -> bool {
+ if let Some(path_str) = path.to_str() {
+ if cfg!(windows) {
+ path_str.ends_with('\\')
+ } else {
+ path_str.ends_with('/')
+ }
+ } else {
+ false
+ }
+}
+
#[cfg(test)]
mod tests {
use super::*;
@@ -754,4 +768,29 @@ mod tests {
assert_eq!(result.to_string(), expected);
}
}
+
+ #[test]
+ fn test_path_has_trailing_slash() {
+ #[cfg(not(windows))]
+ {
+ run_test("/Users/johndoe/Desktop/deno-project/target/", true);
+ run_test(r"/Users/johndoe/deno-project/target//", true);
+ run_test("/Users/johndoe/Desktop/deno-project", false);
+ run_test(r"/Users/johndoe/deno-project\", false);
+ }
+
+ #[cfg(windows)]
+ {
+ run_test(r"C:\test\deno-project\", true);
+ run_test(r"C:\test\deno-project\\", true);
+ run_test(r"C:\test\file.txt", false);
+ run_test(r"C:\test\file.txt/", false);
+ }
+
+ fn run_test(path_str: &str, expected: bool) {
+ let path = Path::new(path_str);
+ let result = path_has_trailing_slash(path);
+ assert_eq!(result, expected);
+ }
+ }
}