Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_marg_1(self):
lw = latexwalker.LatexWalker(r'\cmd ab')
s = MacroStandardArgsParser('{')
parsing_state = lw.make_parsing_state()
(argd, p, l) = s.parse_args(lw, len(r'\cmd'), parsing_state=parsing_state)
self.assertPMAEqual(
argd,
ParsedMacroArgs(argspec='{', argnlist=[
LatexCharsNode(parsing_state=parsing_state,
chars='a',
pos=len(r'\cmd')+1,len=1)
])
def test_marg_0(self):
lw = latexwalker.LatexWalker(r'{ab}')
s = MacroStandardArgsParser('{')
parsing_state = lw.make_parsing_state()
(argd, p, l) = s.parse_args(lw, 0, parsing_state=parsing_state)
self.assertPMAEqual(
argd,
ParsedMacroArgs(
argspec='{',
argnlist=[ LatexGroupNode(
parsing_state=parsing_state,
delimiters=('{','}'),
nodelist=[
LatexCharsNode(parsing_state=parsing_state,
chars='ab',
pos=1,len=2)
],
pos=0,len=4)
])
def test_star_1(self):
lw = latexwalker.LatexWalker(r'\cmd* xyz')
s = MacroStandardArgsParser('*')
parsing_state = lw.make_parsing_state()
(argd, p, l) = s.parse_args(lw, len(r'\cmd'), parsing_state=parsing_state)
self.assertPMAEqual(
argd,
ParsedMacroArgs(argspec='*', argnlist=[
LatexCharsNode(parsing_state=parsing_state,
chars='*',
pos=4,len=1)
])
def test_star_0(self):
lw = latexwalker.LatexWalker(r'\cmd xyz')
s = MacroStandardArgsParser('*')
(argd, p, l) = s.parse_args(lw, len(r'\cmd'))
self.assertPMAEqual(
argd,
ParsedMacroArgs(argspec='*', argnlist=[ None ])
)
def test_star_2(self):
lw = latexwalker.LatexWalker(r'\cmd * xyz')
s = MacroStandardArgsParser('*')
parsing_state = lw.make_parsing_state()
(argd, p, l) = s.parse_args(lw, len(r'\cmd'), parsing_state=parsing_state)
self.assertPMAEqual(
argd,
ParsedMacroArgs(argspec='*', argnlist=[
LatexCharsNode(parsing_state=parsing_state,
chars='*',
pos=5,len=1)
])
def test_error_dangling_missing_args_2(self):
latextext = r'''Test _''' # missing underscore arguments
latex_context = get_default_latex_context_db()
latex_context.add_context_category('custom-category', prepend=True, specials=[
macrospec.SpecialsSpec('_', args_parser=macrospec.MacroStandardArgsParser('{'))
])
lw = LatexWalker(latextext, latex_context=latex_context, tolerant_parsing=False)
parsing_state = lw.make_parsing_state()
with self.assertRaises(LatexWalkerParseError):
lw.get_latex_nodes(parsing_state=parsing_state)
def test_combined_0(self):
lw = latexwalker.LatexWalker(r'\cmd{ab}c*')
s = MacroStandardArgsParser('{*[{*')
parsing_state = lw.make_parsing_state()
(argd, p, l) = s.parse_args(lw, len(r'\cmd'), parsing_state=parsing_state)
self.assertPMAEqual(
argd,
ParsedMacroArgs(argspec='{*[{*', argnlist=[
LatexGroupNode(parsing_state=parsing_state,
delimiters=('{', '}'),
nodelist=[
LatexCharsNode(parsing_state=parsing_state,
chars='ab',
pos=5,len=2)
],
pos=4,len=4),
None,
None,
LatexCharsNode(parsing_state=parsing_state,
def test_oarg_1(self):
lw = latexwalker.LatexWalker(r'\cmd xyz')
s = MacroStandardArgsParser('[')
(argd, p, l) = s.parse_args(lw, len(r'\cmd'))
self.assertPMAEqual(
argd,
ParsedMacroArgs(argspec='[', argnlist=[ None ])
)
std_macro('provideenvironment', "*{[[{{"),
std_macro('DeclareMathOperator', '*{{'),
std_macro('hspace', '*{'),
std_macro('vspace', '*{'),
MacroSpec('mbox', args_parser=MacroStandardArgsParser('{', args_math_mode=[False])),
# (Note: single backslash) end of line with optional no-break ('*') and
# additional vertical spacing, e.g. \\*[2mm]
#
# Special for this command: don't allow an optional spacing argument
# to be on a new line. This emulates the behavior in AMS
# environments.
MacroSpec('\\', args_parser=MacroStandardArgsParser('*[', optional_arg_no_space=True)),
std_macro('item', True, 0),
# \input{someotherfile}
std_macro('input', False, 1),
std_macro('include', False, 1),
std_macro('includegraphics', True, 1),
std_macro('chapter', '*[{'),
std_macro('section', '*[{'),
std_macro('subsection', '*[{'),
std_macro('subsubsection', '*[{'),
std_macro('pagagraph', '*[{'),
std_macro('subparagraph', '*[{'),
std_macro('addlength', True, 2),
std_macro('setcounter', True, 2),
std_macro('addcounter', True, 2),
std_macro('newcommand', "*{[[{"),
std_macro('renewcommand', "*{[[{"),
std_macro('providecommand', "*{[[{"),
std_macro('newenvironment', "*{[[{{"),
std_macro('renewenvironment', "*{[[{{"),
std_macro('provideenvironment', "*{[[{{"),
std_macro('DeclareMathOperator', '*{{'),
std_macro('hspace', '*{'),
std_macro('vspace', '*{'),
MacroSpec('mbox', args_parser=MacroStandardArgsParser('{', args_math_mode=[False])),
# (Note: single backslash) end of line with optional no-break ('*') and
# additional vertical spacing, e.g. \\*[2mm]
#
# Special for this command: don't allow an optional spacing argument
# to be on a new line. This emulates the behavior in AMS
# environments.
MacroSpec('\\', args_parser=MacroStandardArgsParser('*[', optional_arg_no_space=True)),
std_macro('item', True, 0),
# \input{someotherfile}
std_macro('input', False, 1),
std_macro('include', False, 1),
std_macro('includegraphics', True, 1),