Skip to content

Commit 04896f6

Browse files
committed
root: don't coerce
1 parent c5984b3 commit 04896f6

File tree

4 files changed

+15
-21
lines changed

4 files changed

+15
-21
lines changed

+stdlib/root_dir.m

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,13 @@
99
% * root_dir('path/to/file') returns ''
1010

1111
function r = root_dir(p)
12-
arguments
13-
p (1,1) string
14-
end
15-
16-
r = "";
1712

1813
if startsWith(p, ["/", filesep])
1914
r = extractBefore(p, 2);
2015
elseif ispc() && ~isempty(regexp(p, '^[A-Za-z]:[\\/]','once'))
2116
r = extractBetween(p, 3, 3);
17+
else
18+
r = extractBefore(p, 1);
2219
end
2320

2421
end

+stdlib/root_name.m

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,11 @@
66

77

88
function r = root_name(p)
9-
arguments
10-
p (1,1) string
11-
end
12-
13-
r = "";
149

1510
if ispc() && ~isempty(regexp(p, '^[A-Za-z]:', 'once'))
1611
r = extractBefore(p, 3);
12+
else
13+
r = extractBefore(p, 1);
1714
end
1815

1916
end

test/TestDisk.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ function test_is_mount(tc, B_ps)
7777

7878
if ispc()
7979
sd = getenv("SystemDrive");
80-
tc.assertTrue(sd == stdlib.root_name(sd), sd)
80+
tc.assertEqual(sd, stdlib.root_name(sd))
8181
tc.verifyFalse(stdlib.is_mount(sd, B_ps), sd)
8282
tc.verifyTrue(stdlib.is_mount(sd + "/", B_ps), sd)
8383
tc.verifyTrue(stdlib.is_mount(sd + "\", B_ps), sd)

test/TestRoot.m

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@
1313

1414
function test_root(tc, p)
1515
r = stdlib.root(p{1});
16-
tc.assertClass(r, 'string')
17-
tc.verifyEqual(r, p{2})
16+
tc.assertClass(r, class(p{1}))
17+
tc.verifyEqual(r, p{2}, "root(" + p{1} + ")")
1818
end
1919

2020
function test_root_dir(tc, rd)
2121
r = stdlib.root_dir(rd{1});
22-
tc.assertClass(r, 'string')
22+
tc.assertClass(r, class(rd{1}))
2323
tc.verifyEqual(r, rd{2}, "root_dir(" + rd{1} + ")")
2424
end
2525

2626
function test_root_name(tc, rn)
2727
r = stdlib.root_name(rn{1});
28-
tc.assertClass(r, 'string')
28+
tc.assertClass(r, class(rn{1}))
2929
tc.verifyEqual(r, rn{2})
3030
end
3131

@@ -40,15 +40,15 @@ function test_root_name(tc, rn)
4040
{"a/b", ""}, ...
4141
{"./a/b", ""}, ...
4242
{"/etc", "/"}, ...
43-
{'/etc', "/"}, ...
43+
{'/etc', '/'}, ...
4444
{"c:", ""}, ...
4545
{"c:/etc", ""}, ...
46-
{'c:\etc', ""}};
46+
{'c:\etc', ''}};
4747

4848
if ispc()
4949
p{6}{2} = "c:";
5050
p{7}{2} = "c:/";
51-
p{8}{2} = "c:\";
51+
p{8}{2} = 'c:\';
5252
end
5353

5454
end
@@ -59,12 +59,12 @@ function test_root_name(tc, rn)
5959
p = init_root();
6060

6161
p{4}{2} = "";
62-
p{5}{2} = "";
62+
p{5}{2} = '';
6363

6464
if ispc()
6565
p{6}{2} = "c:";
6666
p{7}{2} = "c:";
67-
p{8}{2} = "c:";
67+
p{8}{2} = 'c:';
6868
end
6969

7070
end
@@ -77,7 +77,7 @@ function test_root_name(tc, rn)
7777
if ispc()
7878
p{6}{2} = "";
7979
p{7}{2} = "/";
80-
p{8}{2} = "\";
80+
p{8}{2} = '\';
8181
end
8282

8383
end

0 commit comments

Comments
 (0)