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 'make.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 | $if !windows { |
61 | assert 'cmd/tools/test_if_v_test_system_works.v' in matches |
62 | } |
63 | $if windows { |
64 | assert 'test_if_v_test_system_works.v' in matches |
65 | } |
66 | } |
67 | |
68 | fn test_glob_star() { |
69 | os.chdir(@VMODROOT)! |
70 | matches := os.glob('*ake*')! |
71 | assert 'Makefile' in matches |
72 | assert 'make.bat' in matches |
73 | } |
74 | |
75 | fn test_glob_not_found() { |
76 | os.glob('an_unknown_folder/*.v') or { |
77 | assert true |
78 | return |
79 | } |
80 | } |