Skip to content

diff have a problem #22

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
yangtuo opened this issue Aug 2, 2018 · 5 comments
Closed

diff have a problem #22

yangtuo opened this issue Aug 2, 2018 · 5 comments

Comments

@yangtuo
Copy link

yangtuo commented Aug 2, 2018

Expected Behavior

original new
This is a test senctence. This is a test for diffutils.
This is the second line.

Actual Behavior

original new
This is a test senctence. This is a test for diffutils.**
This is the second line.
         DiffRowGenerator generator = DiffRowGenerator.create()
			.showInlineDiffs(true)
			.inlineDiffByWord(true)
			.oldTag(f -> "~")
			.newTag(f -> "**")
			.build();
	List<DiffRow> rows = generator.generateDiffRows(
			Arrays.asList("This is a test senctence."),
			Arrays.asList("This is a test for diffutils.", "This is the second line."));

	System.out.println("|original|new|");
	System.out.println("|--------|---|");
	for (DiffRow row : rows) {
		System.out.println("|" + row.getOldLine() + "|" + row.getNewLine() + "|");
	}
@wumpz
Copy link
Collaborator

wumpz commented Aug 2, 2018

I assume you flipped expected and actual behavior.

@wumpz
Copy link
Collaborator

wumpz commented Aug 2, 2018

This boils down to the question, if the linefeed should be part of the difference or not. I think it should be part of it, since in your example a newline is introduced. The Arrays have different size. If you start with

Arrays.asList("This is a test senctence.","")

you get your expected behavior.

@yangtuo yangtuo closed this as completed Aug 2, 2018
@yangtuo
Copy link
Author

yangtuo commented Aug 2, 2018

thanks for the reply,I want to compare the difference between two strings 。
String a = "This is a test senctence."
String b="This is a test for diffutils.\nThis is the second line."


               DiffRowGenerator generator = DiffRowGenerator.create()
				.showInlineDiffs(true)
				.inlineDiffByWord(true)
				.oldTag(f -> "~")
				.newTag(f -> "**")
				.build();

		String aa = "This is a test senctence.";
		String bb ="This is a test for diffutils.\nThis is the second line.";
		List<DiffRow> rows = generator.generateDiffRows(
				Arrays.asList(aa.split("\n")),
				Arrays.asList(bb.split("\n")));

		System.out.println("|original|new|");
		System.out.println("|--------|---|");
		for (DiffRow row : rows) {
			System.out.println("|" + row.getOldLine() + "|" + row.getNewLine() + "|");
		}

@wumpz wumpz reopened this Aug 3, 2018
@wumpz
Copy link
Collaborator

wumpz commented Aug 3, 2018

I changed my mind. Due to visualization it is clear, that there is a linefeed. And because this line diff is generated for visualiization purposes the result should be the one you expected.

@wumpz
Copy link
Collaborator

wumpz commented Aug 3, 2018

The actual result in version 3.0-SNAPSHOT is

original new
This is a test senctence. This is a test for diffutils.
This is the second line.

@wumpz wumpz closed this as completed in c410422 Aug 3, 2018
wumpz added a commit that referenced this issue Aug 3, 2018
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

No branches or pull requests

2 participants