提交 3e2bf8da authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Use rows / rows (ordered) in TestScript

上级 0462af5c
...@@ -20,6 +20,7 @@ import java.sql.ResultSet; ...@@ -20,6 +20,7 @@ import java.sql.ResultSet;
import java.sql.ResultSetMetaData; import java.sql.ResultSetMetaData;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Statement; import java.sql.Statement;
import java.util.ArrayDeque;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
...@@ -53,7 +54,7 @@ public class TestScript extends TestDb { ...@@ -53,7 +54,7 @@ public class TestScript extends TestDb {
private LineNumberReader in; private LineNumberReader in;
private PrintStream out; private PrintStream out;
private final ArrayList<String[]> result = new ArrayList<>(); private final ArrayList<String[]> result = new ArrayList<>();
private String putBack; private final ArrayDeque<String> putBack = new ArrayDeque<>();
private StringBuilder errors; private StringBuilder errors;
private Random random = new Random(1); private Random random = new Random(1);
...@@ -199,7 +200,7 @@ public class TestScript extends TestDb { ...@@ -199,7 +200,7 @@ public class TestScript extends TestDb {
in = null; in = null;
out = null; out = null;
result.clear(); result.clear();
putBack = null; putBack.clear();
errors = null; errors = null;
if (statements == null) { if (statements == null) {
...@@ -224,16 +225,13 @@ public class TestScript extends TestDb { ...@@ -224,16 +225,13 @@ public class TestScript extends TestDb {
} }
private String readLine() throws IOException { private String readLine() throws IOException {
if (putBack != null) { String s = putBack.pollFirst();
String s = putBack; return s != null ? s : readNextLine();
putBack = null;
return s;
}
while (true) {
String s = in.readLine();
if (s == null) {
return null;
} }
private String readNextLine() throws IOException {
String s;
while ((s = in.readLine()) != null) {
if (s.startsWith("#")) { if (s.startsWith("#")) {
int end = s.indexOf('#', 1); int end = s.indexOf('#', 1);
if (end < 3) { if (end < 3) {
...@@ -265,10 +263,15 @@ public class TestScript extends TestDb { ...@@ -265,10 +263,15 @@ public class TestScript extends TestDb {
} }
} }
s = s.trim(); s = s.trim();
if (s.length() > 0) { if (!s.isEmpty()) {
return s; break;
} }
} }
return s;
}
public void putBack(String line) {
putBack.addLast(line);
} }
private void testFile(String inFile, boolean allowReconnect) throws Exception { private void testFile(String inFile, boolean allowReconnect) throws Exception {
...@@ -448,7 +451,6 @@ public class TestScript extends TestDb { ...@@ -448,7 +451,6 @@ public class TestScript extends TestDb {
} }
private void writeResultSet(String sql, ResultSet rs) throws Exception { private void writeResultSet(String sql, ResultSet rs) throws Exception {
boolean ordered = StringUtils.toLowerEnglish(sql).contains("order by");
ResultSetMetaData meta = rs.getMetaData(); ResultSetMetaData meta = rs.getMetaData();
int len = meta.getColumnCount(); int len = meta.getColumnCount();
int[] max = new int[len]; int[] max = new int[len];
...@@ -474,7 +476,7 @@ public class TestScript extends TestDb { ...@@ -474,7 +476,7 @@ public class TestScript extends TestDb {
} }
rs.close(); rs.close();
String line = readLine(); String line = readLine();
putBack = line; putBack(line);
if (line != null && line.startsWith(">> ")) { if (line != null && line.startsWith(">> ")) {
switch (result.size()) { switch (result.size()) {
case 0: case 0:
...@@ -493,6 +495,22 @@ public class TestScript extends TestDb { ...@@ -493,6 +495,22 @@ public class TestScript extends TestDb {
return; return;
} }
} }
boolean ordered;
for (;;) {
line = readNextLine();
if (line == null) {
addWriteResultError("<row count>", "<eof>");
return;
}
putBack(line);
if (line.startsWith("> rows: ")) {
ordered = false;
break;
} else if (line.startsWith("> rows (ordered): ")) {
ordered = true;
break;
}
}
writeResult(sql, format(head, max), null); writeResult(sql, format(head, max), null);
writeResult(sql, format(null, max), null); writeResult(sql, format(null, max), null);
String[] array = new String[result.size()]; String[] array = new String[result.size()];
...@@ -575,7 +593,7 @@ public class TestScript extends TestDb { ...@@ -575,7 +593,7 @@ public class TestScript extends TestDb {
} }
} else { } else {
addWriteResultError("<nothing>", s); addWriteResultError("<nothing>", s);
putBack = compare; putBack(compare);
} }
write(s); write(s);
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论