File: Primitives.py

package info (click to toggle)
plastex 3.1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,132 kB
  • sloc: python: 23,341; xml: 18,076; javascript: 7,755; ansic: 46; makefile: 40; sh: 26
file content (52 lines) | stat: -rw-r--r-- 1,766 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from plasTeX.TeX import TeX
from helpers.utils import compare_output

def test_expandafter():
    compare_output(r'\def\a[#1]{Argument is #1!}\def\args{[FOO]}\expandafter\a\args')

def test_expandafter_undefined():
    compare_output(r'\def\xx{\yy}\expandafter\def\xx{a}\yy')

def test_expandafter_def_csname():
    compare_output(r'\expandafter\def\csname xx\endcsname{a}\xx')

def test_expandafter_let_csname():
    compare_output(r'\expandafter\let\csname xx\endcsname=a\xx')

def test_expandafter_once():
    compare_output(r'\def\a{ab}\def\b{\a}\def\foo#1{#1.}\expandafter\foo\b')

def test_expandafter_non_macro():
    compare_output(r'\def\foo#1{#1.}\expandafter\foo ab')

def test_evil_double_dollars():
    tex = TeX()
    tex.input('$a$$b$')
    nodes = tex.parse().getElementsByTagName('math')
    assert len(nodes) == 2
    assert nodes[0].textContent == 'a'
    assert nodes[1].textContent == 'b'

def test_more_evil_double_dollars():
    tex = TeX()
    tex.input('$a$$$b$$$c$')
    doc = tex.parse()
    mathnodes = doc.getElementsByTagName('math')
    assert len(mathnodes) == 2
    assert mathnodes[0].textContent == 'a'
    assert mathnodes[1].textContent == 'c'
    displaymathnodes = doc.getElementsByTagName('displaymath')
    assert len(displaymathnodes) == 1
    assert displaymathnodes[0].textContent == 'b'

def test_even_more_evil_double_dollars():
    tex = TeX()
    tex.input('$a$$$$$$$b$$')
    doc = tex.parse()
    mathnodes = doc.getElementsByTagName('math')
    assert len(mathnodes) == 1
    assert mathnodes[0].textContent == 'a'
    displaymathnodes = doc.getElementsByTagName('displaymath')
    assert len(displaymathnodes) == 2
    assert displaymathnodes[0].textContent == ''
    assert displaymathnodes[1].textContent == 'b'