##// 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 18 line_with_cursor = '%s|%s' % (line[:column], line[column:])
19 19 line
20 20 nt.assert_equal(token, expected,
21 "Excpected %r, got %r in: %s" % (
22 expected, token, line_with_cursor)
21 "Expected %r, got %r in: %r (pos %i)" % (
22 expected, token, line_with_cursor, cursor_pos)
23 23 )
24 24
25 25 def test_simple():
@@ -30,7 +30,14 b' def test_simple():'
30 30 def test_function():
31 31 cell = "foo(a=5, b='10')"
32 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 41 expect_token("foo", cell, i)
35 42
36 43 def test_multiline():
@@ -39,25 +46,25 b' def test_multiline():'
39 46 'b = hello("string", there)'
40 47 ])
41 48 expected = 'hello'
42 start = cell.index(expected)
49 start = cell.index(expected) + 1
43 50 for i in range(start, start + len(expected)):
44 51 expect_token(expected, cell, i)
45 52 expected = 'there'
46 start = cell.index(expected)
53 start = cell.index(expected) + 1
47 54 for i in range(start, start + len(expected)):
48 55 expect_token(expected, cell, i)
49 56
50 57 def test_attrs():
51 58 cell = "foo(a=obj.attr.subattr)"
52 59 expected = 'obj'
53 idx = cell.find('obj')
60 idx = cell.find('obj') + 1
54 61 for i in range(idx, idx + 3):
55 62 expect_token(expected, cell, i)
56 idx = idx + 4
63 idx = cell.find('.attr') + 2
57 64 expected = 'obj.attr'
58 65 for i in range(idx, idx + 4):
59 66 expect_token(expected, cell, i)
60 idx = idx + 5
67 idx = cell.find('.subattr') + 2
61 68 expected = 'obj.attr.subattr'
62 69 for i in range(idx, len(cell)):
63 70 expect_token(expected, cell, i)
@@ -47,7 +47,9 b' def token_at_cursor(cell, cursor_pos=0):'
47 47 # token, text, start, end, line = tup
48 48 start_col = tok.start[1]
49 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 53 # current token starts after the cursor,
52 54 # don't consume it
53 55 break
General Comments 0
You need to be logged in to leave comments. Login now