Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6c61004

Browse files
committed
add three tests for cell magic syntax highlighting
1 parent 0d71ec6 commit 6c61004

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

IPython/lib/tests/test_lexers.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,50 @@ def testIPythonLexer(self):
127127
(Token.Text, '\n'),
128128
]
129129
self.assertEqual(tokens, list(self.lexer.get_tokens(fragment)))
130+
131+
fragment = '%%writefile -a foo.py\nif a == b:\n pass'
132+
tokens = [
133+
(Token.Operator, '%%writefile'),
134+
(Token.Text, ' -a foo.py\n'),
135+
(Token.Keyword, 'if'),
136+
(Token.Text, ' '),
137+
(Token.Name, 'a'),
138+
(Token.Text, ' '),
139+
(Token.Operator, '=='),
140+
(Token.Text, ' '),
141+
(Token.Name, 'b'),
142+
(Token.Punctuation, ':'),
143+
(Token.Text, '\n'),
144+
(Token.Text, ' '),
145+
(Token.Keyword, 'pass'),
146+
(Token.Text, '\n'),
147+
]
148+
self.assertEqual(tokens, list(self.lexer.get_tokens(fragment)))
149+
150+
fragment = '%%timeit\nmath.sin(0)'
151+
tokens = [
152+
(Token.Operator, '%%timeit\n'),
153+
(Token.Name, 'math'),
154+
(Token.Operator, '.'),
155+
(Token.Name, 'sin'),
156+
(Token.Punctuation, '('),
157+
(Token.Literal.Number.Integer, '0'),
158+
(Token.Punctuation, ')'),
159+
(Token.Text, '\n'),
160+
]
161+
162+
fragment = '%%HTML\n<div>foo</div>'
163+
tokens = [
164+
(Token.Operator, '%%HTML'),
165+
(Token.Text, '\n'),
166+
(Token.Punctuation, '<'),
167+
(Token.Name.Tag, 'div'),
168+
(Token.Punctuation, '>'),
169+
(Token.Text, 'foo'),
170+
(Token.Punctuation, '<'),
171+
(Token.Punctuation, '/'),
172+
(Token.Name.Tag, 'div'),
173+
(Token.Punctuation, '>'),
174+
(Token.Text, '\n'),
175+
]
176+
self.assertEqual(tokens, list(self.lexer.get_tokens(fragment)))

0 commit comments

Comments
 (0)