You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ch...@apache.org on 2017/06/05 13:44:54 UTC
[1/2] [text] [junit]: Added test cases for CsvTranslators
Repository: commons-text
Updated Branches:
refs/heads/master da8e7a95f -> 5f498c0f4
[junit]: Added test cases for CsvTranslators
Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/e85959f7
Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/e85959f7
Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/e85959f7
Branch: refs/heads/master
Commit: e85959f7a2caa98b942d4b8a3e1132da7024bda5
Parents: 343b4a9
Author: Amey Jadiye <am...@gmail.com>
Authored: Fri Jun 2 23:54:23 2017 +0530
Committer: Amey Jadiye <am...@gmail.com>
Committed: Sat Jun 3 00:54:23 2017 +0530
----------------------------------------------------------------------
.../text/translate/CsvTranslatorsTest.java | 137 +++++++++++++++++++
1 file changed, 137 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-text/blob/e85959f7/src/test/java/org/apache/commons/text/translate/CsvTranslatorsTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/text/translate/CsvTranslatorsTest.java b/src/test/java/org/apache/commons/text/translate/CsvTranslatorsTest.java
new file mode 100644
index 0000000..6d1e721
--- /dev/null
+++ b/src/test/java/org/apache/commons/text/translate/CsvTranslatorsTest.java
@@ -0,0 +1,137 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.text.translate;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+import java.io.StringWriter;
+import java.io.Writer;
+
+import org.apache.commons.lang3.CharUtils;
+import org.junit.Test;
+
+public class CsvTranslatorsTest {
+
+ @Test
+ public void csvEscaperPlaneTextTest() throws IOException{
+ final CsvTranslators.CsvEscaper escaper = new CsvTranslators.CsvEscaper();
+ final Writer writer = new StringWriter();
+ final String input = "hi this is just a plane text nothing to do with csv!";
+ escaper.translateWhole(input, writer);
+ String data = writer.toString();
+ assertEquals(data, input);
+ }
+
+ @Test
+ public void csvEscaperCommaTest() throws IOException{
+ final CsvTranslators.CsvEscaper escaper = new CsvTranslators.CsvEscaper();
+ final Writer writer = new StringWriter();
+ final String input = "hi,this,is,a,test";
+ escaper.translateWhole(input, writer);
+ String data = writer.toString();
+ assertEquals(data, "\"hi,this,is,a,test\"");
+
+ }
+
+ @Test
+ public void csvEscaperQuoteTest() throws IOException{
+ final CsvTranslators.CsvEscaper escaper = new CsvTranslators.CsvEscaper();
+ final Writer writer = new StringWriter();
+ final String input = "hi,this,is,a,\"quote,test";
+ escaper.translateWhole(input, writer);
+ String data = writer.toString();
+ assertEquals(data, "\"hi,this,is,a,\"\"quote,test\"");
+
+ }
+ @Test
+ public void csvEscaperCRTest() throws IOException{
+ final CsvTranslators.CsvEscaper escaper = new CsvTranslators.CsvEscaper();
+ final Writer writer = new StringWriter();
+ final String input = "hi,this,is,a,CR,test" + String.valueOf(CharUtils.CR);
+ escaper.translateWhole(input, writer);
+ String data = writer.toString();
+ assertEquals(data, "\"hi,this,is,a,CR,test"+String.valueOf(CharUtils.CR)+"\"");
+
+ }
+ @Test
+ public void csvEscaperLFTest() throws IOException{
+ final CsvTranslators.CsvEscaper escaper = new CsvTranslators.CsvEscaper();
+ final Writer writer = new StringWriter();
+ final String input = "hi,this,is,a,LF,test" + String.valueOf(CharUtils.LF);
+ escaper.translateWhole(input, writer);
+ String data = writer.toString();
+ assertEquals(data, "\"hi,this,is,a,LF,test" + String.valueOf(CharUtils.LF) +"\"");
+
+ }
+
+ @Test
+ public void csvUnEscaperPlaneTextTest() throws IOException{
+ final CsvTranslators.CsvUnescaper escaper = new CsvTranslators.CsvUnescaper();
+ final Writer writer = new StringWriter();
+ final String input = "hi,this,is,unescape,test";
+ escaper.translateWhole(input, writer);
+ String data = writer.toString();
+ assertEquals(data, "hi,this,is,unescape,test");
+
+ }
+
+ @Test
+ public void csvUnEscaperTest1() throws IOException{
+ final CsvTranslators.CsvUnescaper escaper = new CsvTranslators.CsvUnescaper();
+ final Writer writer = new StringWriter();
+ final String input = "\"hi,this,is,unescape,test\"";
+ escaper.translateWhole(input, writer);
+ String data = writer.toString();
+ assertEquals(data, "hi,this,is,unescape,test");
+
+ }
+
+ @Test
+ public void csvUnEscaperTest2() throws IOException{
+ final CsvTranslators.CsvUnescaper escaper = new CsvTranslators.CsvUnescaper();
+ final Writer writer = new StringWriter();
+ final String input = "\"hi,this,is,unescape,test";
+ escaper.translateWhole(input, writer);
+ String data = writer.toString();
+ assertEquals(data, input);
+
+ }
+
+ @Test
+ public void csvUnEscaperTest3() throws IOException{
+ final CsvTranslators.CsvUnescaper escaper = new CsvTranslators.CsvUnescaper();
+ final Writer writer = new StringWriter();
+ final String input = "hi,this,is,unescape,test\"";
+ escaper.translateWhole(input, writer);
+ String data = writer.toString();
+ assertEquals(data, input);
+
+ }
+
+ @Test
+ public void csvUnEscaperTest4() throws IOException{
+ final CsvTranslators.CsvUnescaper escaper = new CsvTranslators.CsvUnescaper();
+ final Writer writer = new StringWriter();
+ final String input = "\"hi,this,is,\"unescape,test\"";
+ escaper.translateWhole(input, writer);
+ String data = writer.toString();
+ assertEquals(data, "hi,this,is,\"unescape,test");
+
+ }
+
+}
[2/2] [text] Merge commit [Junit]: Added test cases for
CsvTranslators from Amey Jadiye
Posted by ch...@apache.org.
Merge commit [Junit]: Added test cases for CsvTranslators from Amey Jadiye
Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/5f498c0f
Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/5f498c0f
Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/5f498c0f
Branch: refs/heads/master
Commit: 5f498c0f4783d035bfeb77517731c948f8567b1e
Parents: da8e7a9 e85959f
Author: Rob Tompkins <ch...@apache.org>
Authored: Mon Jun 5 09:44:15 2017 -0400
Committer: Rob Tompkins <ch...@apache.org>
Committed: Mon Jun 5 09:44:15 2017 -0400
----------------------------------------------------------------------
.../text/translate/CsvTranslatorsTest.java | 137 +++++++++++++++++++
1 file changed, 137 insertions(+)
----------------------------------------------------------------------