Skip to content

Adding roundtrip for nested processing #140

Closed

Description

@lorenzwalthert

Might be implemented similar to depreciated flat roundtrip

#' Verify parse data modifications
#'
#' @description Check whether serializing the parse data results in the same
#' number of lines as the initial data that should be styled.
#' @param pd_flat A parse table.
#' @param text A character vector with the initial text to compare against.
#' @return If the verification is successful, `pd` is returned, with empty
#'   lines at the end of `text` stripped. \cr
#'   Otherwise, an error is thrown.
#' @seealso [serialize_parse_data_flat()]
verify_roundtrip <- function(pd_flat, text) {
  roundtrip <- serialize_parse_data_flat(pd_flat)

  if (length(roundtrip) < length(text)) {
    stopifnot(text[-seq_along(roundtrip)] == "")
    text <- text[seq_along(roundtrip)]
  }

  stopifnot(identical(text, roundtrip))
  text
}

Activity

  1. lorenzwalthert commented on Sep 21, 2017

    @lorenzwalthert
    CollaboratorAuthor

    Reference: #85.

  2. lorenzwalthert commented on Sep 23, 2017

    @lorenzwalthert
    CollaboratorAuthor

    Related: #216.

  3. lorenzwalthert commented on Oct 29, 2017

    @lorenzwalthert
    CollaboratorAuthor

    I wonder how that should be implemented. Because with reference to #85, I think it would make sense to not just test parsing and serialising (because that almost certainly works now), but also whether the code is still valid after tokens were inserted, compare #259. So a simple parse statement of the output could check that.

  4. krlmlr commented on Oct 31, 2017

    @krlmlr
    Member

    I think there are multiple layers of roundtrip testing:

    • At the text level: parse + nest + serialize should give exactly the same output (minus tabs to spaces conversion)
    • At the code level: styling with any scope below "token" should lead to identical results (language objects or call trees) after parsing
    • At the semantic level: styling with scope "token" should not change semantics of the code

    The first two can be tested automatically, for the third we need tests with good coverage and rely on the user. We still could test that the resulting code is parseable, but this doesn't buy us much.

  5. lorenzwalthert commented on Nov 3, 2017

    @lorenzwalthert
    CollaboratorAuthor

    Can we label this with "Status: Postponed" and close it for now?

  6. krlmlr commented on Nov 4, 2017

    @krlmlr
    Member

    Sure.

  7. lorenzwalthert commented on Nov 21, 2017

    @lorenzwalthert
    CollaboratorAuthor

    Reference: #280.

  8. krlmlr commented on Feb 28, 2018

    @krlmlr
    Member

    Have we implemented roundtrip checking by now?

  9. lorenzwalthert commented on Feb 28, 2018

    @lorenzwalthert
    CollaboratorAuthor

    In #287, we implemented verifying whenever possible (can_verify_roundtrip), which seems to be the case whenever we don't have any token manipulators.

  10. lorenzwalthert commented on Mar 13, 2018

    @lorenzwalthert
    CollaboratorAuthor

    Reference: #368.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions