-
-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathdiscovery_spec.lua
More file actions
76 lines (61 loc) · 1.86 KB
/
Copy pathdiscovery_spec.lua
File metadata and controls
76 lines (61 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
local dappy = require("dap-python")
describe("test discovery", function()
it("finds simple function", function()
local source = [[
def test_foo():
assert 1 == 2
class FooTest(TestCase):
def test_bar(self):
self.assertEqual(1, 2)
def last():
assert 1 == 1
]]
local nodes = dappy._get_nodes(source, "function", 7)
assert.are.same(1, #nodes)
assert.are.same("test_bar", vim.treesitter.get_node_text(nodes[1], source))
nodes = dappy._get_nodes(source, "function", 4)
assert.are.same(1, #nodes)
assert.are.same("test_foo", vim.treesitter.get_node_text(nodes[1], source))
end)
it("ignores nested functions", function()
local source = [[
class FooTest(TestCase):
def test_foo(self):
def dummy():
return 1
self.assertEqual(1, 2)
]]
local nodes = dappy._get_nodes(source, "function", 5)
assert.are.same(1, #nodes)
assert.are.same("test_foo", vim.treesitter.get_node_text(nodes[1], source))
end)
it("finds class", function()
local source = [[
class FooTest(TestCase):
def test_foo(self):
def dummy():
return 1
self.assertEqual(1, 2)
]]
local nodes = dappy._get_nodes(source, "class", 5)
assert.are.same(1, #nodes)
assert.are.same("FooTest", vim.treesitter.get_node_text(nodes[1], source))
end)
it("returns all nested classes", function()
local source = [[
class NoMatch(TestCase):
def test_x(self):
pass
class A(TestCase):
class B(TestCase):
def test_foo(self):
def dummy():
return 1
self.assertEqual(1, 2)
]]
local nodes = dappy._get_nodes(source, "class", 11)
assert.are.same(2, #nodes)
assert.are.same("A", vim.treesitter.get_node_text(nodes[1], source))
assert.are.same("B", vim.treesitter.get_node_text(nodes[2], source))
end)
end)