Skip to content

Commit

Permalink
Fix #107: Cursor is reset to position 0
Browse files Browse the repository at this point in the history
  • Loading branch information
eliangcs committed Feb 13, 2017
1 parent 33ac125 commit 6fc961c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
2 changes: 1 addition & 1 deletion http_prompt/lexer.py
Expand Up @@ -155,7 +155,7 @@ class HttpPromptLexer(RegexLexer):

(r"(')((?:[^\r\n'\\=:]|(?:\\.))+)", bygroups(Text, String)),

(r'([^\-](?:[^\s"\'\\=:]|(\\.))+)(\s+|$)',
(r'([^\-](?:[^\s"\'\\=:]|(?:\\.))+)(\s+|$)',
bygroups(String, Text),
combined('concat_mut', 'redir_out', 'pipe')),

Expand Down
32 changes: 26 additions & 6 deletions tests/test_lexer.py
Expand Up @@ -10,12 +10,12 @@ class LexerTestCase(unittest.TestCase):
def setUp(self):
self.lexer = HttpPromptLexer()

def get_tokens(self, text):
tokens = []
for ttype, value in self.lexer.get_tokens(text):
if value.strip():
tokens.append((ttype, value))
return tokens
def get_tokens(self, text, filter_spaces=True):
tokens = self.lexer.get_tokens(text)
tokens = filter(lambda t: t[1], tokens)
if filter_spaces:
tokens = filter(lambda t: t[1].strip(), tokens)
return list(tokens)


class TestLexer_mutation(LexerTestCase):
Expand Down Expand Up @@ -402,6 +402,16 @@ def test_httpie_options(self):
(String, 'test'), (Name, '--body')
])

def test_httpie_relative_path(self):
tokens = self.get_tokens('httpie /api/test name==foo',
filter_spaces=False)
self.assertEqual(tokens, [
(Keyword, 'httpie'), (Text, ' '),
(String, '/api/test'), (Text, ' '),
(Name, 'name'), (Operator, '=='), (String, 'foo'),
(Text, '\n')
])


class TestShellCode(LexerTestCase):

Expand Down Expand Up @@ -674,6 +684,16 @@ def test_options(self):
(Keyword, 'options')
])

def test_post_relative_path(self):
tokens = self.get_tokens('post /api/test name=foo',
filter_spaces=False)
self.assertEqual(tokens, [
(Keyword, 'post'), (Text, ' '),
(String, '/api/test'), (Text, ' '),
(Name, 'name'), (Operator, '='), (String, 'foo'),
(Text, '\n')
])


class TestLexerActionRedirection(LexerTestCase):

Expand Down

0 comments on commit 6fc961c

Please sign in to comment.