mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-29 17:07:19 +02:00
Enhancement
- Added Path::is_absolute, and corresponding unit tests. - Replaced expandPath and isAbsolutePath call in Config.cpp.
This commit is contained in:
parent
c02cfd594c
commit
e1f3f2355a
4 changed files with 20 additions and 3 deletions
|
@ -100,8 +100,8 @@ bool Config::load (const std::string& file, int nest /* = 1 */)
|
||||||
std::string::size_type include = line.find ("include"); // no i18n.
|
std::string::size_type include = line.find ("include"); // no i18n.
|
||||||
if (include != std::string::npos)
|
if (include != std::string::npos)
|
||||||
{
|
{
|
||||||
Path included (expandPath (trim (line.substr (include + 7), " \t")));
|
Path included (trim (line.substr (include + 7), " \t"));
|
||||||
if (isAbsolutePath (included.data))
|
if (included.is_absolute ())
|
||||||
{
|
{
|
||||||
if (included.readable ())
|
if (included.readable ())
|
||||||
this->load (included.data, nest + 1);
|
this->load (included.data, nest + 1);
|
||||||
|
|
|
@ -121,6 +121,15 @@ bool Path::is_directory () const
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
bool Path::is_absolute () const
|
||||||
|
{
|
||||||
|
if (data.length () && data.substr (0, 1) == "/")
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
bool Path::readable () const
|
bool Path::readable () const
|
||||||
{
|
{
|
||||||
|
|
|
@ -44,6 +44,7 @@ public:
|
||||||
std::string extension () const;
|
std::string extension () const;
|
||||||
bool exists () const;
|
bool exists () const;
|
||||||
bool is_directory () const;
|
bool is_directory () const;
|
||||||
|
bool is_absolute () const;
|
||||||
bool readable () const;
|
bool readable () const;
|
||||||
bool writable () const;
|
bool writable () const;
|
||||||
bool executable () const;
|
bool executable () const;
|
||||||
|
|
|
@ -33,7 +33,7 @@ Context context;
|
||||||
|
|
||||||
int main (int argc, char** argv)
|
int main (int argc, char** argv)
|
||||||
{
|
{
|
||||||
UnitTest t (26);
|
UnitTest t (31);
|
||||||
|
|
||||||
// Path ();
|
// Path ();
|
||||||
Path p0;
|
Path p0;
|
||||||
|
@ -101,6 +101,13 @@ int main (int argc, char** argv)
|
||||||
t.ok (out.size () == 1, "/[s-u]mp -> 1 result");
|
t.ok (out.size () == 1, "/[s-u]mp -> 1 result");
|
||||||
t.is (out[0], "/tmp", "/[s-u]mp -> /tmp");
|
t.is (out[0], "/tmp", "/[s-u]mp -> /tmp");
|
||||||
|
|
||||||
|
// bool is_absolute () const;
|
||||||
|
t.notok (p0.is_absolute (), "'' !is_absolute");
|
||||||
|
t.notok (p1.is_absolute (), "foo !is_absolute");
|
||||||
|
t.ok (p2.is_absolute (), "~ is_absolute (after expansion)");
|
||||||
|
t.ok (p3.is_absolute (), "/tmp is_absolute");
|
||||||
|
t.ok (p4.is_absolute (), "/a/b/c/file.ext is_absolute");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue