Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Shardingsphere
提交
fb77124c
Shardingsphere
项目概览
apache
/
Shardingsphere
通知
56
Star
3
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Shardingsphere
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
fb77124c
编写于
5月 12, 2017
作者:
T
terrymanu
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'parser' of
https://github.com/dangdangdotcom/sharding-jdbc
into parser
上级
78df234b
dfcf4580
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
62 addition
and
3 deletion
+62
-3
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/sharding/parsing/lexer/analyzer/TokenizerTest.java
...me/rdb/sharding/parsing/lexer/analyzer/TokenizerTest.java
+62
-3
未找到文件。
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/sharding/parsing/lexer/analyzer/TokenizerTest.java
浏览文件 @
fb77124c
...
...
@@ -19,6 +19,7 @@ package com.dangdang.ddframe.rdb.sharding.parsing.lexer.analyzer;
import
com.dangdang.ddframe.rdb.sharding.parsing.lexer.token.Literals
;
import
com.dangdang.ddframe.rdb.sharding.parsing.lexer.token.Token
;
import
com.dangdang.ddframe.rdb.sharding.parsing.lexer.token.TokenType
;
import
org.junit.Test
;
import
org.mockito.internal.matchers.apachecommons.ReflectionEquals
;
...
...
@@ -89,10 +90,68 @@ public final class TokenizerTest {
tokenizer
.
skipComment
();
}
@Test
public
void
assertSkipHint
()
{
String
comment
=
"/*--xyz \n WHERE XX=1 //xyz*/"
;
String
sql
=
"SELECT * FROM XXX_TABLE "
+
comment
+
"WHERE YY>2"
;
Tokenizer
tokenizer
=
new
Tokenizer
(
sql
,
dictionary
,
sql
.
indexOf
(
"/"
));
int
expected
=
sql
.
indexOf
(
"/"
)
+
comment
.
length
();
assertThat
(
tokenizer
.
skipHint
(),
is
(
expected
));
}
@Test
(
expected
=
UnterminatedCharException
.
class
)
public
void
assertSkipHintUnterminatedCharException
()
{
String
comment
=
"/*--xyz \n WHERE XX=1 //xyz"
;
String
sql
=
"SELECT * FROM XXX_TABLE "
+
comment
;
Tokenizer
tokenizer
=
new
Tokenizer
(
sql
,
dictionary
,
sql
.
indexOf
(
"/"
));
tokenizer
.
skipHint
();
}
@Test
public
void
assertScanVariable
()
{
String
sql
=
"SELECT * FROM XXX_TABLE @var WHERE YY>2"
;
Tokenizer
tokenizer
=
new
Tokenizer
(
sql
,
dictionary
,
sql
.
indexOf
(
"@"
));
assertTrue
(
new
ReflectionEquals
(
tokenizer
.
scanVariable
()).
matches
(
new
Token
(
Literals
.
VARIABLE
,
"@var"
,
28
)));
String
sql
=
"SELECT * FROM XXX_TABLE %s WHERE YY>2"
;
assertScanVariable
(
sql
,
"@var"
);
assertScanVariable
(
sql
,
"@@var"
);
}
private
void
assertScanVariable
(
final
String
sql
,
final
String
literals
)
{
String
formatSql
=
String
.
format
(
sql
,
literals
);
Tokenizer
tokenizer
=
new
Tokenizer
(
formatSql
,
dictionary
,
formatSql
.
indexOf
(
"@"
));
assertTrue
(
new
ReflectionEquals
(
tokenizer
.
scanVariable
()).
matches
(
new
Token
(
Literals
.
VARIABLE
,
literals
,
formatSql
.
indexOf
(
"WHERE"
)
-
1
)));
}
@Test
public
void
assertScanNumber
()
{
String
sql
=
"SELECT * FROM XXX_TABLE WHERE XX=%s"
;
assertScanNumber
(
sql
,
"123"
,
Literals
.
INT
);
assertScanNumber
(
sql
,
"-123"
,
Literals
.
INT
);
assertScanNumber
(
sql
,
"123.0"
,
Literals
.
FLOAT
);
assertScanNumber
(
sql
,
"123e4"
,
Literals
.
FLOAT
);
assertScanNumber
(
sql
,
"123E4"
,
Literals
.
FLOAT
);
assertScanNumber
(
sql
,
"123e+4"
,
Literals
.
FLOAT
);
assertScanNumber
(
sql
,
"123E+4"
,
Literals
.
FLOAT
);
assertScanNumber
(
sql
,
"123e-4"
,
Literals
.
FLOAT
);
assertScanNumber
(
sql
,
"123E-4"
,
Literals
.
FLOAT
);
assertScanNumber
(
sql
,
".5"
,
Literals
.
FLOAT
);
assertScanNumber
(
sql
,
"123f"
,
Literals
.
FLOAT
);
assertScanNumber
(
sql
,
"123F"
,
Literals
.
FLOAT
);
assertScanNumber
(
sql
,
".5f"
,
Literals
.
FLOAT
);
assertScanNumber
(
sql
,
".5F"
,
Literals
.
FLOAT
);
assertScanNumber
(
sql
,
"123d"
,
Literals
.
FLOAT
);
assertScanNumber
(
sql
,
"123D"
,
Literals
.
FLOAT
);
assertScanHexDecimal
(
sql
,
"0x1e"
,
Literals
.
HEX
);
assertScanHexDecimal
(
sql
,
"0x-1e"
,
Literals
.
HEX
);
}
private
void
assertScanNumber
(
final
String
sql
,
final
String
literals
,
final
TokenType
type
)
{
String
formatSql
=
String
.
format
(
sql
,
literals
);
Tokenizer
tokenizer
=
new
Tokenizer
(
formatSql
,
dictionary
,
sql
.
indexOf
(
"="
)
+
1
);
assertTrue
(
new
ReflectionEquals
(
tokenizer
.
scanNumber
()).
matches
(
new
Token
(
type
,
literals
,
formatSql
.
length
())));
}
private
void
assertScanHexDecimal
(
final
String
sql
,
final
String
literals
,
final
TokenType
type
)
{
String
formatSql
=
String
.
format
(
sql
,
literals
);
Tokenizer
tokenizer
=
new
Tokenizer
(
formatSql
,
dictionary
,
sql
.
indexOf
(
"="
)
+
1
);
assertTrue
(
new
ReflectionEquals
(
tokenizer
.
scanHexDecimal
()).
matches
(
new
Token
(
type
,
literals
,
formatSql
.
length
())));
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录