def test_detect_function_declaration(): result = parse_element(load_fragment_tag("function.xml")) symbol = result.symbols[0] assert symbol.element.text == "p(x;θ,y)" assert symbol.type_ == "function" assert symbol.start == 0 assert symbol.end == 16 assert ( Token("(", "atom", 1, 2, "<mo>(</mo>", ()) in symbol.tokens ), "function tokens should include parentheses" assert ( Token(")", "atom", 15, 16, "<mo>)</mo>", ()) in symbol.tokens ), "function tokens should include parentheses" assert not any( [t.text == "," for t in symbol.tokens] ), "function tokens should not include commas" assert not any( [t.text == ";" for t in symbol.tokens] ), "function tokens should not include semicolons" child_symbols = symbol.child_symbols assert len(child_symbols) == 8 assert str(child_symbols[0].element) == "<mi>p</mi>" assert str(child_symbols[2].element) == "<mi>x</mi>" assert str(child_symbols[4].element) == "<mi>θ</mi>" assert str(child_symbols[6].element) == "<mi>y</mi>"
def test_parse_accent(): result = parse_element(load_fragment_tag("bar_x.xml")) assert len(result.symbols) == 1 symbol = result.symbols[0] assert str(symbol.element) == '<mover accent="true"><mi>x</mi><mo>ˉ</mo></mover>' assert symbol.contains_affix_token assert symbol.tokens == [ Token("ˉ", "affix", 0, 5, "<mo>ˉ</mo>", ()), Token("x", "atom", 5, 6, "<mi>x</mi>", ()), ]
def test_parse_prime(): result = parse_element(load_fragment_tag("x_prime.xml")) assert len(result.symbols) == 1 symbol = result.symbols[0] assert len(symbol.children) == 2 assert str(symbol.children[0].element) == "<mi>x</mi>" assert symbol.tokens == [ Token("x", "atom", 0, 1, "<mi>x</mi>", ()), Token("′", "atom", 1, 2, "<mo>′</mo>", ()), ]
def test_merge_contiguous_identifiers(): result = parse_element(load_fragment_tag("relu.xml")) symbol = result.symbols[0] assert str(symbol.element) == "<mi>ReLU</mi>" assert symbol.children == [] assert symbol.tokens == [ Token("R", "atom", 0, 1, "<mi>R</mi>", ()), Token("e", "atom", 1, 2, "<mi>e</mi>", ()), Token("L", "atom", 2, 3, "<mi>L</mi>", ()), Token("U", "atom", 3, 4, "<mi>U</mi>", ()), ]
def test_merge_contiguous_styled_identifiers(): result = parse_element(load_fragment_tag("bold_relu.xml")) symbol = result.symbols[0] assert str(symbol.element == '<mi mathvariant="bold">ReLU</mi>') assert symbol.start == 0 assert symbol.end == 13 assert symbol.tokens == [ Token("R", "atom", 8, 9, '<mi mathvariant="bold">R</mi>', ("mathbf",)), Token("e", "atom", 9, 10, '<mi mathvariant="bold">e</mi>', ("mathbf",)), Token("L", "atom", 10, 11, '<mi mathvariant="bold">L</mi>', ("mathbf",)), Token("U", "atom", 11, 12, '<mi mathvariant="bold">U</mi>', ("mathbf",)), ]
def test_parse_node_with_child_nodes(): result = parse_element(load_fragment_tag("x_sub_i.xml")) symbol = result.symbols[0] assert str(symbol.element) == "<msub><mi>x</mi><mi>i</mi></msub>" assert len(symbol.children) == 2 assert symbol.start == 0 assert symbol.end == 3 assert str(symbol.children[0].element) == "<mi>x</mi>" assert str(symbol.children[1].element) == "<mi>i</mi>" assert symbol.tokens == [ Token("x", "atom", 0, 1, "<mi>x</mi>", ()), Token("i", "atom", 2, 3, "<mi>i</mi>", ()), ]
def test_parse_single_symbol(): result = parse_element(load_fragment_tag("x.xml")) assert len(result.symbols) == 1 symbol = result.symbols[0] assert str(symbol.element) == "<mi>x</mi>" assert symbol.type_ == "identifier" assert symbol.children == [] assert symbol.tokens == [Token("x", "atom", 0, 1, "<mi>x</mi>", ())] assert symbol.start == 0 assert symbol.end == 1 assert not symbol.defined assert not symbol.contains_affix_token