diff options
author | Sven Gothel <[email protected]> | 2022-07-07 03:11:30 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2022-07-07 03:11:30 +0200 |
commit | e2ad720568f730fe5ca2f1d0c9c911b339fb58b8 (patch) | |
tree | e2e8baf85c006d0b494b42554dc9b3d87a794816 /test | |
parent | b9d1c558884dd5f5ce23ee7d35e2f14201a2c4c2 (diff) |
Fix dir_item::reduce()
- use while-loop to remove initial './'
- always use spos and reset to pre-len when re-assembling pre+post
- break resolve loop once on found idx == npos
- limit loop to spos <= haystack.size()-pattern_size
- resolve '/./':
- remove dead-case '_dot == pre' as resolved upfront
- resolve '/../':
- test non-starting '/..' at end of pre -> no change. E.g. '../../../bbb'
- case 'pre_str = direname(pre)': test '.' (first dir removed)
Diffstat (limited to 'test')
-rw-r--r-- | test/java/jau/test/fs/TestFileUtils01.java | 38 | ||||
-rw-r--r-- | test/test_fileutils01.cpp | 37 |
2 files changed, 73 insertions, 2 deletions
diff --git a/test/java/jau/test/fs/TestFileUtils01.java b/test/java/jau/test/fs/TestFileUtils01.java index 78cfecf..55e0f7f 100644 --- a/test/java/jau/test/fs/TestFileUtils01.java +++ b/test/java/jau/test/fs/TestFileUtils01.java @@ -420,7 +420,43 @@ public class TestFileUtils01 extends FileUtilBaseTest { PrintUtil.println(System.err, "test04_dir_item: 60 '"+path1_+" -> "+di.toString()+" -> '"+di.path()+"'\n"); Assert.assertTrue( "../../test_data".equals( di.dirname() ) ); Assert.assertTrue( "file_01_slink09R1.txt".equals( di.basename() ) ); - Assert.assertTrue( "../../test_data/file_01_slink09R1.txt".equals( di.path() ) ); + Assert.assertTrue( path1_.equals( di.path() ) ); + } + + { + final String path1_ = "../../../jaulib/test_data"; + final DirItem di = new DirItem(path1_); + PrintUtil.println(System.err, "test04_dir_item: 61 '"+path1_+" -> "+di.toString()+" -> '"+di.path()+"'\n"); + Assert.assertTrue( "../../../jaulib".equals( di.dirname() ) ); + Assert.assertTrue( "test_data".equals( di.basename() ) ); + Assert.assertTrue( path1_.equals( di.path() ) ); + } + + { + final String path1_ = "../../../../jaulib/test_data"; + final DirItem di = new DirItem(path1_); + PrintUtil.println(System.err, "test04_dir_item: 62 '"+path1_+" -> "+di.toString()+" -> '"+di.path()+"'\n"); + Assert.assertTrue( "../../../../jaulib".equals( di.dirname() ) ); + Assert.assertTrue( "test_data".equals( di.basename() ) ); + Assert.assertTrue( path1_.equals( di.path() ) ); + } + + { + final String path1_ = "././././jaulib/test_data"; + final DirItem di = new DirItem(path1_); + PrintUtil.println(System.err, "test04_dir_item: 63 '"+path1_+" -> "+di.toString()+" -> '"+di.path()+"'\n"); + Assert.assertTrue( "jaulib".equals( di.dirname() ) ); + Assert.assertTrue( "test_data".equals( di.basename() ) ); + Assert.assertTrue( "jaulib/test_data".equals( di.path() ) ); + } + + { + final String path1_ = "a/././././jaulib/test_data"; + final DirItem di = new DirItem(path1_); + PrintUtil.println(System.err, "test04_dir_item: 64 '"+path1_+" -> "+di.toString()+" -> '"+di.path()+"'\n"); + Assert.assertTrue( "a/jaulib".equals( di.dirname() ) ); + Assert.assertTrue( "test_data".equals( di.basename() ) ); + Assert.assertTrue( "a/jaulib/test_data".equals( di.path() ) ); } { diff --git a/test/test_fileutils01.cpp b/test/test_fileutils01.cpp index d10be65..54a59e8 100644 --- a/test/test_fileutils01.cpp +++ b/test/test_fileutils01.cpp @@ -396,7 +396,42 @@ class TestFileUtil01 : TestFileUtilBase { INFO_STR("\n\ntest04_dir_item: 60 '"+path1_+" -> "+di.to_string()+" -> '"+di.path()+"'\n"); REQUIRE( "../../test_data" == di.dirname() ); REQUIRE( "file_01_slink09R1.txt" == di.basename() ); - REQUIRE( "../../test_data/file_01_slink09R1.txt" == di.path() ); + REQUIRE( path1_ == di.path() ); + } + + { + const std::string path1_ = "../../../jaulib/test_data"; + const jau::fs::dir_item di(path1_); + INFO_STR("\n\ntest04_dir_item: 61 '"+path1_+" -> "+di.to_string()+" -> '"+di.path()+"'\n"); + REQUIRE( "../../../jaulib" == di.dirname() ); + REQUIRE( "test_data" == di.basename() ); + REQUIRE( path1_ == di.path() ); + } + + { + const std::string path1_ = "../../../../jaulib/test_data"; + const jau::fs::dir_item di(path1_); + INFO_STR("\n\ntest04_dir_item: 62 '"+path1_+" -> "+di.to_string()+" -> '"+di.path()+"'\n"); + REQUIRE( "../../../../jaulib" == di.dirname() ); + REQUIRE( "test_data" == di.basename() ); + REQUIRE( path1_ == di.path() ); + } + + { + const std::string path1_ = "././././jaulib/test_data"; + const jau::fs::dir_item di(path1_); + INFO_STR("\n\ntest04_dir_item: 63 '"+path1_+" -> "+di.to_string()+" -> '"+di.path()+"'\n"); + REQUIRE( "jaulib" == di.dirname() ); + REQUIRE( "test_data" == di.basename() ); + REQUIRE( "jaulib/test_data" == di.path() ); + } + { + const std::string path1_ = "a/././././jaulib/test_data"; + const jau::fs::dir_item di(path1_); + INFO_STR("\n\ntest04_dir_item: 64 '"+path1_+" -> "+di.to_string()+" -> '"+di.path()+"'\n"); + REQUIRE( "a/jaulib" == di.dirname() ); + REQUIRE( "test_data" == di.basename() ); + REQUIRE( "a/jaulib/test_data" == di.path() ); } { |