Unverified 提交 5c6935dd authored 作者: Noel Grandin's avatar Noel Grandin 提交者: GitHub

Merge pull request #711 from ilm-informatique/TestFunctions-Locale

TestFunctions less english dependent
...@@ -17,6 +17,7 @@ import java.util.Currency; ...@@ -17,6 +17,7 @@ import java.util.Currency;
import java.util.GregorianCalendar; import java.util.GregorianCalendar;
import java.util.Locale; import java.util.Locale;
import java.util.TimeZone; import java.util.TimeZone;
import org.h2.api.ErrorCode; import org.h2.api.ErrorCode;
import org.h2.message.DbException; import org.h2.message.DbException;
...@@ -653,7 +654,7 @@ public class ToChar { ...@@ -653,7 +654,7 @@ public class ToChar {
cal.get(Calendar.DAY_OF_MONTH))); cal.get(Calendar.DAY_OF_MONTH)));
i += 2; i += 2;
} else if ((cap = containsAt(format, i, "DY")) != null) { } else if ((cap = containsAt(format, i, "DY")) != null) {
String day = StringUtils.toUpperEnglish(new SimpleDateFormat("EEE").format(ts)); String day = new SimpleDateFormat("EEE").format(ts);
output.append(cap.apply(day)); output.append(cap.apply(day));
i += 2; i += 2;
} else if ((cap = containsAt(format, i, "DAY")) != null) { } else if ((cap = containsAt(format, i, "DAY")) != null) {
...@@ -884,7 +885,7 @@ public class ToChar { ...@@ -884,7 +885,7 @@ public class ToChar {
} }
/** Represents a capitalization / casing strategy. */ /** Represents a capitalization / casing strategy. */
private enum Capitalization { static public enum Capitalization {
/** /**
* All letters are uppercased. * All letters are uppercased.
...@@ -911,7 +912,7 @@ public class ToChar { ...@@ -911,7 +912,7 @@ public class ToChar {
* @return the capitalization / casing strategy which should be used * @return the capitalization / casing strategy which should be used
* when the first and second letters have the specified casing * when the first and second letters have the specified casing
*/ */
public static Capitalization toCapitalization(Boolean up1, Boolean up2) { private static Capitalization toCapitalization(Boolean up1, Boolean up2) {
if (up1 == null) { if (up1 == null) {
return Capitalization.CAPITALIZE; return Capitalization.CAPITALIZE;
} else if (up2 == null) { } else if (up2 == null) {
......
...@@ -27,6 +27,7 @@ import java.sql.SQLException; ...@@ -27,6 +27,7 @@ import java.sql.SQLException;
import java.sql.Statement; import java.sql.Statement;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.sql.Types; import java.sql.Types;
import java.text.DecimalFormatSymbols;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -53,6 +54,7 @@ import org.h2.util.DateTimeUtils; ...@@ -53,6 +54,7 @@ import org.h2.util.DateTimeUtils;
import org.h2.util.IOUtils; import org.h2.util.IOUtils;
import org.h2.util.New; import org.h2.util.New;
import org.h2.util.StringUtils; import org.h2.util.StringUtils;
import org.h2.util.ToChar.Capitalization;
import org.h2.util.ToDateParser; import org.h2.util.ToDateParser;
import org.h2.value.Value; import org.h2.value.Value;
...@@ -1484,18 +1486,18 @@ public class TestFunctions extends TestBase implements AggregateFunction { ...@@ -1484,18 +1486,18 @@ public class TestFunctions extends TestBase implements AggregateFunction {
boolean daylight = tz.inDaylightTime(new Date()); boolean daylight = tz.inDaylightTime(new Date());
String tzShortName = tz.getDisplayName(daylight, TimeZone.SHORT); String tzShortName = tz.getDisplayName(daylight, TimeZone.SHORT);
String tzLongName = tz.getID(); String tzLongName = tz.getID();
final Timestamp timestamp1979 = Timestamp.valueOf("1979-11-12 08:12:34.560");
stat.executeUpdate("CREATE TABLE T (X TIMESTAMP(6))"); stat.executeUpdate("CREATE TABLE T (X TIMESTAMP(6))");
stat.executeUpdate("INSERT INTO T VALUES " + stat.executeUpdate("INSERT INTO T VALUES " +
"(TIMESTAMP '1979-11-12 08:12:34.560')"); "(TIMESTAMP '"+timestamp1979.toString()+"')");
stat.executeUpdate("CREATE TABLE U (X TIMESTAMP(6))"); stat.executeUpdate("CREATE TABLE U (X TIMESTAMP(6))");
stat.executeUpdate("INSERT INTO U VALUES " + stat.executeUpdate("INSERT INTO U VALUES " +
"(TIMESTAMP '-100-01-15 14:04:02.120')"); "(TIMESTAMP '-100-01-15 14:04:02.120')");
assertResult("1979-11-12 08:12:34.56", stat, "SELECT X FROM T"); assertResult("1979-11-12 08:12:34.56", stat, "SELECT X FROM T");
assertResult("-100-01-15 14:04:02.12", stat, "SELECT X FROM U"); assertResult("-100-01-15 14:04:02.12", stat, "SELECT X FROM U");
String expected = String.format("%tb", String expected = String.format("%tb", timestamp1979).toUpperCase();
Timestamp.valueOf("1979-11-12 08:12:34.560")).toUpperCase();
assertResult("12-" + expected + "-79 08.12.34.560000 AM", stat, assertResult("12-" + expected + "-79 08.12.34.560000 AM", stat,
"SELECT TO_CHAR(X) FROM T"); "SELECT TO_CHAR(X) FROM T");
assertResult("- / , . ; : text - /", stat, assertResult("- / , . ; : text - /", stat,
...@@ -1544,8 +1546,7 @@ public class TestFunctions extends TestBase implements AggregateFunction { ...@@ -1544,8 +1546,7 @@ public class TestFunctions extends TestBase implements AggregateFunction {
assertResult("am", stat, "SELECT TO_CHAR(X, 'pm') FROM T"); assertResult("am", stat, "SELECT TO_CHAR(X, 'pm') FROM T");
assertResult("2", stat, "SELECT TO_CHAR(X, 'D') FROM T"); assertResult("2", stat, "SELECT TO_CHAR(X, 'D') FROM T");
assertResult("2", stat, "SELECT TO_CHAR(X, 'd') FROM T"); assertResult("2", stat, "SELECT TO_CHAR(X, 'd') FROM T");
expected = String.format("%tA", expected = String.format("%tA", timestamp1979);
Timestamp.valueOf("1979-11-12 08:12:34.560"));
expected = expected.substring(0, 1).toUpperCase() + expected.substring(1); expected = expected.substring(0, 1).toUpperCase() + expected.substring(1);
String spaces = " "; String spaces = " ";
String first9 = (expected + spaces).substring(0, 9); String first9 = (expected + spaces).substring(0, 9);
...@@ -1564,18 +1565,16 @@ public class TestFunctions extends TestBase implements AggregateFunction { ...@@ -1564,18 +1565,16 @@ public class TestFunctions extends TestBase implements AggregateFunction {
assertResult("316", stat, "SELECT TO_CHAR(X, 'DdD') FROM T"); assertResult("316", stat, "SELECT TO_CHAR(X, 'DdD') FROM T");
assertResult("316", stat, "SELECT TO_CHAR(X, 'dDD') FROM T"); assertResult("316", stat, "SELECT TO_CHAR(X, 'dDD') FROM T");
assertResult("316", stat, "SELECT TO_CHAR(X, 'ddd') FROM T"); assertResult("316", stat, "SELECT TO_CHAR(X, 'ddd') FROM T");
expected = String.format("%1$tA, %1$tB %1$te, %1$tY", expected = String.format("%1$tA, %1$tB %1$te, %1$tY", timestamp1979);
Timestamp.valueOf("1979-11-12 08:12:34.560"));
assertResult(expected, stat, assertResult(expected, stat,
"SELECT TO_CHAR(X, 'DL') FROM T"); "SELECT TO_CHAR(X, 'DL') FROM T");
assertResult("11/12/1979", stat, "SELECT TO_CHAR(X, 'DS') FROM T"); assertResult("11/12/1979", stat, "SELECT TO_CHAR(X, 'DS') FROM T");
assertResult("11/12/1979", stat, "SELECT TO_CHAR(X, 'Ds') FROM T"); assertResult("11/12/1979", stat, "SELECT TO_CHAR(X, 'Ds') FROM T");
assertResult("11/12/1979", stat, "SELECT TO_CHAR(X, 'dS') FROM T"); assertResult("11/12/1979", stat, "SELECT TO_CHAR(X, 'dS') FROM T");
assertResult("11/12/1979", stat, "SELECT TO_CHAR(X, 'ds') FROM T"); assertResult("11/12/1979", stat, "SELECT TO_CHAR(X, 'ds') FROM T");
expected = String.format("%1$ta", expected = String.format("%1$ta", timestamp1979);
Timestamp.valueOf("1979-11-12 08:12:34.560"));
assertResult(expected.toUpperCase(), stat, "SELECT TO_CHAR(X, 'DY') FROM T"); assertResult(expected.toUpperCase(), stat, "SELECT TO_CHAR(X, 'DY') FROM T");
assertResult(expected, stat, "SELECT TO_CHAR(X, 'Dy') FROM T"); assertResult(Capitalization.CAPITALIZE.apply(expected), stat, "SELECT TO_CHAR(X, 'Dy') FROM T");
assertResult(expected.toLowerCase(), stat, "SELECT TO_CHAR(X, 'dy') FROM T"); assertResult(expected.toLowerCase(), stat, "SELECT TO_CHAR(X, 'dy') FROM T");
assertResult(expected.toLowerCase(), stat, "SELECT TO_CHAR(X, 'dY') FROM T"); assertResult(expected.toLowerCase(), stat, "SELECT TO_CHAR(X, 'dY') FROM T");
assertResult("08:12:34.560000", stat, assertResult("08:12:34.560000", stat,
...@@ -1618,8 +1617,7 @@ public class TestFunctions extends TestBase implements AggregateFunction { ...@@ -1618,8 +1617,7 @@ public class TestFunctions extends TestBase implements AggregateFunction {
assertResult("11", stat, "SELECT TO_CHAR(X, 'Mm') FROM T"); assertResult("11", stat, "SELECT TO_CHAR(X, 'Mm') FROM T");
assertResult("11", stat, "SELECT TO_CHAR(X, 'mM') FROM T"); assertResult("11", stat, "SELECT TO_CHAR(X, 'mM') FROM T");
assertResult("11", stat, "SELECT TO_CHAR(X, 'mm') FROM T"); assertResult("11", stat, "SELECT TO_CHAR(X, 'mm') FROM T");
expected = String.format("%1$tb", expected = String.format("%1$tb", timestamp1979);
Timestamp.valueOf("1979-11-12 08:12:34.560"));
expected = expected.substring(0, 1).toUpperCase() + expected.substring(1); expected = expected.substring(0, 1).toUpperCase() + expected.substring(1);
assertResult(expected.toUpperCase(), stat, assertResult(expected.toUpperCase(), stat,
"SELECT TO_CHAR(X, 'MON') FROM T"); "SELECT TO_CHAR(X, 'MON') FROM T");
...@@ -1627,16 +1625,15 @@ public class TestFunctions extends TestBase implements AggregateFunction { ...@@ -1627,16 +1625,15 @@ public class TestFunctions extends TestBase implements AggregateFunction {
"SELECT TO_CHAR(X, 'Mon') FROM T"); "SELECT TO_CHAR(X, 'Mon') FROM T");
assertResult(expected.toLowerCase(), stat, assertResult(expected.toLowerCase(), stat,
"SELECT TO_CHAR(X, 'mon') FROM T"); "SELECT TO_CHAR(X, 'mon') FROM T");
expected = String.format("%1$tB", expected = String.format("%1$tB", timestamp1979);
Timestamp.valueOf("1979-11-12 08:12:34.560"));
expected = (expected + " ").substring(0, 9); expected = (expected + " ").substring(0, 9);
assertResult(expected.toUpperCase(), stat, assertResult(expected.toUpperCase(), stat,
"SELECT TO_CHAR(X, 'MONTH') FROM T"); "SELECT TO_CHAR(X, 'MONTH') FROM T");
assertResult(expected, stat, assertResult(Capitalization.CAPITALIZE.apply(expected), stat,
"SELECT TO_CHAR(X, 'Month') FROM T"); "SELECT TO_CHAR(X, 'Month') FROM T");
assertResult(expected.toLowerCase(), stat, assertResult(expected.toLowerCase(), stat,
"SELECT TO_CHAR(X, 'month') FROM T"); "SELECT TO_CHAR(X, 'month') FROM T");
assertResult(expected.trim(), stat, assertResult(Capitalization.CAPITALIZE.apply(expected.trim()), stat,
"SELECT TO_CHAR(X, 'fmMonth') FROM T"); "SELECT TO_CHAR(X, 'fmMonth') FROM T");
assertResult("4", stat, "SELECT TO_CHAR(X, 'Q') FROM T"); assertResult("4", stat, "SELECT TO_CHAR(X, 'Q') FROM T");
assertResult("XI", stat, "SELECT TO_CHAR(X, 'RM') FROM T"); assertResult("XI", stat, "SELECT TO_CHAR(X, 'RM') FROM T");
...@@ -1646,7 +1643,11 @@ public class TestFunctions extends TestBase implements AggregateFunction { ...@@ -1646,7 +1643,11 @@ public class TestFunctions extends TestBase implements AggregateFunction {
assertResult("1979", stat, "SELECT TO_CHAR(X, 'RRRR') FROM T"); assertResult("1979", stat, "SELECT TO_CHAR(X, 'RRRR') FROM T");
assertResult("34", stat, "SELECT TO_CHAR(X, 'SS') FROM T"); assertResult("34", stat, "SELECT TO_CHAR(X, 'SS') FROM T");
assertResult("29554", stat, "SELECT TO_CHAR(X, 'SSSSS') FROM T"); assertResult("29554", stat, "SELECT TO_CHAR(X, 'SSSSS') FROM T");
assertResult("8:12:34 AM", stat, "SELECT TO_CHAR(X, 'TS') FROM T"); expected = new SimpleDateFormat("h:mm:ss aa").format(timestamp1979);
if (Locale.getDefault().getLanguage().equals(Locale.ENGLISH.getLanguage())) {
assertEquals("8:12:34 AM", expected);
}
assertResult(expected, stat, "SELECT TO_CHAR(X, 'TS') FROM T");
assertResult(tzLongName, stat, "SELECT TO_CHAR(X, 'TZR') FROM T"); assertResult(tzLongName, stat, "SELECT TO_CHAR(X, 'TZR') FROM T");
assertResult(tzShortName, stat, "SELECT TO_CHAR(X, 'TZD') FROM T"); assertResult(tzShortName, stat, "SELECT TO_CHAR(X, 'TZD') FROM T");
expected = String.format("%f", 1.1).substring(1, 2); expected = String.format("%f", 1.1).substring(1, 2);
...@@ -1933,14 +1934,17 @@ public class TestFunctions extends TestBase implements AggregateFunction { ...@@ -1933,14 +1934,17 @@ public class TestFunctions extends TestBase implements AggregateFunction {
assertResult("0.001", stat, "select to_char(0.001, 'FM0.099') from dual;"); assertResult("0.001", stat, "select to_char(0.001, 'FM0.099') from dual;");
assertResult("0.001", stat, "select to_char(0.0012, 'FM0.099') from dual;"); assertResult("0.001", stat, "select to_char(0.0012, 'FM0.099') from dual;");
assertResult("0.002", stat, "select to_char(0.0019, 'FM0.099') from dual;"); assertResult("0.002", stat, "select to_char(0.0019, 'FM0.099') from dual;");
assertResult("0.0", stat, "select to_char(0, 'FM0D099') from dual;"); final char decimalSeparator = DecimalFormatSymbols.getInstance().getDecimalSeparator();
assertResult("0.00", stat, "select to_char(0., 'FM0D009') from dual;"); final String oneDecimal = "0" + decimalSeparator + "0";
assertResult("0.", stat, "select to_char(0, 'FM0D9') from dual;"); final String twoDecimals = "0" + decimalSeparator + "00";
assertResult("0.0", stat, "select to_char(0.0, 'FM0D099') from dual;"); assertResult(oneDecimal, stat, "select to_char(0, 'FM0D099') from dual;");
assertResult("0.00", stat, "select to_char(0.00, 'FM0D009') from dual;"); assertResult(twoDecimals, stat, "select to_char(0., 'FM0D009') from dual;");
assertResult("0.00", stat, "select to_char(0, 'FM0D009') from dual;"); assertResult("0" + decimalSeparator, stat, "select to_char(0, 'FM0D9') from dual;");
assertResult("0.0", stat, "select to_char(0, 'FM0D09') from dual;"); assertResult(oneDecimal, stat, "select to_char(0.0, 'FM0D099') from dual;");
assertResult("0.0", stat, "select to_char(0, 'FM0D0') from dual;"); assertResult(twoDecimals, stat, "select to_char(0.00, 'FM0D009') from dual;");
assertResult(twoDecimals, stat, "select to_char(0, 'FM0D009') from dual;");
assertResult(oneDecimal, stat, "select to_char(0, 'FM0D09') from dual;");
assertResult(oneDecimal, stat, "select to_char(0, 'FM0D0') from dual;");
conn.close(); conn.close();
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论