-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEVALTest.java
More file actions
71 lines (61 loc) · 2.06 KB
/
Copy pathEVALTest.java
File metadata and controls
71 lines (61 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package cn.fay.test;
import cn.fay.excel.ExcelExportExecutor;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import java.lang.reflect.Field;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @author fay fay9395@gmail.com
* @date 2019-03-21 19:57.
*/
public class EVALTest {
Pattern pattern;
@Before
public void before() throws NoSuchFieldException, IllegalAccessException {
Field field = ExcelExportExecutor.class.getDeclaredField("EVAL_PATTERN");
field.setAccessible(true);
pattern = (Pattern) field.get(null);
}
@Test
public void test() {
Matcher matcher = pattern.matcher("` 3 * ( 1 + 4 ) `");
Assert.assertTrue(matcher.find());
Assert.assertEquals(matcher.group(1), " 3 * ( 1 + 4 ) ");
}
@Test
public void test2() {
String value = "` 3 * ( 1 + 4 ) ` && ` 1 - 1 `";
Matcher matcher = pattern.matcher(value);
while (matcher.find()) {
value = value.replace(matcher.group(), matcher.group(1));
}
Assert.assertEquals(value, " 3 * ( 1 + 4 ) && 1 - 1 ");
}
@Test
public void test3() throws Exception {
String[] INDEX_MAP = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"};
for (int index = 0; index < 100; index++) {
int h = index / 26;
int l = index % 26;
System.out.println(h <= 0 ? INDEX_MAP[l] : INDEX_MAP[h - 1] + INDEX_MAP[l]);
}
}
@Test
public void test4() {
String exprs[] =new String[]{ "`${column}-1`${row}/`${column}-9`${row}"
};
int row = 1;
int column = 14;
for(String expr:exprs) {
ExcelExportExecutor.handleDefaultValuePlaceHolder(expr, row, column);
}
}
@Test
public void test5() throws Exception {
System.out.println(Double.valueOf(String.valueOf("13.0")).intValue());
}
}