Skip to content

Commit 29ba37c

Browse files
committed
add test for filewatch
1 parent fbbcb96 commit 29ba37c

File tree

3 files changed

+45
-12
lines changed

3 files changed

+45
-12
lines changed

test.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ local function testAll()
6666
test 'document_symbol'
6767
test 'code_action'
6868
test 'type_formatting'
69-
--test 'other'
69+
test 'other'
7070
end
7171

7272
local files = require "files"

test/other/filewatch.lua

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
local thread = require 'bee.thread'
2+
local fw = require 'filewatch'
3+
local fs = require 'bee.filesystem'
4+
local fsu = require 'fs-utility'
5+
6+
local path = fs.path(LOGPATH) / 'fw'
7+
8+
fs.create_directories(path)
9+
10+
os.remove((path / 'test.txt'):string())
11+
12+
local _ <close> = fw.watch(path:string())
13+
fsu.saveFile(path / 'test.txt', 'test')
14+
15+
local events
16+
fw.event(function (ev, filename)
17+
events[#events+1] = {ev, filename}
18+
end)
19+
20+
thread.sleep(1)
21+
events = {}
22+
fw.update()
23+
assert(#events == 1)
24+
assert(events[1][1] == 'create')
25+
26+
fsu.saveFile(path / 'test.txt', 'modify')
27+
28+
thread.sleep(1)
29+
events = {}
30+
fw.update()
31+
assert(#events == 1)
32+
assert(events[1][1] == 'change')
33+
34+
local f <close> = io.open((path / 'test.txt'):string(), 'a')
35+
assert(f)
36+
f:write('xxx')
37+
f:flush()
38+
39+
thread.sleep(1)
40+
events = {}
41+
fw.update()
42+
assert(#events == 1)
43+
assert(events[1][1] == 'change')

test/other/init.lua

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1 @@
1-
local fs = require 'bee.filesystem'
2-
local platform = require 'bee.platform'
3-
local path = fs.path '/a/b/c/d/e/../../../..'
4-
local absolute = fs.absolute(path)
5-
if platform.OS == 'Windows' then
6-
assert(absolute:string():sub(-2) == '/a', absolute:string())
7-
elseif platform.OS == 'Linux' then
8-
assert(absolute:string():sub(-3) == '/a/', absolute:string())
9-
elseif platform.OS == 'macOS' then
10-
-- 不支持
11-
end
1+
require 'other.filewatch'

0 commit comments

Comments
 (0)