add tests for concat function

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1891874 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
PJ Fanning 2021-07-29 11:15:37 +00:00
parent cf38746a0f
commit 1b527ceca5
1 changed files with 25 additions and 1 deletions

View File

@ -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++) {