From e62075044a5896c835459acbb096a2d73f3fba1b Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Thu, 2 May 2024 14:28:15 +0200 Subject: [PATCH] Fix parseFilePath: replace delimiter with sep (#127) `path.delimiter` is a colon, we want `path.sep` which is a `/`. --- sphinx_js/js/convertTopLevel.ts | 6 ++--- .../source/{ => subdir}/pathSegments.ts | 0 .../test_typedoc_analysis.py | 27 ++++++++++++++++--- 3 files changed, 27 insertions(+), 6 deletions(-) rename tests/test_typedoc_analysis/source/{ => subdir}/pathSegments.ts (100%) diff --git a/sphinx_js/js/convertTopLevel.ts b/sphinx_js/js/convertTopLevel.ts index 266c3f65..174fece1 100644 --- a/sphinx_js/js/convertTopLevel.ts +++ b/sphinx_js/js/convertTopLevel.ts @@ -29,7 +29,7 @@ import { Type, TypeParam, } from "./ir.ts"; -import { delimiter, relative } from "path"; +import { sep, relative } from "path"; import { SphinxJsConfig } from "./sphinxJsConfig.ts"; function parseFilePath(path: string, base_dir: string): string[] { @@ -39,12 +39,12 @@ function parseFilePath(path: string, base_dir: string): string[] { let pathSegments: string[]; if (!rel.startsWith("..")) { // We don't have to go up so path is under base_dir - pathSegments = rel.split(delimiter); + pathSegments = rel.split(sep); } else { // It's not under base_dir... maybe it's in a global node_modules or // something? This makes it look the same as if it were under a local // node_modules. - pathSegments = path.split(delimiter); + pathSegments = path.split(sep); pathSegments.reverse(); const idx = pathSegments.indexOf("node_modules"); if (idx !== -1) { diff --git a/tests/test_typedoc_analysis/source/pathSegments.ts b/tests/test_typedoc_analysis/source/subdir/pathSegments.ts similarity index 100% rename from tests/test_typedoc_analysis/source/pathSegments.ts rename to tests/test_typedoc_analysis/source/subdir/pathSegments.ts diff --git a/tests/test_typedoc_analysis/test_typedoc_analysis.py b/tests/test_typedoc_analysis/test_typedoc_analysis.py index 782af4c4..d9bf1122 100644 --- a/tests/test_typedoc_analysis/test_typedoc_analysis.py +++ b/tests/test_typedoc_analysis/test_typedoc_analysis.py @@ -41,7 +41,7 @@ def join_descri(t: Type) -> str: class TestPathSegments(TypeDocTestCase): """Make sure ``make_path_segments() `` works on all its manifold cases.""" - files = ["pathSegments.ts"] + files = ["subdir/pathSegments.ts"] def commented_object(self, comment, **kwargs): """Return the object from ``json`` having the given comment short-text.""" @@ -56,11 +56,17 @@ def commented_object_path(self, comment, **kwargs): return obj.path.segments def test_class(self): - assert self.commented_object_path("Foo class") == ["./", "pathSegments.", "Foo"] + assert self.commented_object_path("Foo class") == [ + "./", + "subdir/", + "pathSegments.", + "Foo", + ] def test_instance_property(self): assert self.commented_object_path("Num instance var") == [ "./", + "subdir/", "pathSegments.", "Foo#", "numInstanceVar", @@ -69,6 +75,7 @@ def test_instance_property(self): def test_static_property(self): assert self.commented_object_path("Static member") == [ "./", + "subdir/", "pathSegments.", "Foo.", "staticMember", @@ -77,6 +84,7 @@ def test_static_property(self): def test_interface_property(self): assert self.commented_object_path("Interface property") == [ "./", + "subdir/", "pathSegments.", "Face.", "moof", @@ -87,6 +95,7 @@ def test_weird_name(self): like #./~ get their pathnames built correctly.""" assert self.commented_object_path("Weird var") == [ "./", + "subdir/", "pathSegments.", "Foo#", "weird#Var", @@ -95,6 +104,7 @@ def test_weird_name(self): def test_getter(self): assert self.commented_object_path("Getter") == [ "./", + "subdir/", "pathSegments.", "Foo#", "getter", @@ -103,6 +113,7 @@ def test_getter(self): def test_setter(self): assert self.commented_object_path("Setter") == [ "./", + "subdir/", "pathSegments.", "Foo#", "setter", @@ -111,6 +122,7 @@ def test_setter(self): def test_method(self): assert self.commented_object_path("Method") == [ "./", + "subdir/", "pathSegments.", "Foo#", "someMethod", @@ -122,6 +134,7 @@ def test_static_method(self): expect.""" assert self.commented_object_path("Static method") == [ "./", + "subdir/", "pathSegments.", "Foo.", "staticMethod", @@ -135,13 +148,19 @@ def test_constructor(self): # Constructors get a #. They aren't static; they can see ``this``. assert self.commented_object_path("Constructor") == [ "./", + "subdir/", "pathSegments.", "Foo#", "constructor", ] def test_function(self): - assert self.commented_object_path("Function") == ["./", "pathSegments.", "foo"] + assert self.commented_object_path("Function") == [ + "./", + "subdir/", + "pathSegments.", + "foo", + ] @pytest.mark.xfail( reason="Test approach doesn't work anymore and broken by typedoc v0.20" @@ -153,6 +172,7 @@ def test_relative_paths(self): "./", "test_typedoc_analysis/", "source/", + "subdir/", "pathSegments.", "foo", ] @@ -161,6 +181,7 @@ def test_namespaced_var(self): """Make sure namespaces get into the path segments.""" assert self.commented_object_path("Namespaced number") == [ "./", + "subdir/", "pathSegments.", "SomeSpace.", "spacedNumber",