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

WIP: Omit plus and minus in string diffs, except in text mode #270

Merged
merged 7 commits into from Feb 29, 2016

Conversation

papandreou
Copy link
Member

oldLine.prependLinesWith(this.clone().diffRemovedLine('-'));
newLine.prependLinesWith(this.clone().diffAddedLine('+'));
},
fallback: function () {}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here it would be nice of magicPen.alt allowed omitting fallback: function () {}.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would happen in the unexpected-pdf ;-)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It just wouldn't do anything in that mode. It'd just assume that you wanted to fall back to NOOP :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make the fallback default to a noop then.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, on it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in magicpen 5.6.0, updated to it on the branch.

@sunesimonsen
Copy link
Member

I'm okay with putting all the formatting in a style. But I would like the actual diffing to happen somewhere else. Think: spilling computation from presentation.

I'll get back to you with more feedback, probably tonight.

@sunesimonsen
Copy link
Member

I like the main idea of loosing the + and - signs, but I don't think we should put things in styles that is not about styling. If we can create a string diff data structure and hand that of to a style I would prefer that. I would think it is possible to just have the + and - in an alt style. It is okay to create more styles that is capable of formating a added/removed line.

@papandreou
Copy link
Member Author

I like the main idea of loosing the + and - signs

Great, that's the main thing at this point :)

I don't think we should put things in styles that is not about styling. If we can create a string diff data structure and hand that of to a style I would prefer that.

I thought that we already sort of had that in the shape of require('diff').diffLines? You're right that we have added some postprocessing that isn't all about styling per se, but I think we're pretty close to what you want already?

@sunesimonsen
Copy link
Member

Okay I'll take a second look at what's going on. I still think it is possible to achieve this without using prependLinesWith.

@papandreou
Copy link
Member Author

@sunesimonsen Thanks, ironically enough I'm beginning to think it's a bit dirty to manipulate the contents of a pen.

Feel free to push to the branch if you get anywhere ofc :)

@sunesimonsen
Copy link
Member

I agree, I would probably have made it immutable today 😁

var type = options.type || 'WordsWithSpace';
var diffLines = [];
var lastPart;
stringDiff.diffLines(actual, expected).forEach(function (part) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the part I don't really like, the style does the actual diff computation instead of being handed the diff. I know that the API from the outside would be convenient by letting the style taking care of it, but I just think it is misplaced. I would prefer:

var diff = utils.stringDiff(actual, expected)
pen.appendDiff(diff)

It is mainly about separation of concerns.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would of cause mean that we would need to change the output of the utils.stringDiff.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the the diff formatting codes looks a bit weird, maybe it would also help to just start over. Make a utils.stringDiff that produces a data structure that contains lines of tokens. Then hand that output to a magicpen style that would format it the way we want. Then it should also be possible to get rid of `prependLinesWith'.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shit I don't know, maybe we should just allow magicpen to do these crazy things, magicpen-prism is in the same space. It just feels a bit wrong, but what ever :-) Could I take a stab at fixing up the formatting code?

I realize that I'm having a conversation with myself and convincing myself of going in new directions :-)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shit this is much more complicated than I remembered :-)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can simplify things if we only used diffAddedLine, diffRemovedLine with one line and not multiple lines. Then we would be able to move the -/+ signs to these methods:

    expect.addStyle('diffAddedLine', function (line) {
        this.alt({ text: '+' });
        this.green(line);
    });

    expect.addStyle('diffRemovedLine', function (line) {
        this.alt({ text: '-' });
        this.red(line);
    });

    expect.addStyle('diffUnchangedLine', function (line){
        this.alt({ text: ' ' });
        this.text(line)
    });

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's also what I arrived at. I attempted it once, but got stuck when I ran into the "internal" diff that the handling of replaced chunks does.

@sunesimonsen
Copy link
Member

I'm not going to block this improvement with a cleanup of the stringDiff - it was fucked before, that situation has not changed just because the turd moved.

👍

@papandreou
Copy link
Member Author

I'm not at all satisfied with the state this is in myself, but you're right that the cleanup might be better handled as a separate task. Let's discuss that here: #272

Merging.

papandreou added a commit that referenced this pull request Feb 29, 2016
…tringDiffs

WIP: Omit plus and minus in string diffs, except in text mode
@papandreou papandreou merged commit 626f0de into master Feb 29, 2016
@papandreou papandreou deleted the feature/omitPlusAndMinusInStringDiffs branch February 29, 2016 07:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants