def test_program_to_lispress_with_quotes_inside_string():
    # a string with a double-quote in it
    v, _ = mk_value_op(value='i got quotes"', schema="String", idx=0)
    program = Program(expressions=[v])
    rendered_lispress = render_pretty(program_to_lispress(program))
    assert rendered_lispress == '(#(String "i got quotes\\""))'
    round_tripped, _ = lispress_to_program(parse_lispress(rendered_lispress), 0)
    assert round_tripped == program
def test_surface_to_sexp_round_trips():
    """
    Tests that parsing a Lispress surface string into an S-expression
    and then pretty printing it is a no-op.
    """
    for surface_string in surface_strings:
        surface_string = surface_string.strip()
        lispress = parse_lispress(surface_string)
        round_tripped_surface_string = render_pretty(lispress)
        assert round_tripped_surface_string == surface_string
def test_surface_to_program_round_trips():
    """
    Goes all the way to `Program` and so is stricter
    than `test_surface_to_sexp_round_trips`.
    """
    for surface_string in surface_strings:
        surface_string = surface_string.strip()
        sexp = parse_lispress(surface_string)
        program, _ = lispress_to_program(sexp, 0)
        round_tripped_sexp = program_to_lispress(program)
        round_tripped_surface_string = render_pretty(round_tripped_sexp, max_width=60)
        assert round_tripped_surface_string == surface_string
def _try_round_trip(lispress_str: str) -> str:
    """
    If `lispress_str` is valid lispress, round-trips it to and from `Program`.
    This puts named arguments in alphabetical order.
    If it is not valid, returns the original string unmodified.
    """
    try:
        # round-trip to canonicalize
        lispress = parse_lispress(lispress_str)
        program, _ = lispress_to_program(lispress, 0)
        round_tripped = program_to_lispress(program)
        return render_compact(round_tripped)
    except Exception:  # pylint: disable=W0703
        return lispress_str
 def program(self) -> Program:
     program, _ = lispress_to_program(parse_lispress(self.lispress), idx=0)
     return program
 def tokenized_lispress(self) -> List[str]:
     return lispress_to_seq(parse_lispress(self.lispress))