Skip to content

Commit

Permalink
Fix parseFilePath: replace delimiter with sep (mozilla#127)
Browse files Browse the repository at this point in the history
`path.delimiter` is a colon, we want `path.sep` which is a `/`.
  • Loading branch information
hoodmane authored May 2, 2024
1 parent 97abcce commit e620750
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
6 changes: 3 additions & 3 deletions sphinx_js/js/convertTopLevel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] {
Expand All @@ -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) {
Expand Down
27 changes: 24 additions & 3 deletions tests/test_typedoc_analysis/test_typedoc_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -95,6 +104,7 @@ def test_weird_name(self):
def test_getter(self):
assert self.commented_object_path("Getter") == [
"./",
"subdir/",
"pathSegments.",
"Foo#",
"getter",
Expand All @@ -103,6 +113,7 @@ def test_getter(self):
def test_setter(self):
assert self.commented_object_path("Setter") == [
"./",
"subdir/",
"pathSegments.",
"Foo#",
"setter",
Expand All @@ -111,6 +122,7 @@ def test_setter(self):
def test_method(self):
assert self.commented_object_path("Method") == [
"./",
"subdir/",
"pathSegments.",
"Foo#",
"someMethod",
Expand All @@ -122,6 +134,7 @@ def test_static_method(self):
expect."""
assert self.commented_object_path("Static method") == [
"./",
"subdir/",
"pathSegments.",
"Foo.",
"staticMethod",
Expand All @@ -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"
Expand All @@ -153,6 +172,7 @@ def test_relative_paths(self):
"./",
"test_typedoc_analysis/",
"source/",
"subdir/",
"pathSegments.",
"foo",
]
Expand All @@ -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",
Expand Down

0 comments on commit e620750

Please sign in to comment.