File: test_superscript_subscript.py

package info (click to toggle)
plots 0.8.5%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,612 kB
  • sloc: python: 3,247; xml: 443; sh: 26; makefile: 6
file content (94 lines) | stat: -rw-r--r-- 3,290 bytes parent folder | download
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# Copyright 2021 Alexander Huntley

# This file is part of Plots.

# Plots is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# Plots is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with Plots.  If not, see <https://www.gnu.org/licenses/>.

from plots.parser import from_latex
from plots.utils import Direction
import plots.formula as f

from tests.fixtures import cursor

def test_insert_empty_super(cursor):
    elems = from_latex("x")
    cursor.reparent(elems, -1)
    cursor.insert_superscript_subscript()
    assert elems.to_latex() == r"x^{}"
    assert cursor.owner is elems[1].exponent

def test_add_to_super_after(cursor):
    elems = from_latex("x^{2}2")
    cursor.reparent(elems, -1)
    cursor.handle_movement(Direction.LEFT, select=True)
    cursor.insert_superscript_subscript()
    assert elems.to_latex() == "x^{22}"
    assert cursor.owner is elems[1].exponent

def test_add_to_super_after_alternative(cursor):
    elems = from_latex("x^{2}2")
    cursor.reparent(elems, 2)
    cursor.handle_movement(Direction.RIGHT, select=True)
    cursor.insert_superscript_subscript()
    assert elems.to_latex() == "x^{22}"
    assert cursor.owner is elems[1].exponent

def test_add_to_super_before(cursor):
    elems = from_latex("xy^{z}")
    cursor.reparent(elems, 1)
    cursor.handle_movement(Direction.RIGHT, select=True)
    cursor.insert_superscript_subscript()
    assert elems.to_latex() == "x^{yz}"
    assert cursor.owner is elems[1].exponent

def test_add_to_super_before_alternative(cursor):
    elems = from_latex("xy^{z}")
    cursor.reparent(elems, 2)
    cursor.handle_movement(Direction.LEFT, select=True)
    cursor.insert_superscript_subscript()
    assert elems.to_latex() == "x^{yz}"
    assert cursor.owner is elems[1].exponent

def test_move_to_super_before(cursor):
    elems = from_latex("x^{2}")
    cursor.reparent(elems, 1)
    cursor.insert_superscript_subscript()
    assert elems.to_latex() == "x^{2}"
    assert cursor.owner is elems[1].exponent

def test_delete_super(cursor):
    elems = from_latex("x_{4}^{3}")
    cursor.reparent(elems[1].exponent, 0)
    cursor.backspace(Direction.LEFT)
    assert elems.to_latex() == "x_{4}3"

def test_delete_sub(cursor):
    elems = from_latex("x_{4}^{3}")
    cursor.reparent(elems[1].subscript, 0)
    cursor.backspace(Direction.LEFT)
    assert elems.to_latex() == "x4^{3}"

def test_add_sub_to_super(cursor):
    elems = from_latex("x^{3}")
    cursor.reparent(elems, -1)
    cursor.insert_superscript_subscript(superscript=False)
    assert elems.to_latex() == "x_{}^{3}"
    assert cursor.owner is elems[1].subscript

def test_add_super_to_sub(cursor):
    elems = from_latex("x_{3}")
    cursor.reparent(elems, -1)
    cursor.insert_superscript_subscript(superscript=True)
    assert elems.to_latex() == "x_{3}^{}"
    assert cursor.owner is elems[1].exponent