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
Create a test suite showing all the features of supercsv #56
Comments
Thanks for pointing me to this issue. I will try to start working on test suite this week. |
Sounds fantastic. Not sure how we should structure this? I mean we cannot put ALL the features into one test I guess since we have extra modules e.g. for jodatime. Any ideas? Maybe put a "feature" test in each package? Then we also need from the frontpage, to link to alle the "featuretests" |
"Feature" test in each package sounds good. We can start using this approach and when we will see better one we can refactor already created tests. Edit:
we can A: Create TokenizerTest which will be containing 8 test for each related features. Put this test to "features" subpackage. |
I'm not sure what provides the better overview. Maybe it will be clear after some code |
I have implemented first test for "Tokenizer" section and actually it is not possible to:
Or maybe it is possible, but I could not find any feature which allows that. Actually, we can trim leading and trailing white-characters but we have to choose proper cell processors. I think, it should be listed in documentation or guideline. Below you can see class and simple tests. I did not want to push them as PR because actually I do not know what to do with tests for which we are not able to change "escape character". Should we thrown exception "Not implemented yet!" or something like this? What do you think? package org.supercsv.features;
import org.junit.Assert;
import org.junit.Test;
import org.supercsv.cellprocessor.constraint.NotNull;
import org.supercsv.cellprocessor.ift.CellProcessor;
import org.supercsv.io.CsvBeanWriter;
import org.supercsv.io.CsvListWriter;
import org.supercsv.prefs.CsvPreference;
import java.io.IOException;
import java.io.StringWriter;
import java.util.Arrays;
import java.util.List;
/**
* Test class which checks all features listed on <a href="http://csveed.org/comparison-matrix.html">comparison page</a> in "Tokenizer" section.
*
* @author Michał Ziober
*/
public class TokenizerFeaturesTest {
@Test
public void testCustomSeparator() throws IOException {
List<String> data = Arrays.asList("John", "Connor");
CellProcessor[] processors = { new NotNull(), new NotNull() };
char customSeparator = '+';
CsvPreference customPreference = new CsvPreference.Builder('"', customSeparator, "").build();
StringWriter writer = new StringWriter();
CsvListWriter beanWriter = new CsvListWriter(writer, customPreference);
beanWriter.write(data, processors);
beanWriter.close();
Assert.assertEquals("John+Connor", writer.toString());
}
@Test
public void testCustomQuote() throws IOException {
List<String> data = Arrays.asList("John \n Connor");
CellProcessor[] processors = { new NotNull() };
char customQuote = '|';
CsvPreference customPreference = new CsvPreference.Builder(customQuote, ',', "").build();
StringWriter writer = new StringWriter();
CsvListWriter beanWriter = new CsvListWriter(writer, customPreference);
beanWriter.write(data, processors);
beanWriter.close();
Assert.assertEquals("|John Connor|", writer.toString());
}
//TODO: not possible to change
@Test
public void testCustomEscape() throws IOException {
List<String> data = Arrays.asList("\"John Connor\"");
CellProcessor[] processors = { new NotNull() };
CsvPreference customPreference = new CsvPreference.Builder('"', ',', "").build();
StringWriter writer = new StringWriter();
CsvListWriter beanWriter = new CsvListWriter(writer, customPreference);
beanWriter.write(data, processors);
beanWriter.close();
Assert.assertEquals("\"\"\"John Connor\"\"\"", writer.toString());
}
@Test
public void testCustomEOL() throws IOException {
List<String> data = Arrays.asList("John Connor");
CellProcessor[] processors = { new NotNull() };
String customEndOfLine = ">\r\n";
CsvPreference customPreference = new CsvPreference.Builder('"', ',', customEndOfLine).build();
StringWriter writer = new StringWriter();
CsvListWriter beanWriter = new CsvListWriter(writer, customPreference);
beanWriter.write(data, processors);
beanWriter.close();
Assert.assertEquals("John Connor>\r\n", writer.toString());
}
@Test
public void testNewLineInDelimitedField() throws IOException {
List<String> data = Arrays.asList("Jo\nhn", "Con\nnor");
CellProcessor[] processors = { new NotNull(), new NotNull() };
CsvPreference customPreference = new CsvPreference.Builder('"', ',', "\n").build();
StringWriter writer = new StringWriter();
CsvListWriter beanWriter = new CsvListWriter(writer, customPreference);
beanWriter.write(data, processors);
beanWriter.close();
Assert.assertEquals("\"Jo\nhn\",\"Con\nnor\"\n", writer.toString());
}
@Test
public void testEscapedQuoteInQuotedField() throws IOException {
List<String> data = Arrays.asList("Joh\"n", "Con\"nor");
CellProcessor[] processors = { new NotNull(), new NotNull() };
CsvPreference customPreference = new CsvPreference.Builder('"', ',', "").build();
StringWriter writer = new StringWriter();
CsvListWriter beanWriter = new CsvListWriter(writer, customPreference);
beanWriter.write(data, processors);
beanWriter.close();
Assert.assertEquals("\"Joh\"\"n\",\"Con\"\"nor\"", writer.toString());
}
//TODO: not possible to separate
@Test
public void testDifferentEscapeAndQuote() throws IOException {
List<String> data = Arrays.asList("\"John Connor\"");
CellProcessor[] processors = { new NotNull() };
char customQuote = '"';
CsvPreference customPreference = new CsvPreference.Builder(customQuote, ',', "").build();
StringWriter writer = new StringWriter();
CsvListWriter beanWriter = new CsvListWriter(writer, customPreference);
beanWriter.write(data, processors);
beanWriter.close();
Assert.assertEquals("\"\"\"John Connor\"\"\"", writer.toString());
}
//TODO: not possible to trim values
@Test
public void testDealWithLeadingTrailingWhitespace() throws IOException {
List<String> data = Arrays.asList(" John", "Connor ");
CellProcessor[] processors = { new NotNull(), new NotNull() };
char customQuote = '"';
CsvPreference customPreference = new CsvPreference.Builder(customQuote, ',', "").surroundingSpacesNeedQuotes(false).build();
StringWriter writer = new StringWriter();
CsvListWriter beanWriter = new CsvListWriter(writer, customPreference);
beanWriter.write(data, processors);
beanWriter.close();
Assert.assertEquals(" John,Connor ", writer.toString());
}
} |
Hey Michał, looks like all of those tests are for writing, whereas any features that Tokenizer should support are related to reading. Some features only apply to reading or writing, others apply to both. Regarding Here's some related issues:
I don't think the feature tests should break the build (perhaps we should just |
Actually I wanted wrote these tests for "read" mode as well but at the beginning I just wanted show first draft and talk about that a little. Anyway, that a good point that some features are available in "read" and "write" mode and some only in one mode. I agree that |
How we organise the tests are still unclear to me but a test fixture for reading features and one for writing features sound great. With the tests we need a table in the documentation to quickly give an overview of the features possibly with a column referring to the specific tests by linking to the source code maybe. |
It is a good idea to create documentation which explicitly tells which features are available. A little sum up:
When tests will be ready and "well implemented" we can create new section in documentation. |
1. Added two new tests which explicitly checks features from http://csveed.org/comparison-matrix.html page (Tokenizer section).
I've pushed tests for Tokenizer read/write features. Let me know what do you think about this implementation. |
1. Added two new tests which explicitly checks features from http://csveed.org/comparison-matrix.html page (Tokenizer section).
1. Added two new tests which explicitly checks features from http://csveed.org/comparison-matrix.html page (Tokenizer section).
I've also added tests which explicitly checks features from http://csveed.org/comparison-matrix.html page from “Line Reading” section. |
Great I was about to asking just that
|
We have to write tests also for "Bean Mapping" and "Writing CSV" sections. "Documentation" sections is completed for "super-csv". I am not sure whether is something to do related with "Quality of error feedback", what do you think? "Convenience" section is also not clear for me. Will you merge this PR as it is now or you want to wait for tests related with other sections? |
Already merged.. but feel free to send more stuff 👍 |
I am not sure whether it is already merged ... :) I am a little confused what some ideas mean in this comparison matrix in "Bean mapping" section.
What do you think guys? |
My interpretation...
|
Thanks for it! I've added new tests. Could you please, @kbilsted, @jamesbassett review them? |
1. Added two new tests which explicitly checks features from http://csveed.org/comparison-matrix.html page.
#56 - test suite for Tokenizer read/write operations.
@kbilsted ,
Next sections mostly covers "concepts" not "implementation":
Do you think we can do anything more in this issue? |
Sure create the new issues and close. Do we need an issue for making a documentation page giving an overview of all features of supercsv linking into the tests? |
I think that we can create new documentation page in this issue. P.S: Until first of October I have a lot of work and probably I will not be able to do it sooner. |
I have created new issues which should be implemented:
Also, I have asked to update Comparison matrix in this task 42BV/CSVeed#65. I checked documentation and it contains already all needed informations. I think that we can create new documentation page when above tasks will be finished. |
An idea could be to create a unit test called "FeaturesOfSuperCsv" which has a test for each row of the comparison matrix showing that supercsv in fact has this feature. Missing features should be made into individual issues which the community then can implement or reject.
this test is nice for
features to show can be found in
The text was updated successfully, but these errors were encountered: