summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-11-23 12:27:58 +0000
committer最萌小汐 <sumneko@hotmail.com>2022-11-23 12:27:58 +0000
commit29ba37ce3cadb85448773988d961fec4bc44c14e (patch)
treeb44f930b91fb9eed5343aab5d3f80b2ed838973d
parentfbbcb96227b0fcad77d2e061cfb95b3871f4bcc7 (diff)
downloadlua-language-server-29ba37ce3cadb85448773988d961fec4bc44c14e.zip
add test for filewatch
-rw-r--r--test.lua2
-rw-r--r--test/other/filewatch.lua43
-rw-r--r--test/other/init.lua12
3 files changed, 45 insertions, 12 deletions
diff --git a/test.lua b/test.lua
index 329de053..2c2c1713 100644
--- a/test.lua
+++ b/test.lua
@@ -66,7 +66,7 @@ local function testAll()
test 'document_symbol'
test 'code_action'
test 'type_formatting'
- --test 'other'
+ test 'other'
end
local files = require "files"
diff --git a/test/other/filewatch.lua b/test/other/filewatch.lua
new file mode 100644
index 00000000..59c5812d
--- /dev/null
+++ b/test/other/filewatch.lua
@@ -0,0 +1,43 @@
+local thread = require 'bee.thread'
+local fw = require 'filewatch'
+local fs = require 'bee.filesystem'
+local fsu = require 'fs-utility'
+
+local path = fs.path(LOGPATH) / 'fw'
+
+fs.create_directories(path)
+
+os.remove((path / 'test.txt'):string())
+
+local _ <close> = fw.watch(path:string())
+fsu.saveFile(path / 'test.txt', 'test')
+
+local events
+fw.event(function (ev, filename)
+ events[#events+1] = {ev, filename}
+end)
+
+thread.sleep(1)
+events = {}
+fw.update()
+assert(#events == 1)
+assert(events[1][1] == 'create')
+
+fsu.saveFile(path / 'test.txt', 'modify')
+
+thread.sleep(1)
+events = {}
+fw.update()
+assert(#events == 1)
+assert(events[1][1] == 'change')
+
+local f <close> = io.open((path / 'test.txt'):string(), 'a')
+assert(f)
+f:write('xxx')
+f:flush()
+
+thread.sleep(1)
+events = {}
+fw.update()
+assert(#events == 1)
+assert(events[1][1] == 'change')
diff --git a/test/other/init.lua b/test/other/init.lua
index 069a2454..dcb57404 100644
--- a/test/other/init.lua
+++ b/test/other/init.lua
@@ -1,11 +1 @@
-local fs = require 'bee.filesystem'
-local platform = require 'bee.platform'
-local path = fs.path '/a/b/c/d/e/../../../..'
-local absolute = fs.absolute(path)
-if platform.OS == 'Windows' then
- assert(absolute:string():sub(-2) == '/a', absolute:string())
-elseif platform.OS == 'Linux' then
- assert(absolute:string():sub(-3) == '/a/', absolute:string())
-elseif platform.OS == 'macOS' then
- -- 不支持
-end
+require 'other.filewatch'