-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
localisationTestForInvalidStrings #3198
Conversation
Hey @steph37tours, this goes into the right direction. I think the test fails in the right places, but the message is quite big. This would require to iterate over all property strings, similar as in |
Thank you @Lynyus. I see what you mean. I'll correct this tomorrow if it's ok :-). Ok, I am on actually. |
InputStreamReader reader = new InputStreamReader(is, StandardCharsets.UTF_8)) { | ||
properties.load(reader); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); |
There was a problem hiding this comment.
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
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 |
Wow @koppor (; |
There was a problem hiding this 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
@koppor to make this crystal clear: Do we need to fix the underscores or not?
# , ! , = , and : .So is there need to pursue this PR, or not? |
@koppor @lynyus That is specified in the java docs:
|
The question is, of course, why they were introduced in the first place. Is there any pitfall if we remove them?!? |
From what I understand the key can't contain whitespaces or the first whitepsace would be recognized as spearator in the key: |
there are spaces in the localization values and show detailed error.
I just push a change. I hope it is what you want. I've got difficult to test it. |
There was a problem hiding this 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 { |
There was a problem hiding this comment.
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(" ", "")); |
There was a problem hiding this comment.
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(), |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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(" ")); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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?
-correct name change s with z -change messages more clear
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 |
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! |
So is-it done now for me ? |
Can you push your commit please? (; You'll have to pull first, as I have already fixed the localization files on your branch. |
sorry, it doesn't want to push ! It seems I have to pull your change before. I 'm looking at... |
I'm sorry I can't push ! I'm looking for always. You can help ! |
on the current branch try the following: |
git merge said not remote branch for the current I'm sorry to be so beginner... |
git merge Localisation_test_for_invalid_Strings |
Hm. Maybe try a GUI client like Github Desktop to figure everything out. Or clone the repository again and apply your changes again. |
I'm sorry, I just clone and try to push again with the same error message. I continue to look for a solution. |
This reverts commit ffa51c6.
I don't know what to do. |
perhaps I have to do another fork ? |
…b.com/steph37tours/jabref into Localisation_test_for_invalid_Strings Follow trouble with pull
It seems it's ok now. I don't know what happen exactly. |
|
||
//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(" ")); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
I'll merge this now, thanks for the efforts, @steph37tours! I hope you have learned something and are still eager to contribute. (; |
Thank you very much @lynyus ! |
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. |
Thank you @koppor for the link ! I'll study it ! |
…te for instance
gradle localizationUpdate
?