From 09a21620b1873f9b38dffaf3ecfed111e373800c 2015-01-25 18:00:47 From: Lev Abalkin Date: 2015-01-25 18:00:47 Subject: [PATCH] #7548: Fixed handling of != operator. Added tests. --- diff --git a/IPython/nbconvert/utils/lexers.py b/IPython/nbconvert/utils/lexers.py index 652d2f1..427e1b8 100644 --- a/IPython/nbconvert/utils/lexers.py +++ b/IPython/nbconvert/utils/lexers.py @@ -57,7 +57,7 @@ ipython_tokens = [ using(BashLexer), Text)), (r'(%)(\w+)(.*\n)', bygroups(Operator, Keyword, Text)), (r'^(!!)(.+)(\n)', bygroups(Operator, using(BashLexer), Text)), - (r'((?!=)!)(.+)(\n)', bygroups(Operator, using(BashLexer), Text)), + (r'(!)(?!=)(.+)(\n)', bygroups(Operator, using(BashLexer), Text)), (r'^(\s*)(\?\??)(\s*%{0,2}[\w\.\*]*)', bygroups(Text, Operator, Text)), ] diff --git a/IPython/nbconvert/utils/tests/test_lexers.py b/IPython/nbconvert/utils/tests/test_lexers.py index a18f892..91a090e 100644 --- a/IPython/nbconvert/utils/tests/test_lexers.py +++ b/IPython/nbconvert/utils/tests/test_lexers.py @@ -109,3 +109,23 @@ class TestLexers(TestsBase): (Token.Text, '\n'), ] self.assertEqual(tokens_2, list(self.lexer.get_tokens(fragment_2))) + + fragment_2 = 'x != y\n' + tokens_2 = [ + (Token.Name, 'x'), + (Token.Text, ' '), + (Token.Operator, '!='), + (Token.Text, ' '), + (Token.Name, 'y'), + (Token.Text, '\n'), + ] + self.assertEqual(tokens_2, list(self.lexer.get_tokens(fragment_2))) + + fragment_2 = ' ?math.sin\n' + tokens_2 = [ + (Token.Text, ' '), + (Token.Operator, '?'), + (Token.Text, 'math.sin'), + (Token.Text, '\n'), + ] + self.assertEqual(tokens_2, list(self.lexer.get_tokens(fragment_2)))