Skip to content

Adding roundtrip for nested processing #140

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
lorenzwalthert opened this issue Aug 20, 2017 · 10 comments
Closed

Adding roundtrip for nested processing #140

lorenzwalthert opened this issue Aug 20, 2017 · 10 comments

Comments

@lorenzwalthert
Copy link
Collaborator

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
}
@lorenzwalthert
Copy link
Collaborator Author

Reference: #85.

@lorenzwalthert
Copy link
Collaborator Author

Related: #216.

@lorenzwalthert
Copy link
Collaborator Author

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.

@krlmlr
Copy link
Member

krlmlr commented Oct 31, 2017

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.

@lorenzwalthert
Copy link
Collaborator Author

lorenzwalthert commented Nov 3, 2017

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

@krlmlr
Copy link
Member

krlmlr commented Nov 4, 2017

Sure.

@lorenzwalthert
Copy link
Collaborator Author

Reference: #280.

@krlmlr
Copy link
Member

krlmlr commented Feb 28, 2018

Have we implemented roundtrip checking by now?

@lorenzwalthert
Copy link
Collaborator Author

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

@lorenzwalthert
Copy link
Collaborator Author

Reference: #368.

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

No branches or pull requests

2 participants