]>
Commit | Line | Data |
---|---|---|
1d09f67e TL |
1 | # Licensed to the Apache Software Foundation (ASF) under one |
2 | # or more contributor license agreements. See the NOTICE file | |
3 | # distributed with this work for additional information | |
4 | # regarding copyright ownership. The ASF licenses this file | |
5 | # to you under the Apache License, Version 2.0 (the | |
6 | # "License"); you may not use this file except in compliance | |
7 | # with the License. You may obtain a copy of the License at | |
8 | # | |
9 | # http://www.apache.org/licenses/LICENSE-2.0 | |
10 | # | |
11 | # Unless required by applicable law or agreed to in writing, | |
12 | # software distributed under the License is distributed on an | |
13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
14 | # KIND, either express or implied. See the License for the | |
15 | # specific language governing permissions and limitations | |
16 | # under the License. | |
17 | ||
18 | class TestFileInfo < Test::Unit::TestCase | |
19 | def setup | |
20 | @file_info = Arrow::FileInfo.new | |
21 | end | |
22 | ||
23 | sub_test_case("#type") do | |
24 | test("default") do | |
25 | assert_equal(Arrow::FileType::UNKNOWN, | |
26 | @file_info.type) | |
27 | end | |
28 | end | |
29 | ||
30 | test("#type=") do | |
31 | @file_info.type = :dir | |
32 | assert_equal(Arrow::FileType::DIR, | |
33 | @file_info.type) | |
34 | end | |
35 | ||
36 | sub_test_case("#path") do | |
37 | test("default") do | |
38 | assert_equal("", @file_info.path) | |
39 | end | |
40 | end | |
41 | ||
42 | test("#path=") do | |
43 | @file_info.path = "/a/b/c.d" | |
44 | assert_equal("/a/b/c.d", | |
45 | @file_info.path) | |
46 | end | |
47 | ||
48 | sub_test_case("#base_name") do | |
49 | test("default") do | |
50 | assert_equal("", @file_info.base_name) | |
51 | end | |
52 | ||
53 | test("with directory") do | |
54 | @file_info.path = "/a/b/c.d" | |
55 | assert_equal("c.d", @file_info.base_name) | |
56 | end | |
57 | end | |
58 | ||
59 | sub_test_case("#dir_name") do | |
60 | test("default") do | |
61 | assert_equal("", @file_info.dir_name) | |
62 | end | |
63 | ||
64 | test("with directory") do | |
65 | @file_info.path = "/a/b/c.d" | |
66 | assert_equal("/a/b", @file_info.dir_name) | |
67 | end | |
68 | end | |
69 | ||
70 | sub_test_case("#extension") do | |
71 | test("default") do | |
72 | assert_equal("", @file_info.extension) | |
73 | end | |
74 | ||
75 | test("exist") do | |
76 | @file_info.path = "/a/b/c.d" | |
77 | assert_equal("d", @file_info.extension) | |
78 | end | |
79 | end | |
80 | ||
81 | sub_test_case("#size") do | |
82 | test("default") do | |
83 | assert_equal(-1, @file_info.size) | |
84 | end | |
85 | end | |
86 | ||
87 | sub_test_case("#mtime") do | |
88 | test("default") do | |
89 | assert_equal(-1, @file_info.mtime) | |
90 | end | |
91 | end | |
92 | ||
93 | sub_test_case("#==") do | |
94 | def setup | |
95 | super | |
96 | @other_file_info = Arrow::FileInfo.new | |
97 | end | |
98 | ||
99 | test("all the properties are the same") do | |
100 | assert do | |
101 | @file_info == @other_file_info | |
102 | end | |
103 | end | |
104 | ||
105 | test("the different type") do | |
106 | @other_file_info.type = Arrow::FileType::FILE | |
107 | assert do | |
108 | @file_info != @other_file_info | |
109 | end | |
110 | end | |
111 | ||
112 | test("the different path") do | |
113 | @other_file_info.path = "/a/b/c" | |
114 | assert do | |
115 | @file_info != @other_file_info | |
116 | end | |
117 | end | |
118 | ||
119 | test("the different size") do | |
120 | @other_file_info.size = 42 | |
121 | assert do | |
122 | @file_info != @other_file_info | |
123 | end | |
124 | end | |
125 | ||
126 | test("the different mtime") do | |
127 | @other_file_info.mtime = Time.now.to_i | |
128 | assert do | |
129 | @file_info != @other_file_info | |
130 | end | |
131 | end | |
132 | end | |
133 | ||
134 | sub_test_case("#file?") do | |
135 | test("true") do | |
136 | @file_info.type = :file | |
137 | assert do | |
138 | @file_info.file? | |
139 | end | |
140 | end | |
141 | ||
142 | test("false") do | |
143 | @file_info.type = :dir | |
144 | assert do | |
145 | not @file_info.file? | |
146 | end | |
147 | end | |
148 | end | |
149 | ||
150 | sub_test_case("#dir?") do | |
151 | test("true") do | |
152 | @file_info.type = :dir | |
153 | assert do | |
154 | @file_info.dir? | |
155 | end | |
156 | end | |
157 | ||
158 | test("false") do | |
159 | @file_info.type = :file | |
160 | assert do | |
161 | not @file_info.dir? | |
162 | end | |
163 | end | |
164 | end | |
165 | ||
166 | test("#to_s") do | |
167 | assert_equal("FileInfo(FileType::Unknown, )", | |
168 | @file_info.to_s) | |
169 | end | |
170 | end |