| 1 | import os |
| 2 | |
| 3 | fn deep_glob() ! { |
| 4 | os.chdir(@VMODROOT)! |
| 5 | matches := os.glob('vlib/v/*/*.v') or { panic(err) } |
| 6 | assert matches.len > 10 |
| 7 | assert 'vlib/v/ast/ast.v' in matches |
| 8 | assert 'vlib/v/ast/table.v' in matches |
| 9 | assert 'vlib/v/token/token.v' in matches |
| 10 | for f in matches { |
| 11 | if !f.starts_with('vlib/v/') { |
| 12 | assert false |
| 13 | } |
| 14 | assert f.ends_with('.v') |
| 15 | } |
| 16 | } |
| 17 | |
| 18 | fn redeep_glob() ! { |
| 19 | os.chdir(@VMODROOT)! |
| 20 | matches := os.glob('vlib/v/**/*.v') or { panic(err) } |
| 21 | assert matches.len > 10 |
| 22 | assert 'vlib/v/ast/ast.v' in matches |
| 23 | assert 'vlib/v/ast/table.v' in matches |
| 24 | assert 'vlib/v/token/token.v' in matches |
| 25 | for f in matches { |
| 26 | if !f.starts_with('vlib/v/') { |
| 27 | assert false |
| 28 | } |
| 29 | assert f.ends_with('.v') |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | fn test_glob_can_find_v_files_3_levels_deep() { |
| 34 | $if !windows { |
| 35 | deep_glob()! |
| 36 | redeep_glob()! |
| 37 | } |
| 38 | assert true |
| 39 | } |
| 40 | |
| 41 | fn test_glob_can_find_files_in_current_folder() { |
| 42 | os.chdir(@VMODROOT)! |
| 43 | matches := os.glob('*')! |
| 44 | assert '.gitignore' in matches |
| 45 | assert 'makev.bat' in matches |
| 46 | assert 'Makefile' in matches |
| 47 | assert 'Dockerfile' in matches |
| 48 | assert 'README.md' in matches |
| 49 | assert 'v.mod' in matches |
| 50 | assert 'cmd/' in matches |
| 51 | assert 'vlib/' in matches |
| 52 | assert 'thirdparty/' in matches |
| 53 | } |
| 54 | |
| 55 | fn test_glob_can_be_used_with_multiple_patterns() { |
| 56 | os.chdir(@VMODROOT)! |
| 57 | matches := os.glob('*', 'cmd/tools/*')! |
| 58 | assert 'README.md' in matches |
| 59 | assert 'Makefile' in matches |
| 60 | assert 'cmd/tools/test_if_v_test_system_works.v' in matches |
| 61 | } |
| 62 | |
| 63 | fn test_glob_star() { |
| 64 | os.chdir(@VMODROOT)! |
| 65 | matches := os.glob('*ake*')! |
| 66 | assert 'Makefile' in matches |
| 67 | assert 'makev.bat' in matches |
| 68 | } |
| 69 | |
| 70 | fn test_glob_not_found() { |
| 71 | os.glob('an_unknown_folder/*.v') or { |
| 72 | assert true |
| 73 | return |
| 74 | } |
| 75 | } |
| 76 | |