Mercurial > octave-nkf
comparison scripts/miscellaneous/fileparts.m @ 11931:d7d30988b3ea release-3-0-x
fix fileparts tests
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Thu, 29 Jan 2009 08:48:30 +0100 |
parents | e0229beb02c9 |
children | 8d1427a14f45 |
comparison
equal
deleted
inserted
replaced
11930:5032328e940b | 11931:d7d30988b3ea |
---|---|
25 | 25 |
26 function [directory, name, extension, version] = fileparts (filename) | 26 function [directory, name, extension, version] = fileparts (filename) |
27 | 27 |
28 if (nargin == 1) | 28 if (nargin == 1) |
29 if (ischar (filename)) | 29 if (ischar (filename)) |
30 ds = rindex (filename, filesep); | 30 if !( findstr (octave_config_info('canonical_host_type'), 'msvc') || findstr (octave_config_info('canonical_host_type'), 'mingw') ) |
31 ds = rindex (filename, filesep); | |
32 else | |
33 ds = max (rindex (filename, "\\"),rindex (filename, "/")); | |
34 endif | |
31 es = rindex (filename, "."); | 35 es = rindex (filename, "."); |
32 ## These can be the same if they are both 0 (no dir or ext). | 36 ## These can be the same if they are both 0 (no dir or ext). |
33 if (es <= ds) | 37 if (es <= ds) |
34 es = length(filename)+1; | 38 es = length(filename)+1; |
35 endif | 39 endif |
63 %!test | 67 %!test |
64 %! [d, n, e] = fileparts ("file.ext"); | 68 %! [d, n, e] = fileparts ("file.ext"); |
65 %! assert (strcmp (d, "") && strcmp (n, "file") && strcmp (e, ".ext")); | 69 %! assert (strcmp (d, "") && strcmp (n, "file") && strcmp (e, ".ext")); |
66 | 70 |
67 %!test | 71 %!test |
68 %! [d, n, e] = fileparts ("/file.ext"); | 72 %! [d, n, e] = fileparts ([filesep "file.ext"]); |
69 %! assert (strcmp (d, "/") && strcmp (n, "file") && strcmp (e, ".ext")); | 73 %! assert (strcmp (d, filesep) && strcmp (n, "file") && strcmp (e, ".ext")); |
70 | 74 |
71 %!test | 75 %!test |
72 %! [d, n, e] = fileparts ("dir/file.ext"); | 76 %! [d, n, e] = fileparts (["dir" filesep "file.ext"]); |
73 %! assert (strcmp (d, "dir") && strcmp (n, "file") && strcmp (e, ".ext")); | 77 %! assert (strcmp (d, "dir") && strcmp (n, "file") && strcmp (e, ".ext")); |
74 | 78 |
75 %!test | 79 %!test |
76 %! [d, n, e] = fileparts ("./file.ext"); | 80 %! [d, n, e] = fileparts (["." filesep "file.ext"); |
77 %! assert (strcmp (d, ".") && strcmp (n, "file") && strcmp (e, ".ext")); | 81 %! assert (strcmp (d, ".") && strcmp (n, "file") && strcmp (e, ".ext")); |
78 | 82 |
79 %!test | 83 %!test |
80 %! [d, n, e] = fileparts ("d1/d2/file.ext"); | 84 %! [d, n, e] = fileparts (["d1" filesep "d2" filesep "file.ext"]); |
81 %! assert (strcmp (d, "d1/d2") && strcmp (n, "file") && strcmp (e, ".ext")); | 85 %! assert (strcmp (d, "d1/d2") && strcmp (n, "file") && strcmp (e, ".ext")); |
82 | 86 |
83 %!test | 87 %!test |
84 %! [d, n, e] = fileparts ("/d1/d2/file.ext"); | 88 %! [d, n, e] = fileparts ([filesep "d1" filesep "d2" filesep "file.ext"]); |
85 %! assert (strcmp (d, "/d1/d2") && strcmp (n, "file") && strcmp (e, ".ext")); | 89 %! assert (strcmp (d, "/d1/d2") && strcmp (n, "file") && strcmp (e, ".ext")); |
86 | 90 |
87 %!test | 91 %!test |
88 %! [d, n, e] = fileparts ("/.ext"); | 92 %! [d, n, e] = fileparts ([filesep ".ext"]); |
89 %! assert (strcmp (d, "/") && strcmp (n, char (zeros (1, 0))) && strcmp (e, ".ext")); | 93 %! assert (strcmp (d, "/") && strcmp (n, char (zeros (1, 0))) && strcmp (e, ".ext")); |
90 | 94 |
91 %!test | 95 %!test |
92 %! [d, n, e] = fileparts (".ext"); | 96 %! [d, n, e] = fileparts (".ext"); |
93 %! assert (strcmp (d, "") && strcmp (n, char (zeros (1, 0))) && strcmp (e, ".ext")); | 97 %! assert (strcmp (d, "") && strcmp (n, char (zeros (1, 0))) && strcmp (e, ".ext")); |