Skip to content
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

Tool wanted: Compare stream. #8

Open
martinheidegger opened this issue Nov 8, 2015 · 3 comments
Open

Tool wanted: Compare stream. #8

martinheidegger opened this issue Nov 8, 2015 · 3 comments

Comments

@martinheidegger
Copy link
Contributor

martinheidegger commented Nov 8, 2015

I came to have the opinion that the important code written for the workshoppers is obfuscated by workshopper-exercise and adventure in different ways but both hang on the same issue: They try to take the work of "comparing output of executed code for you". Now I think that it would be cleanest to get a tool that would do nothing else but compare two streams and end with an error or regular message.

I imagine the API for workshoppers like this:

var submissionStream = /* ... */
if (mode === "verify") {
   var solutionStream = /* ... */
   compareStream({actual: __('{compare.actual}'), expected: __('{compare.expected}')
   }, submissionStream, solutionStream, callback)
} else {
  callback(null, submissionStream)
}

And the API for the compare should tool like this:

var options =  {
  actual: String // The title to be shown for the actual section
  expected: String // The title to be shown for the expected section
}

function callback(err, compared) {
  if (err) {
     // true if 
  }
  compared // Markdown table with the differences highlighted as ``**`` bold ``**`` 
}

var stream = compareStream(options, streamA, streamB, callback); 

The output should be

| {compare.actual} | {compare.expected} |
|---|---|
| line1 | line1 |
| *L*ine2 | *l*ine2 |
| line3 | line3 |
| **line4** | __EOF__ |

Note: If one stream has less lines than the other it should write __EOF__ to indicate that the file ended.

This could replace the way we do comparison now. Anyone up for that?

@a0viedo
Copy link
Member

a0viedo commented Mar 25, 2016

maybe @maxogden or @mafintosh know some tool that could apply for the use case

@martinheidegger
Copy link
Contributor Author

Thinking of it: an even more abstract API might be better, since markdown rendering might be problematic if the content contains other markdown syntax.

var stream = compareStreamByLine(streamA, streamB)
var error = false
stream.on('data', function (line) {
  line // Array with the parts that are same/different:
  // ["ab", ["cd", "ef"], "12"] for the inputs "abcd12" and "abef12"

  console.log(format(line)) // Here it is possible to format the line and immediately show the output

  // We can detect problems with this little trick
  if (line.length > 0 || Array.isArray(line[0]) {
    error = true
  }
})
stream.on('error', function (errorInfo) {
  // If an error occured while reading the stream
  errorInfo.stream; // 'a' or 'b' if an error occurred null if the error occurred somewhere else
  errorInfo.err // error that occured
  error = true
})
stream.on('end', function () {
  if (error) {
    console.log('error occurred')
  }
})

@martinheidegger
Copy link
Contributor Author

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