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

localisationTestForInvalidStrings #3198

Merged

Conversation

steph37tours
Copy link
Contributor

@steph37tours steph37tours commented Sep 5, 2017

…te for instance

  • Change in CHANGELOG.md described
  • Tests created for changes
  • Screenshots added (for bigger UI changes)
  • Manually tested changed features in running JabRef
  • Check documentation status (Issue created for outdated help page at help.jabref.org?)
  • If you changed the localization: Did you run gradle localizationUpdate?

@steph37tours steph37tours reopened this Sep 5, 2017
@LinusDietz
Copy link
Member

Hey @steph37tours, this goes into the right direction. I think the test fails in the right places, but the message is quite big.
What would be better is something like this:
Found an invalid character in the <language> localization of <JabRef | Menu>: The <key | value> <actual string> contains a space!

This would require to iterate over all property strings, similar as in LocalizationConsistencyTest.keyValueShouldBeEqualForEnglishPropertiesMenu().
Please give it another shot.

@steph37tours
Copy link
Contributor Author

steph37tours commented Sep 5, 2017

Thank you @Lynyus. I see what you mean. I'll correct this tomorrow if it's ok :-).

Ok, I am on actually.

@LinusDietz LinusDietz changed the title adding of the new method localisationTestForInvalidStrings not comple… [WIP] localisationTestForInvalidStrings Sep 5, 2017
InputStreamReader reader = new InputStreamReader(is, StandardCharsets.UTF_8)) {
properties.load(reader);
} catch (IOException e) {
throw new RuntimeException(e);
Copy link
Member

Choose a reason for hiding this comment

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

No need to catch and throw - the method already throws the exception

@koppor
Copy link
Member

koppor commented Sep 5, 2017

I am unsure whether JabRef really cannot handle underscores. I once looked at the code and I think, we could get rid of using the underscores and always use spaces. Could you check that? I think _ is so 2005 😇

@LinusDietz
Copy link
Member

Wow @koppor (;

Copy link
Member

@koppor koppor left a comment

Choose a reason for hiding this comment

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

Exceptions typically don't need to be catched in JUnit test cases

@LinusDietz
Copy link
Member

@koppor to make this crystal clear: Do we need to fix the underscores or not?
In

// space, #, !, = and : are not allowed in properties file keys
there is a comment that fixes the spaces, but not the #, !, =, and :.
So is there need to pursue this PR, or not?

@Siedlerchr
Copy link
Member

@koppor @lynyus That is specified in the java docs:
http://docs.oracle.com/javase/8/docs/api/java/util/Properties.html#load(java.io.Reader)

.A comment line has an ASCII '#' or '!' as its first non-white space character; comment lines are also ignored and do not encode key-element information
In addition to line terminators, this format considers the characters space (' ', '\u0020'), tab ('\t', '\u0009'), and form feed ('\f', '\u000C') to be white space.

The key contains all of the characters in the line starting with the first non-white space character and up to, but not including, the first unescaped '=', ':', or white space character other than a line terminator

@koppor
Copy link
Member

koppor commented Sep 6, 2017

Then, we can have the values without underscores? That would improve the language files a lot!

grafik

@LinusDietz
Copy link
Member

The question is, of course, why they were introduced in the first place. Is there any pitfall if we remove them?!?

@Siedlerchr
Copy link
Member

Siedlerchr commented Sep 6, 2017

From what I understand the key can't contain whitespaces or the first whitepsace would be recognized as spearator in the key:
A key is all the characters up to the first whitespace or a key/value separator
http://kajabity.com/kajabity-tools/java-properties-classes/the-java-properties-file-format/

there are spaces in the localization values and show detailed error.
@steph37tours
Copy link
Contributor Author

I just push a change. I hope it is what you want. I've got difficult to test it.
And I'm not sure for the "throws IOException" Eclipse ask me for remove it.
Thank you for help and permit to participate. It was very interesting for me.

Copy link
Member

@LinusDietz LinusDietz left a comment

Choose a reason for hiding this comment

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

The functionality is not yet doing what it should. Please go through the comments and try to run the tests yourself.

In order to merge this pull request it would also be necessary to fix the invalid localization files such that the test actually passes. If you want to, I can help you with that. In this case you would have to give me push access to your fork of JabRef.

@@ -183,6 +183,28 @@ public void localizationParameterMustIncludeAString() throws IOException {
}
}

@Test
public void localisationTestForInvalidStrings() throws IOException {
Copy link
Member

Choose a reason for hiding this comment

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

Indeed, you can remove the throws statement.

for (Map.Entry<Object, Object> entry : textKeys.entrySet()) {
String expectedKeyEqualsKey = String.format("%s=%s", entry.getKey(), entry.getKey());
String actualKeyEqualsValue = String.format("%s=%s", entry.getKey(),
entry.getValue().toString().replace(" ", ""));
Copy link
Member

Choose a reason for hiding this comment

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

I would suggest that you check for spaces using String.contains(). Then there is no need to compare strings. later.

//parse object "textKeys" to find any spaces
for (Map.Entry<Object, Object> entry : textKeys.entrySet()) {
String expectedKeyEqualsKey = String.format("%s=%s", entry.getKey(), entry.getKey());
String actualKeyEqualsValue = String.format("%s=%s", entry.getKey(),
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 not correct. While in the english localization the key must equal the value, in all other languages the the key is different from the value.

entry.getValue().toString().replace(" ", ""));


assertEquals("Found an invalid character in the "+ lang + "localization of" + bundle + ": The " + entry.getKey().toString() + ":" + expectedKeyEqualsKey + " contains a space!",expectedKeyEqualsKey, actualKeyEqualsValue);
Copy link
Member

Choose a reason for hiding this comment

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

This looks fine, however make sure to include some spaces and quotes to make the sentence more readable
Found an invalid character in the inlocalization ofJabRef: The pairs_processed:pairs_processed=pairs_processed contains a space!
=>
Found an invalid character in the 'in' localization of 'JabRef': The 'pairs_processed:pairs_processed=pairs_processed' contains a space!

Also the error should be apparent from the message. The String above does not have a space.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I give you push access. I'm correcting my code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it's ok now. But I didn't success to test ! It seems I don't know how to do.

Copy link
Member

@LinusDietz LinusDietz left a comment

Choose a reason for hiding this comment

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

We are getting there soon. Check my remarks!

Try to run the tests using eclipse: It's described here https://stackoverflow.com/questions/646307/running-a-single-junit-test-in-eclipse how to do it.

As soon as the test is fine, I'll fix the files and we are good to merge.

.getProperties(propertyFilePath);
//parse object "textKeys" to find any spaces
for (Map.Entry<Object, Object> entry : textKeys.entrySet()) {
assertTrue("Found an invalid character in the " + lang + " localization of " + bundle + " : The " + entry.getKey().toString() + " : " + entry.getValue().toString() + " contains a space!", entry.getValue().toString().contains(" "));
Copy link
Member

Choose a reason for hiding this comment

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

The statement must be inverted. We want the test to fail if there is a ' ' in the String.
Also, you only verify the values, but not the keys of the entry.
Just add another line where you assert that there are also no spaces in the key.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lynyus, I commit and push again.
I correct the message with "At key", which seems to me more clear to find the line.
For the test : I use Junit. It find some failures

java.lang.AssertionError: Found an invalid character in the in localization of JabRef : proces_berpasangan At key : pairs_processed contains a space!

If I correct the P into Pairs_processed, it runs.

But I've got the same trouble in New_article , but I don't find why...

Copy link
Member

Choose a reason for hiding this comment

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

Have you tried using assertFalse instead if assertTrue?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. It runs !

@@ -183,6 +183,23 @@ public void localizationParameterMustIncludeAString() throws IOException {
}
}

@Test
public void localisationTestForInvalidStrings() {
Copy link
Member

Choose a reason for hiding this comment

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

I would suggest to make this name a bit more precise: maybe localizationTestForInvalidCharacters?

@LinusDietz
Copy link
Member

So if you change the Assertions to assertFalse or negate the condition the tests should be operational and we can see if they pass the test on our build server
assertFalse("Found an invalid character in the " + lang + " localization of " + bundle + " : " + entry.getValue().toString() + " At key : " + entry.getKey().toString() + " contains a space!", entry.getValue().toString().contains(" "));

@steph37tours
Copy link
Contributor Author

Yes, I change and commit. I found spaces in pt_BR localization :

java.lang.AssertionError: Found an invalid character in the pt_BR localization of JabRef : Normalizar para o formato_de_nome_do_BibTeX At key : Normalize_to_BibTeX_name_format contains a space!

@steph37tours
Copy link
Contributor Author

steph37tours commented Sep 6, 2017

So is-it done now for me ?

@LinusDietz
Copy link
Member

Can you push your commit please? (; You'll have to pull first, as I have already fixed the localization files on your branch.

@steph37tours
Copy link
Contributor Author

sorry, it doesn't want to push ! It seems I have to pull your change before. I 'm looking at...

@steph37tours
Copy link
Contributor Author

steph37tours commented Sep 6, 2017

I'm sorry I can't push !
I've got the error that the branch countain work I doesn't have in local.
I try git pull
git pull --rebase without success for instance !

I'm looking for always. You can help !

@LinusDietz
Copy link
Member

on the current branch try the following:
git fetch
git merge
git push

@steph37tours
Copy link
Contributor Author

steph37tours commented Sep 6, 2017

git merge said not remote branch for the current

I'm sorry to be so beginner...

@steph37tours
Copy link
Contributor Author

git merge Localisation_test_for_invalid_Strings
said up-to-date

@LinusDietz
Copy link
Member

Hm. Maybe try a GUI client like Github Desktop to figure everything out. Or clone the repository again and apply your changes again.

@steph37tours
Copy link
Contributor Author

I'm sorry, I just clone and try to push again with the same error message. I continue to look for a solution.

@steph37tours
Copy link
Contributor Author

I don't know what to do.
Into Eclipse, the menu team/pull give to me an error "Missing commit"

@steph37tours
Copy link
Contributor Author

perhaps I have to do another fork ?

@steph37tours
Copy link
Contributor Author

It seems it's ok now. I don't know what happen exactly.
Really thank you for this first experience, thank you for the time you share with me to help.


//parse object "textKeys" to find any spaces
for (Map.Entry<Object, Object> entry : textKeys.entrySet()) {
assertFalse("Found an invalid character in the " + lang + " localization of " + bundle + " : " + entry.getValue().toString() + " At key : " + entry.getKey().toString() + " contains a space!", entry.getValue().toString().contains(" "));
Copy link
Member

Choose a reason for hiding this comment

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

Just a minor thing: if you concatenate Strings and objects (no matter which type) with"some text " + object
You don't need to do an explicit call to "toString()" The method is automatically invoked. But beware, in the case where you want to call a methond on a string like the contains, you have to use the toString

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you @Siedlerchr for this explanation.

@LinusDietz LinusDietz changed the title [WIP] localisationTestForInvalidStrings localisationTestForInvalidStrings Sep 7, 2017
@LinusDietz
Copy link
Member

I'll merge this now, thanks for the efforts, @steph37tours! I hope you have learned something and are still eager to contribute. (;
How about this? #2942 It's a small feature in the UI, and everybody would be quite happy if somebody finds time to implement it!

@LinusDietz LinusDietz merged commit 529fa43 into JabRef:master Sep 7, 2017
@steph37tours
Copy link
Contributor Author

steph37tours commented Sep 7, 2017

Thank you very much @lynyus !
I learn many things with this experience.
So I agree to continue ! :-)

@koppor
Copy link
Member

koppor commented Sep 8, 2017

Good to see that you won the git war :). -- For learning git, I would recommend the tutorials listed at https://github.com/dictcp/awesome-git.

@steph37tours
Copy link
Contributor Author

Thank you @koppor for the link ! I'll study it !

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.

4 participants