test_latex.py
65 lines
| 2.1 KiB
| text/x-python
|
PythonLexer
Jonathan Frederic
|
r11902 | """ | ||
Module with tests for Latex | ||||
""" | ||||
#----------------------------------------------------------------------------- | ||||
# Copyright (c) 2013, the IPython Development Team. | ||||
# | ||||
# Distributed under the terms of the Modified BSD License. | ||||
# | ||||
# The full license is in the file COPYING.txt, distributed with this software. | ||||
#----------------------------------------------------------------------------- | ||||
#----------------------------------------------------------------------------- | ||||
# Imports | ||||
#----------------------------------------------------------------------------- | ||||
from ...tests.base import TestsBase | ||||
Jonathan Frederic
|
r11928 | from ..latex import escape_latex, strip_math_space | ||
Jonathan Frederic
|
r11902 | |||
#----------------------------------------------------------------------------- | ||||
# Class | ||||
#----------------------------------------------------------------------------- | ||||
class TestLatex(TestsBase): | ||||
def test_escape_latex(self): | ||||
Jonathan Frederic
|
r11934 | """escape_latex test""" | ||
Jonathan Frederic
|
r11902 | tests = [ | ||
(r'How are \you doing today?', r'How are \textbackslashyou doing today?'), | ||||
(r'\escapechar=`\A\catcode`\|=0 |string|foo', r'\textbackslashescapechar=`\textbackslashA\textbackslashcatcode`\textbackslash|=0 |string|foo'), | ||||
(r'# $ % & ~ _ ^ \ { }',r'\# \$ \% \& \~{} \_ \^{} \textbackslash \{ \}'), | ||||
('','')] | ||||
for test in tests: | ||||
Jonathan Frederic
|
r11936 | yield self._try_escape_latex(test[0], test[1]) | ||
Jonathan Frederic
|
r11902 | |||
def _try_escape_latex(self, test, result): | ||||
Jonathan Frederic
|
r11934 | """Try to remove latex from string""" | ||
Jonathan Frederic
|
r11936 | self.assertEqual(escape_latex(test), result) | ||
Jonathan Frederic
|
r11902 | |||
def test_strip_math_space(self): | ||||
Jonathan Frederic
|
r11934 | """strip_math_space test""" | ||
Jonathan Frederic
|
r11902 | tests = [ | ||
('$e$','$e$'), | ||||
('$ e $','$e$'), | ||||
('xxx$e^i$yyy','xxx$e^i$yyy'), | ||||
('xxx$ e^i $yyy','xxx$e^i$yyy'), | ||||
('xxx$e^i $yyy','xxx$e^i$yyy'), | ||||
('xxx$ e^i$yyy','xxx$e^i$yyy'), | ||||
('\$ e $ e $','\$ e $e$'), | ||||
('','')] | ||||
for test in tests: | ||||
Jonathan Frederic
|
r11936 | yield self._try_strip_math_space(test[0], test[1]) | ||
Jonathan Frederic
|
r11902 | |||
def _try_strip_math_space(self, test, result): | ||||
""" | ||||
Try to remove spaces between dollar symbols and contents correctly | ||||
""" | ||||
Jonathan Frederic
|
r11936 | self.assertEqual(strip_math_space(test), result) | ||