def testTokenArgument(self): s = TeX() s.input(r'\foo a ') arg = s.readArgument(type='Tok') assert arg == 'foo' arg = s.readArgument(type='Tok') assert arg == 'a'
def testTeXDimen2(self): s = TeX() s.input(r'''\newcount\mycount\mycount=120 \newdimen\mydimen\mydimen=12sp \newskip\myglue\myglue=10sp plus1pt minus2pt''') s.parse() value = s.ownerDocument.context['mycount'].value assert value == count(120), value value = s.ownerDocument.context['mydimen'].value assert value == dimen('12sp'), value value = s.ownerDocument.context['myglue'].value assert value == glue('10sp', plus='1pt', minus='2pt'), value # Literal dimension s.input(r'3.5pt') arg = s.readArgument(type='Dimen') assert arg == dimen('3.5pt'), arg # Literal dimension, {...} aren't allowed s.input(r'{3.5pt}') arg = s.readArgument(type='Dimen') assert arg == dimen(0), arg # Set by other dimension s.input(r'\mydimen') arg = s.readArgument(type='Dimen') assert arg == dimen('12sp'), arg # Set by count s.input(r'\mycount') arg = s.readArgument(type='Dimen') assert arg == dimen('120sp'), arg assert ParameterCommand._enablelevel == 0
def testTeXDimen(self): s = TeX() s.input(r'''\newcount\mycount\mycount=120 \newdimen\mydimen\mydimen=12sp \newskip\myglue\myglue=10sp plus1pt minus2pt''') s.parse() value = s.ownerDocument.context['mycount'].value assert value == count(120), value value = s.ownerDocument.context['mydimen'].value assert value == dimen('12sp'), value value = s.ownerDocument.context['myglue'].value assert value == glue('10sp', plus='1pt', minus='2pt'), value # Literal dimension s.input(r'3.5pt') arg = s.readArgument(type='Dimen') assert arg == dimen('3.5pt'), arg # Literal dimension, {...} aren't allowed s.input(r'{3.5pt}') arg = s.readArgument(type='Dimen') assert arg == dimen(0), arg # Set by other dimension s.input(r'\mydimen') arg = s.readArgument(type='Dimen') assert arg == dimen('12sp'), arg # Set by count s.input(r'\mycount') arg = s.readArgument(type='Dimen') assert arg == dimen('120sp'), arg assert ParameterCommand._enablelevel == 0
def testTeXNumber(self): s = TeX() s.input(r'''\newcount\mycount\mycount=120 \newdimen\mydimen\mydimen=12sp \newskip\myglue\myglue=10sp plus1pt minus2pt''') s.parse() value = s.ownerDocument.context['mycount'].value assert value == count(120), value value = s.ownerDocument.context['mydimen'].value assert value == dimen('12sp'), value value = s.ownerDocument.context['myglue'].value assert value == glue('10sp', plus='1pt', minus='2pt'), value # Literal number s.input('100') arg = s.readArgument(type='Number') assert arg == count('100'), arg # Set by other dimen s.input(r'\mycount') arg = s.readArgument(type='Number') assert arg == count('120'), arg # Multiply by other dimen s.input(r'3\mycount') arg = s.readArgument(type='Number') assert arg == count('360'), arg # No number s.input('{0}') arg = s.readArgument(type='Number') assert arg == count(0), arg assert ParameterCommand._enablelevel == 0
def testXTokenArgument(self): s = TeX() s.input(r'\newcommand{\foo}{\it}') [x for x in s] s.input(r'\foo a ') arg = s.readArgument(type='XTok') assert arg.nodeName == 'it', arg.nodeName arg = s.readArgument(type='XTok') assert arg == 'a', arg
def testStringSourceArgument(self): s = TeX() s.input(r'{With \$ and \%}') arg = s.readArgument(type='str', subtype='source') assert_that( arg, is_( 'With $ and %' ) ) s = TeX() s.input(r'<With \$ and \%>') arg = s.readArgument(spec="<>", expanded=True, delim=None, type='str', subtype='source') assert_that( arg, is_( 'With $ and %' ) )
def testNumber(self): s = TeX() s.input(r'''\newcount\mycount\mycount=120 \newdimen\mydimen\mydimen=12sp \newskip\myglue\myglue=10sp plus1pt minus2pt''') s.parse() value = s.ownerDocument.context['mycount'].value assert value == count(120), value value = s.ownerDocument.context['mydimen'].value assert value == dimen('12sp'), value value = s.ownerDocument.context['myglue'].value assert value == glue('10sp', plus='1pt', minus='2pt'), value # Literal number, this will only parse the `1` s.input('100') arg = s.readArgument(type='number') assert arg == count(1), arg # Literal number s.input('{100}') arg = s.readArgument(type='number') assert arg == count(100), arg # Set by other number s.input(r'\mycount') arg = s.readArgument(type='number') assert arg == count(120), arg # Set by other number s.input(r'{\mycount}') arg = s.readArgument(type='number') assert arg == count(120), arg # Multiply by other number s.input(r'{5\mycount}') arg = s.readArgument(type='number') assert arg == count(600), arg # No number s.input('{a}') arg = s.readArgument(type='number') assert arg == count(0), arg # No number s.input('b') arg = s.readArgument(type='number') assert arg == count(0), arg # Coerced dimen s.input(r'{\mydimen}') arg = s.readArgument(type='number') assert arg == count(12), arg # Coerced glue s.input(r'{\myglue}') arg = s.readArgument(type='number') assert arg == count(10), arg assert ParameterCommand._enablelevel == 0
def testStringSourceArgument(self): s = TeX() s.input(r'{With \$ and \%}') arg = s.readArgument(type='str', subtype='source') assert_that(arg, is_('With $ and %')) s = TeX() s.input(r'<With \$ and \%>') arg = s.readArgument(spec="<>", expanded=True, delim=None, type='str', subtype='source') assert_that(arg, is_('With $ and %'))
def testDictArgument2(self): s = TeX() s.input(r'{one=1, two={\par}, three={$(x,y)$}, four=4}') arg = s.readArgument(type='dict') keys = list(arg.keys()) keys.sort() expectkeys = ['four', 'one', 'three', 'two'] assert keys == expectkeys, '"%s" != "%s"' % (keys, expectkeys) assert arg['one'] == '1' assert arg['four'] == '4'
def testListTypes(self): s = TeX() s.input(r'''\newcount\mycount\mycount=120 \newdimen\mydimen\mydimen=12sp \newskip\myglue\myglue=10sp plus1pt minus2pt''') s.parse() s.input(r'{1, \mycount, 3}') arg = s.readArgument(type='list', subtype='int') assert arg == [1, 120, 3], arg
def testDictArgument2(self): s = TeX() s.input(r'{one=1, two={\par}, three={$(x,y)$}, four=4}') arg = s.readArgument(type='dict') keys = list(arg.keys()) keys.sort() expectkeys = ['four','one','three','two'] assert keys == expectkeys, '"%s" != "%s"' % (keys, expectkeys) assert arg['one'] == '1' assert arg['four'] == '4'
def testDictTypes(self): s = TeX() s.input(r'''\newcount\mycount\mycount=120 \newdimen\mydimen\mydimen=12sp \newskip\myglue\myglue=10sp plus1pt minus2pt''') s.parse() s.input(r'{one=1, two={\mycount} , three={3}}') arg = s.readArgument(type='dict', expanded=True) keys = list(arg.keys()) keys.sort() assert keys == ['one', 'three', 'two']
def testIntegerArgument(self): s = TeX() s.input('{1{0}2}') arg = s.readArgument(type='int') output = 102 assert arg == output, '"%s" != "%s"' % (arg, output)
def testStringArgument(self): s = TeX() s.input('{foo {bar} one}') arg = s.readArgument(type='str') output = 'foo bar one' assert arg == output, '"%s" != "%s"' % (arg, output)
def testFloatArgument(self): s = TeX() s.input('{ -1{0}2.67 }') arg = s.readArgument(type='float') output = -102.67 assert (output - arg) < 0.000001, '"%s" != "%s"' % (arg, output)
def testListArgument2(self): s = TeX() s.input('{foo; {bar}; one}') arg = s.readArgument(type='list', delim=';') output = ['foo', 'bar', 'one'] assert arg == output, '"%s" != "%s"' % (arg, output)
def testDictArgument(self): s = TeX() s.input('{one=1, two={2}, three=3}') arg = s.readArgument(type='dict') output = {'one': '1', 'two': '2', 'three': '3'} assert arg == output, '"%s" != "%s"' % (arg, output)
def testDictArgument(self): s = TeX() s.input('{one=1, two={2}, three=3}') arg = s.readArgument(type='dict') output = {'one':'1', 'two':'2', 'three':'3'} assert arg == output, '"%s" != "%s"' % (arg, output)
def testListArgument2(self): s = TeX() s.input('{foo; {bar}; one}') arg = s.readArgument(type='list', delim=';') output = ['foo','bar','one'] assert arg == output, '"%s" != "%s"' % (arg, output)
def testIntegerArgument2(self): s = TeX() s.input('{ -1{0}2.67 }') arg = s.readArgument(type='float') output = -102.67 assert (output - arg) < 0.000001, '"%s" != "%s"' % (arg, output)