From 1b527ceca5406925b076b1fe1613ff5438e03b04 Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Thu, 29 Jul 2021 11:15:37 +0000 Subject: [PATCH] add tests for concat function git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1891874 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/ss/formula/functions/TestConcat.java | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/poi/src/test/java/org/apache/poi/ss/formula/functions/TestConcat.java b/poi/src/test/java/org/apache/poi/ss/formula/functions/TestConcat.java index 42bb93f7f9..8edf44340e 100644 --- a/poi/src/test/java/org/apache/poi/ss/formula/functions/TestConcat.java +++ b/poi/src/test/java/org/apache/poi/ss/formula/functions/TestConcat.java @@ -51,7 +51,7 @@ final class TestConcat { } @Test - void testConcatWithCellRefs() throws IOException { + void testConcatWithCellRanges() throws IOException { try (HSSFWorkbook wb = initWorkbook1()) { HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb); HSSFCell cell = wb.getSheetAt(0).getRow(0).createCell(0); @@ -59,6 +59,20 @@ final class TestConcat { } } + @Test + void testConcatWithCellRefs() throws IOException { + try (HSSFWorkbook wb = initWorkbook2()) { + HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb); + HSSFCell cell = wb.getSheetAt(0).createRow(5).createCell(0); + confirmResult(fe, cell, "CONCAT(\"Stream population for \", A2,\" \", A3, \" is \", A4, \"/mile.\")", + "Stream population for brook trout species is 32/mile."); + confirmResult(fe, cell, "CONCAT(B2,\" \", C2)", "Andreas Hauser"); + confirmResult(fe, cell, "CONCAT(C2, \", \", B2)", "Hauser, Andreas"); + confirmResult(fe, cell, "CONCAT(B3,\" & \", C3)", "Fourth & Pine"); + confirmResult(fe, cell, "B3 & \" & \" & C3", "Fourth & Pine"); + } + } + private HSSFWorkbook initWorkbook1() { HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet = wb.createSheet(); @@ -71,6 +85,16 @@ final class TestConcat { return wb; } + private HSSFWorkbook initWorkbook2() { + HSSFWorkbook wb = new HSSFWorkbook(); + HSSFSheet sheet = wb.createSheet(); + addRow(sheet, 0, "Data", "First Name", "Last name"); + addRow(sheet, 1, "brook trout", "Andreas", "Hauser"); + addRow(sheet, 2, "species", "Fourth", "Pine"); + addRow(sheet, 3, "32"); + return wb; + } + private void addRow(HSSFSheet sheet, int rownum, String... values) { HSSFRow row = sheet.createRow(rownum); for (int i = 0; i < values.length; i++) { -- 2.39.5