"""
Testing unbuilding of parameters that are defined as minus a symbolic
reference to another parameter.
"""

from finesse import Model
from finesse.script.generator import KatUnbuilder


def test_unparse_negative_reference_kat():
    """Negative reference defined in katscript."""
    model = Model(
        """
        m m1 phi=22
        m m2 phi=-m1.phi
        """
    )

    unbuilder = KatUnbuilder()
    script = unbuilder.unbuild(model)
    assert "mirror m2 R=0.5 T=0.5 L=0.0 phi=-m1.phi" in script


def test_unparse_negative_reference_python():
    """Negative reference defined in python."""
    model = Model(
        """
        m m1 phi=22
        m m2
        """
    )
    model.m2.phi = -model.m1.phi.ref

    unbuilder = KatUnbuilder()
    script = unbuilder.unbuild(model, prefer_keywords=True)
    assert "mirror m2 R=0.5 T=0.5 L=0.0 phi=-m1.phi" in script
