more tests pass

This commit is contained in:
Anthony Scopatz 2015-03-14 01:00:46 -05:00
parent 61bf220a57
commit 6c52a64cb3
3 changed files with 29 additions and 5 deletions

View file

@ -69,6 +69,14 @@ def test_subproc_toks_ls_str_comment():
obs = subproc_toks(s + com, lexer=LEXER, returnline=True) obs = subproc_toks(s + com, lexer=LEXER, returnline=True)
assert_equal(exp, obs) assert_equal(exp, obs)
def test_subproc_toks_ls_l_semi_ls_first():
lsdl = 'ls -l'
ls = 'ls'
s = '{0}; {1}'.format(lsdl, ls)
exp = '$[{0}]; {1}'.format(lsdl, ls)
obs = subproc_toks(s, lexer=LEXER, returnline=True)
assert_equal(exp, obs)
def test_subproc_toks_ls_l_semi_ls_first(): def test_subproc_toks_ls_l_semi_ls_first():
lsdl = 'ls -l' lsdl = 'ls -l'
ls = 'ls' ls = 'ls'
@ -85,5 +93,22 @@ def test_subproc_toks_ls_l_semi_ls_second():
obs = subproc_toks(s, lexer=LEXER, mincol=7, returnline=True) obs = subproc_toks(s, lexer=LEXER, mincol=7, returnline=True)
assert_equal(exp, obs) assert_equal(exp, obs)
def test_subproc_hello_mom_first():
fst = "echo 'hello'"
sec = "echo 'mom'"
s = '{0}; {1}'.format(fst, sec)
exp = '$[{0}]; {1}'.format(fst, sec)
obs = subproc_toks(s, lexer=LEXER, maxcol=len(fst)+1, returnline=True)
assert_equal(exp, obs)
def test_subproc_hello_mom_second():
fst = "echo 'hello'"
sec = "echo 'mom'"
s = '{0}; {1}'.format(fst, sec)
exp = '{0}; $[{1}]'.format(fst, sec)
obs = subproc_toks(s, lexer=LEXER, mincol=len(fst), returnline=True)
assert_equal(exp, obs)
if __name__ == '__main__': if __name__ == '__main__':
nose.runmodule() nose.runmodule()

View file

@ -100,11 +100,8 @@ class CtxAwareTransformer(NodeTransformer):
"""Tries to parse the line of the node as a subprocess.""" """Tries to parse the line of the node as a subprocess."""
#spline = subproc_line(self.lines[node.lineno - 1]).lstrip() #spline = subproc_line(self.lines[node.lineno - 1]).lstrip()
line = self.lines[node.lineno - 1] line = self.lines[node.lineno - 1]
mincol = line.rfind(';', 0, node.col_offset-1)
line = line[mincol+1:].lstrip()
mincol = -1
spline = subproc_toks(line, spline = subproc_toks(line,
mincol=mincol, maxcol=node.col_offset,
returnline=False, returnline=False,
lexer=self.parser.lexer).lstrip() lexer=self.parser.lexer).lstrip()
try: try:

View file

@ -126,6 +126,7 @@ class Execer(object):
# lines[idx] = subproc_line(lines[idx]) # lines[idx] = subproc_line(lines[idx])
# input = '\n'.join(lines) # input = '\n'.join(lines)
except SyntaxError as e: except SyntaxError as e:
print(last_error_col, e.loc.column)
if (e.loc is None) or (last_error_line == e.loc.lineno and if (e.loc is None) or (last_error_line == e.loc.lineno and
last_error_col == e.loc.column): last_error_col == e.loc.column):
raise raise
@ -133,8 +134,9 @@ class Execer(object):
last_error_line = e.loc.lineno last_error_line = e.loc.lineno
idx = last_error_line - 1 idx = last_error_line - 1
lines = input.splitlines() lines = input.splitlines()
lines[idx] = subproc_toks(lines[idx], mincol=last_error_col+1, lines[idx] = subproc_toks(lines[idx], maxcol=last_error_col+3,
returnline=True, lexer=self.parser.lexer) returnline=True, lexer=self.parser.lexer)
last_error_col += 3
input = '\n'.join(lines) input = '\n'.join(lines)
print(repr(input)) print(repr(input))
return tree return tree