|
|
@ -16,23 +16,23 @@ import java.util.Set; |
|
|
|
* @since 11.0 |
|
|
|
* @since 11.0 |
|
|
|
* Created on 2024/11/5 |
|
|
|
* Created on 2024/11/5 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class FormulaUtilsTest extends TestCase { |
|
|
|
public class TableDataFormulaUtilsTest extends TestCase { |
|
|
|
|
|
|
|
|
|
|
|
public void testSearch() { |
|
|
|
public void testSearch() { |
|
|
|
String rowcount = "=ROWCOUNT(\"123\")"; |
|
|
|
String rowcount = "=ROWCOUNT(\"123\")"; |
|
|
|
Set<String> strings = new HashSet<>(); |
|
|
|
Set<String> strings = new HashSet<>(); |
|
|
|
strings.add("123"); |
|
|
|
strings.add("123"); |
|
|
|
Assert.assertEquals(FormulaUtils.search(rowcount), strings); |
|
|
|
Assert.assertEquals(TableDataFormulaUtils.search4TableData(rowcount), strings); |
|
|
|
Set<String> errorSet = new HashSet<>(); |
|
|
|
Set<String> errorSet = new HashSet<>(); |
|
|
|
errorSet.add("1223"); |
|
|
|
errorSet.add("1223"); |
|
|
|
Assert.assertNotEquals(FormulaUtils.search(rowcount), errorSet); |
|
|
|
Assert.assertNotEquals(TableDataFormulaUtils.search4TableData(rowcount), errorSet); |
|
|
|
String str = "=COLNAME(\"test-测试\",COLCOUNT(\"列数嵌套123\"))"; |
|
|
|
String str = "=COLNAME(\"test-测试\",COLCOUNT(\"列数嵌套123\"))"; |
|
|
|
Set<String> qiantao = new HashSet<>(); |
|
|
|
Set<String> qiantao = new HashSet<>(); |
|
|
|
qiantao.add("test-测试"); |
|
|
|
qiantao.add("test-测试"); |
|
|
|
qiantao.add("列数嵌套123"); |
|
|
|
qiantao.add("列数嵌套123"); |
|
|
|
Assert.assertEquals(FormulaUtils.search(str), qiantao); |
|
|
|
Assert.assertEquals(TableDataFormulaUtils.search4TableData(str), qiantao); |
|
|
|
String str2 = "=sum(len(MAP(value(\"test-测试1\",COLNAME(\"test-测试2\",2),COLCOUNT(\"test-测试3\")),\"test-测试4\",COLNAME(\"test-测试5\",2),COLNAME(\"test-测试6\",4))),ROWCOUNT(\"test-测试7\"),len(TABLEDATAFIELDS(\"test-测试8\")))"; |
|
|
|
String str2 = "=sum(len(MAP(value(\"test-测试1\",COLNAME(\"test-测试2\",2),COLCOUNT(\"test-测试3\")),\"test-测试4\",COLNAME(\"test-测试5\",2),COLNAME(\"test-测试6\",4))),ROWCOUNT(\"test-测试7\"),len(TABLEDATAFIELDS(\"test-测试8\")))"; |
|
|
|
Set<String> qiantao2 = FormulaUtils.search(str2); |
|
|
|
Set<String> qiantao2 = TableDataFormulaUtils.search4TableData(str2); |
|
|
|
Assert.assertTrue(qiantao2.contains("test-测试1")); |
|
|
|
Assert.assertTrue(qiantao2.contains("test-测试1")); |
|
|
|
Assert.assertTrue(qiantao2.contains("test-测试2")); |
|
|
|
Assert.assertTrue(qiantao2.contains("test-测试2")); |
|
|
|
Assert.assertTrue(qiantao2.contains("test-测试3")); |
|
|
|
Assert.assertTrue(qiantao2.contains("test-测试3")); |
|
|
@ -51,7 +51,7 @@ public class FormulaUtilsTest extends TestCase { |
|
|
|
entity.setNewName("222"); |
|
|
|
entity.setNewName("222"); |
|
|
|
List<TableReplacementEntity> entities = new ArrayList<>(); |
|
|
|
List<TableReplacementEntity> entities = new ArrayList<>(); |
|
|
|
entities.add(entity); |
|
|
|
entities.add(entity); |
|
|
|
Assert.assertEquals(FormulaUtils.replace(rowcount, entities), "=ROWCOUNT(\"222\")"); |
|
|
|
Assert.assertEquals(TableDataFormulaUtils.replace4TableData(rowcount, entities), "=ROWCOUNT(\"222\")"); |
|
|
|
|
|
|
|
|
|
|
|
String colcount = "=COLCOUNT(\"test测试\")"; |
|
|
|
String colcount = "=COLCOUNT(\"test测试\")"; |
|
|
|
TableReplacementEntity entity1 = new TableReplacementEntity(); |
|
|
|
TableReplacementEntity entity1 = new TableReplacementEntity(); |
|
|
@ -59,7 +59,7 @@ public class FormulaUtilsTest extends TestCase { |
|
|
|
entity1.setNewName("替换"); |
|
|
|
entity1.setNewName("替换"); |
|
|
|
List<TableReplacementEntity> entities1 = new ArrayList<>(); |
|
|
|
List<TableReplacementEntity> entities1 = new ArrayList<>(); |
|
|
|
entities1.add(entity1); |
|
|
|
entities1.add(entity1); |
|
|
|
Assert.assertEquals(FormulaUtils.replace(colcount, entities1), "=COLCOUNT(\"替换\")"); |
|
|
|
Assert.assertEquals(TableDataFormulaUtils.replace4TableData(colcount, entities1), "=COLCOUNT(\"替换\")"); |
|
|
|
|
|
|
|
|
|
|
|
String colname = "=COLNAME(\"test测试\")"; |
|
|
|
String colname = "=COLNAME(\"test测试\")"; |
|
|
|
TableReplacementEntity entity2 = new TableReplacementEntity(); |
|
|
|
TableReplacementEntity entity2 = new TableReplacementEntity(); |
|
|
@ -67,7 +67,7 @@ public class FormulaUtilsTest extends TestCase { |
|
|
|
entity2.setNewName("替换123"); |
|
|
|
entity2.setNewName("替换123"); |
|
|
|
List<TableReplacementEntity> entities2 = new ArrayList<>(); |
|
|
|
List<TableReplacementEntity> entities2 = new ArrayList<>(); |
|
|
|
entities2.add(entity2); |
|
|
|
entities2.add(entity2); |
|
|
|
Assert.assertEquals(FormulaUtils.replace(colname, entities2), "=COLNAME(\"替换123\")"); |
|
|
|
Assert.assertEquals(TableDataFormulaUtils.replace4TableData(colname, entities2), "=COLNAME(\"替换123\")"); |
|
|
|
|
|
|
|
|
|
|
|
String TABLEDATAFIELDS = "=TABLEDATAFIELDS(\"test测试\")"; |
|
|
|
String TABLEDATAFIELDS = "=TABLEDATAFIELDS(\"test测试\")"; |
|
|
|
TableReplacementEntity entity3 = new TableReplacementEntity(); |
|
|
|
TableReplacementEntity entity3 = new TableReplacementEntity(); |
|
|
@ -75,7 +75,7 @@ public class FormulaUtilsTest extends TestCase { |
|
|
|
entity3.setNewName("替换111"); |
|
|
|
entity3.setNewName("替换111"); |
|
|
|
List<TableReplacementEntity> entities3 = new ArrayList<>(); |
|
|
|
List<TableReplacementEntity> entities3 = new ArrayList<>(); |
|
|
|
entities3.add(entity3); |
|
|
|
entities3.add(entity3); |
|
|
|
Assert.assertEquals(FormulaUtils.replace(TABLEDATAFIELDS, entities3), "=TABLEDATAFIELDS(\"替换111\")"); |
|
|
|
Assert.assertEquals(TableDataFormulaUtils.replace4TableData(TABLEDATAFIELDS, entities3), "=TABLEDATAFIELDS(\"替换111\")"); |
|
|
|
|
|
|
|
|
|
|
|
String test = "=sum(len(MAP(value(\"test-测试\",COLNAME(\"test-测试\",len(MAP(value(\"test-测试\",COLNAME(\"test-测试\",len(MAP(value(\"test-测试\",COLNAME(\"test-测试\",2),COLCOUNT(\"test-测试\")),\"test-测试\",COLNAME(\"test-测试\",2),COLNAME(\"test-测试\",4)))),COLCOUNT(\"test-测试\")),\"test-测试\",COLNAME(\"test-测试\",2),COLNAME(\"test-测试\",4)))),COLCOUNT(\"test-测试\")),\"test-测试\",COLNAME(\"test-测试\",2),COLNAME(\"test-测试\",4))),ROWCOUNT(\"test-测试\"),len(TABLEDATAFIELDS(\"test-测试\")))"; |
|
|
|
String test = "=sum(len(MAP(value(\"test-测试\",COLNAME(\"test-测试\",len(MAP(value(\"test-测试\",COLNAME(\"test-测试\",len(MAP(value(\"test-测试\",COLNAME(\"test-测试\",2),COLCOUNT(\"test-测试\")),\"test-测试\",COLNAME(\"test-测试\",2),COLNAME(\"test-测试\",4)))),COLCOUNT(\"test-测试\")),\"test-测试\",COLNAME(\"test-测试\",2),COLNAME(\"test-测试\",4)))),COLCOUNT(\"test-测试\")),\"test-测试\",COLNAME(\"test-测试\",2),COLNAME(\"test-测试\",4))),ROWCOUNT(\"test-测试\"),len(TABLEDATAFIELDS(\"test-测试\")))"; |
|
|
|
TableReplacementEntity entity4 = new TableReplacementEntity(); |
|
|
|
TableReplacementEntity entity4 = new TableReplacementEntity(); |
|
|
@ -83,7 +83,7 @@ public class FormulaUtilsTest extends TestCase { |
|
|
|
entity4.setNewName("test-测试的副本"); |
|
|
|
entity4.setNewName("test-测试的副本"); |
|
|
|
List<TableReplacementEntity> entities4 = new ArrayList<>(); |
|
|
|
List<TableReplacementEntity> entities4 = new ArrayList<>(); |
|
|
|
entities4.add(entity4); |
|
|
|
entities4.add(entity4); |
|
|
|
Assert.assertEquals(FormulaUtils.replace(test, entities4), "=sum(len(MAP(value(\"test-测试的副本\",COLNAME(\"test-测试的副本\",len(MAP(value(\"test-测试的副本\",COLNAME(\"test-测试的副本\",len(MAP(value(\"test-测试的副本\",COLNAME(\"test-测试的副本\",2),COLCOUNT(\"test-测试的副本\")),\"test-测试的副本\",COLNAME(\"test-测试的副本\",2),COLNAME(\"test-测试的副本\",4)))),COLCOUNT(\"test-测试的副本\")),\"test-测试的副本\",COLNAME(\"test-测试的副本\",2),COLNAME(\"test-测试的副本\",4)))),COLCOUNT(\"test-测试的副本\")),\"test-测试的副本\",COLNAME(\"test-测试的副本\",2),COLNAME(\"test-测试的副本\",4))),ROWCOUNT(\"test-测试的副本\"),len(TABLEDATAFIELDS(\"test-测试的副本\")))"); |
|
|
|
Assert.assertEquals(TableDataFormulaUtils.replace4TableData(test, entities4), "=sum(len(MAP(value(\"test-测试的副本\",COLNAME(\"test-测试的副本\",len(MAP(value(\"test-测试的副本\",COLNAME(\"test-测试的副本\",len(MAP(value(\"test-测试的副本\",COLNAME(\"test-测试的副本\",2),COLCOUNT(\"test-测试的副本\")),\"test-测试的副本\",COLNAME(\"test-测试的副本\",2),COLNAME(\"test-测试的副本\",4)))),COLCOUNT(\"test-测试的副本\")),\"test-测试的副本\",COLNAME(\"test-测试的副本\",2),COLNAME(\"test-测试的副本\",4)))),COLCOUNT(\"test-测试的副本\")),\"test-测试的副本\",COLNAME(\"test-测试的副本\",2),COLNAME(\"test-测试的副本\",4))),ROWCOUNT(\"test-测试的副本\"),len(TABLEDATAFIELDS(\"test-测试的副本\")))"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String testCircle = "=sum(len(MAP(value(\"test-测试1\",COLNAME(\"test-测试2\",len(MAP(value(\"test-测试3\",COLNAME(\"test-测试4\",len(MAP(value(\"test-测试\",COLNAME(\"test-测试\",2),COLCOUNT(\"test-测试\")),\"test-测试\",COLNAME(\"test-测试\",2),COLNAME(\"test-测试\",4)))),COLCOUNT(\"test-测试\")),\"test-测试\",COLNAME(\"test-测试\",2),COLNAME(\"test-测试\",4)))),COLCOUNT(\"test-测试\")),\"test-测试\",COLNAME(\"test-测试\",2),COLNAME(\"test-测试\",4))),ROWCOUNT(\"test-测试\"),len(TABLEDATAFIELDS(\"test-测试\")))"; |
|
|
|
String testCircle = "=sum(len(MAP(value(\"test-测试1\",COLNAME(\"test-测试2\",len(MAP(value(\"test-测试3\",COLNAME(\"test-测试4\",len(MAP(value(\"test-测试\",COLNAME(\"test-测试\",2),COLCOUNT(\"test-测试\")),\"test-测试\",COLNAME(\"test-测试\",2),COLNAME(\"test-测试\",4)))),COLCOUNT(\"test-测试\")),\"test-测试\",COLNAME(\"test-测试\",2),COLNAME(\"test-测试\",4)))),COLCOUNT(\"test-测试\")),\"test-测试\",COLNAME(\"test-测试\",2),COLNAME(\"test-测试\",4))),ROWCOUNT(\"test-测试\"),len(TABLEDATAFIELDS(\"test-测试\")))"; |
|
|
@ -104,7 +104,7 @@ public class FormulaUtilsTest extends TestCase { |
|
|
|
entities5.add(entity6); |
|
|
|
entities5.add(entity6); |
|
|
|
entities5.add(entity7); |
|
|
|
entities5.add(entity7); |
|
|
|
entities5.add(entity8); |
|
|
|
entities5.add(entity8); |
|
|
|
Assert.assertEquals(FormulaUtils.replace(testCircle, entities5), "=sum(len(MAP(value(\"test-测试2\",COLNAME(\"test-测试3\",len(MAP(value(\"test-测试4\",COLNAME(\"test-测试4\",len(MAP(value(\"test-测试的副本\",COLNAME(\"test-测试的副本\",2),COLCOUNT(\"test-测试的副本\")),\"test-测试的副本\",COLNAME(\"test-测试的副本\",2),COLNAME(\"test-测试的副本\",4)))),COLCOUNT(\"test-测试的副本\")),\"test-测试的副本\",COLNAME(\"test-测试的副本\",2),COLNAME(\"test-测试的副本\",4)))),COLCOUNT(\"test-测试的副本\")),\"test-测试的副本\",COLNAME(\"test-测试的副本\",2),COLNAME(\"test-测试的副本\",4))),ROWCOUNT(\"test-测试的副本\"),len(TABLEDATAFIELDS(\"test-测试的副本\")))"); |
|
|
|
Assert.assertEquals(TableDataFormulaUtils.replace4TableData(testCircle, entities5), "=sum(len(MAP(value(\"test-测试2\",COLNAME(\"test-测试3\",len(MAP(value(\"test-测试4\",COLNAME(\"test-测试4\",len(MAP(value(\"test-测试的副本\",COLNAME(\"test-测试的副本\",2),COLCOUNT(\"test-测试的副本\")),\"test-测试的副本\",COLNAME(\"test-测试的副本\",2),COLNAME(\"test-测试的副本\",4)))),COLCOUNT(\"test-测试的副本\")),\"test-测试的副本\",COLNAME(\"test-测试的副本\",2),COLNAME(\"test-测试的副本\",4)))),COLCOUNT(\"test-测试的副本\")),\"test-测试的副本\",COLNAME(\"test-测试的副本\",2),COLNAME(\"test-测试的副本\",4))),ROWCOUNT(\"test-测试的副本\"),len(TABLEDATAFIELDS(\"test-测试的副本\")))"); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |