aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-common/tests/test_paths.py
diff options
context:
space:
mode:
Diffstat (limited to 'packages/meshbay-common/tests/test_paths.py')
-rw-r--r--packages/meshbay-common/tests/test_paths.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/packages/meshbay-common/tests/test_paths.py b/packages/meshbay-common/tests/test_paths.py
index 012a32e..cbaf1f5 100644
--- a/packages/meshbay-common/tests/test_paths.py
+++ b/packages/meshbay-common/tests/test_paths.py
@@ -6,12 +6,15 @@ these are not compatibility niceties — they decide whether two index entries a
one file, and whether a member can save what they downloaded.
"""
+import os
+
import pytest
from meshbay_common.paths import (
find_fold_collisions,
fold,
fold_path,
is_portable_name,
+ long_path,
nfc,
portable_name_problem,
sanitize_for_download,
@@ -126,3 +129,49 @@ def test_a_bidi_override_cannot_hide_an_extension():
disguised = "invoice‮fdp.exe" # displays as "invoiceexe.pdf"
assert sanitize_for_download(disguised) == "invoice_fdp.exe"
assert portable_name_problem(disguised)
+
+
+# ── Long paths on Windows ────────────────────────────────────────────────────
+
+on_windows = pytest.mark.skipif(os.name != "nt", reason="the extended form is Windows'")
+BS = chr(92)
+EXT = BS * 2 + "?" + BS
+DEEP = BS.join(["C:", *["a folder name of some length"] * 9, "track.flac"])
+
+
+@on_windows
+def test_a_short_path_is_left_as_it_is():
+ assert long_path(f"C:{BS}Music{BS}track.flac") == f"C:{BS}Music{BS}track.flac"
+
+
+@on_windows
+def test_a_long_path_gets_the_extended_form():
+ assert long_path(DEEP) == EXT + DEEP
+
+
+@on_windows
+def test_the_extended_form_is_normalised_first():
+ """The system normalises nothing behind the prefix: a forward slash or a
+ `..` left in would name a file that does not exist."""
+ messy = DEEP.replace(BS, "/").replace("/track.flac", "/x/../track.flac")
+ assert long_path(messy) == EXT + DEEP
+
+
+@on_windows
+def test_a_long_share_path_gets_the_unc_form():
+ share = BS * 2 + "server" + BS + "share" + DEEP[2:]
+ assert long_path(share) == EXT + "UNC" + BS + share[2:]
+
+
+@on_windows
+def test_a_path_in_the_extended_form_is_left_alone():
+ assert long_path(EXT + DEEP) == EXT + DEEP
+
+
+@on_windows
+def test_a_directory_gets_it_before_max_path():
+ """Creating a directory is refused twelve characters before MAX_PATH."""
+ at_248 = "C:" + BS + "d" * 245
+ assert len(at_248) == 248
+ assert long_path(at_248) == EXT + at_248
+ assert long_path(at_248[:-1]) == at_248[:-1]