##// END OF EJS Templates
don't pick up tokens right of cursor...
MinRK -
Show More
@@ -18,8 +18,8 b' def expect_token(expected, cell, cursor_pos):'
18 line_with_cursor = '%s|%s' % (line[:column], line[column:])
18 line_with_cursor = '%s|%s' % (line[:column], line[column:])
19 line
19 line
20 nt.assert_equal(token, expected,
20 nt.assert_equal(token, expected,
21 "Excpected %r, got %r in: %s" % (
21 "Expected %r, got %r in: %r (pos %i)" % (
22 expected, token, line_with_cursor)
22 expected, token, line_with_cursor, cursor_pos)
23 )
23 )
24
24
25 def test_simple():
25 def test_simple():
@@ -30,7 +30,14 b' def test_simple():'
30 def test_function():
30 def test_function():
31 cell = "foo(a=5, b='10')"
31 cell = "foo(a=5, b='10')"
32 expected = 'foo'
32 expected = 'foo'
33 for i in (6,7,8,10,11,12):
33 # up to `foo(|a=`
34 for i in range(cell.find('a=') + 1):
35 expect_token("foo", cell, i)
36 # find foo after `=`
37 for i in [cell.find('=') + 1, cell.rfind('=') + 1]:
38 expect_token("foo", cell, i)
39 # in between `5,|` and `|b=`
40 for i in range(cell.find(','), cell.find('b=')):
34 expect_token("foo", cell, i)
41 expect_token("foo", cell, i)
35
42
36 def test_multiline():
43 def test_multiline():
@@ -39,25 +46,25 b' def test_multiline():'
39 'b = hello("string", there)'
46 'b = hello("string", there)'
40 ])
47 ])
41 expected = 'hello'
48 expected = 'hello'
42 start = cell.index(expected)
49 start = cell.index(expected) + 1
43 for i in range(start, start + len(expected)):
50 for i in range(start, start + len(expected)):
44 expect_token(expected, cell, i)
51 expect_token(expected, cell, i)
45 expected = 'there'
52 expected = 'there'
46 start = cell.index(expected)
53 start = cell.index(expected) + 1
47 for i in range(start, start + len(expected)):
54 for i in range(start, start + len(expected)):
48 expect_token(expected, cell, i)
55 expect_token(expected, cell, i)
49
56
50 def test_attrs():
57 def test_attrs():
51 cell = "foo(a=obj.attr.subattr)"
58 cell = "foo(a=obj.attr.subattr)"
52 expected = 'obj'
59 expected = 'obj'
53 idx = cell.find('obj')
60 idx = cell.find('obj') + 1
54 for i in range(idx, idx + 3):
61 for i in range(idx, idx + 3):
55 expect_token(expected, cell, i)
62 expect_token(expected, cell, i)
56 idx = idx + 4
63 idx = cell.find('.attr') + 2
57 expected = 'obj.attr'
64 expected = 'obj.attr'
58 for i in range(idx, idx + 4):
65 for i in range(idx, idx + 4):
59 expect_token(expected, cell, i)
66 expect_token(expected, cell, i)
60 idx = idx + 5
67 idx = cell.find('.subattr') + 2
61 expected = 'obj.attr.subattr'
68 expected = 'obj.attr.subattr'
62 for i in range(idx, len(cell)):
69 for i in range(idx, len(cell)):
63 expect_token(expected, cell, i)
70 expect_token(expected, cell, i)
@@ -47,7 +47,9 b' def token_at_cursor(cell, cursor_pos=0):'
47 # token, text, start, end, line = tup
47 # token, text, start, end, line = tup
48 start_col = tok.start[1]
48 start_col = tok.start[1]
49 end_col = tok.end[1]
49 end_col = tok.end[1]
50 if offset + start_col > cursor_pos:
50 # allow '|foo' to find 'foo' at the beginning of a line
51 boundary = cursor_pos + 1 if start_col == 0 else cursor_pos
52 if offset + start_col >= boundary:
51 # current token starts after the cursor,
53 # current token starts after the cursor,
52 # don't consume it
54 # don't consume it
53 break
55 break
General Comments 0
You need to be logged in to leave comments. Login now