99 */
1010package net .sf .jsqlparser .parser ;
1111
12+ import java .io .ByteArrayInputStream ;
13+ import java .io .StringReader ;
14+ import java .nio .charset .StandardCharsets ;
15+ import java .util .ArrayList ;
16+ import java .util .List ;
1217import net .sf .jsqlparser .JSQLParserException ;
1318import net .sf .jsqlparser .expression .Expression ;
1419import net .sf .jsqlparser .expression .LongValue ;
1520import net .sf .jsqlparser .expression .Parenthesis ;
1621import net .sf .jsqlparser .expression .operators .arithmetic .Addition ;
1722import net .sf .jsqlparser .expression .operators .arithmetic .Multiplication ;
1823import net .sf .jsqlparser .schema .Column ;
24+ import net .sf .jsqlparser .statement .Statement ;
1925import net .sf .jsqlparser .statement .Statements ;
2026import org .junit .After ;
2127import org .junit .AfterClass ;
2228import static org .junit .Assert .*;
23-
24- import java .io .ByteArrayInputStream ;
25- import java .io .StringReader ;
26- import java .nio .charset .StandardCharsets ;
27-
2829import org .junit .Before ;
2930import org .junit .BeforeClass ;
3031import org .junit .Test ;
@@ -81,12 +82,12 @@ public void testParseExpressionNonPartial() throws Exception {
8182
8283 @ Test (expected = JSQLParserException .class )
8384 public void testParseExpressionFromStringFail () throws Exception {
84- CCJSqlParserUtil .parse ("whatever$" );
85+ CCJSqlParserUtil .parse ("whatever$" );
8586 }
8687
8788 @ Test (expected = JSQLParserException .class )
8889 public void testParseExpressionFromRaderFail () throws Exception {
89- CCJSqlParserUtil .parse (new StringReader ("whatever$" ));
90+ CCJSqlParserUtil .parse (new StringReader ("whatever$" ));
9091 }
9192
9293 @ Test
@@ -103,19 +104,19 @@ public void testParseCondExpression() throws Exception {
103104
104105 @ Test (expected = JSQLParserException .class )
105106 public void testParseCondExpressionFail () throws Exception {
106- CCJSqlParserUtil .parseCondExpression (";" );
107+ CCJSqlParserUtil .parseCondExpression (";" );
107108
108109 }
109110
110111 @ Test (expected = JSQLParserException .class )
111112 public void testParseFromStreamFail () throws Exception {
112- CCJSqlParserUtil .parse (new ByteArrayInputStream ("BLA" .getBytes (StandardCharsets .UTF_8 )));
113+ CCJSqlParserUtil .parse (new ByteArrayInputStream ("BLA" .getBytes (StandardCharsets .UTF_8 )));
113114
114115 }
115116
116117 @ Test (expected = JSQLParserException .class )
117118 public void testParseFromStreamWithEncodingFail () throws Exception {
118- CCJSqlParserUtil .parse (new ByteArrayInputStream ("BLA" .getBytes (StandardCharsets .UTF_8 )), StandardCharsets .UTF_8 .name ());
119+ CCJSqlParserUtil .parse (new ByteArrayInputStream ("BLA" .getBytes (StandardCharsets .UTF_8 )), StandardCharsets .UTF_8 .name ());
119120
120121 }
121122
@@ -160,14 +161,36 @@ public void testParseStatementsIssue691() throws Exception {
160161 + "SELECT * FROM dual;\n " , result .toString ());
161162 }
162163
164+ @ Test
165+ public void testStreamStatementsIssue777 () throws Exception {
166+ final List <Statement > list = new ArrayList <>();
167+
168+ CCJSqlParserUtil .streamStatements (new StatementListener () {
169+ @ Override
170+ public void accept (Statement statement ) {
171+ list .add (statement );
172+ }
173+ }, new ByteArrayInputStream (("select * from dual;\n "
174+ + "select\n "
175+ + "*\n "
176+ + "from\n "
177+ + "dual;\n "
178+ + "\n "
179+ + "-- some comment\n "
180+ + "select *\n "
181+ + "from dual;" ).getBytes (StandardCharsets .UTF_8 )), "UTF-8" );
182+
183+ assertEquals (list .size (), 3 );
184+ }
185+
163186 @ Test (expected = JSQLParserException .class )
164187 public void testParseStatementsFail () throws Exception {
165- CCJSqlParserUtil .parseStatements ("select * from dual;WHATEVER!!" );
188+ CCJSqlParserUtil .parseStatements ("select * from dual;WHATEVER!!" );
166189 }
167190
168191 @ Test (expected = JSQLParserException .class )
169192 public void testParseASTFail () throws Exception {
170- CCJSqlParserUtil .parseAST ("select * from dual;WHATEVER!!" );
193+ CCJSqlParserUtil .parseAST ("select * from dual;WHATEVER!!" );
171194 }
172195
173196 @ Test
@@ -180,14 +203,14 @@ public void testParseStatementsIssue691_2() throws Exception {
180203
181204 @ Test
182205 public void testParseStatementIssue742 () throws Exception {
183- Statements result = CCJSqlParserUtil .parseStatements ("CREATE TABLE `table_name` (\n " +
184- " `id` bigint(20) NOT NULL AUTO_INCREMENT,\n " +
185- " `another_column_id` bigint(20) NOT NULL COMMENT 'column id as sent by SYSTEM',\n " +
186- " PRIMARY KEY (`id`),\n " +
187- " UNIQUE KEY `uk_another_column_id` (`another_column_id`)\n " +
188- ")" );
189- assertEquals ("CREATE TABLE `table_name` (`id` bigint (20) NOT NULL AUTO_INCREMENT, `another_column_id` " +
190- "bigint (20) NOT NULL COMMENT 'column id as sent by SYSTEM', PRIMARY KEY (`id`), UNIQUE KEY `uk_another_column_id` " +
191- "(`another_column_id`));\n " , result .toString ());
206+ Statements result = CCJSqlParserUtil .parseStatements ("CREATE TABLE `table_name` (\n "
207+ + " `id` bigint(20) NOT NULL AUTO_INCREMENT,\n "
208+ + " `another_column_id` bigint(20) NOT NULL COMMENT 'column id as sent by SYSTEM',\n "
209+ + " PRIMARY KEY (`id`),\n "
210+ + " UNIQUE KEY `uk_another_column_id` (`another_column_id`)\n "
211+ + ")" );
212+ assertEquals ("CREATE TABLE `table_name` (`id` bigint (20) NOT NULL AUTO_INCREMENT, `another_column_id` "
213+ + "bigint (20) NOT NULL COMMENT 'column id as sent by SYSTEM', PRIMARY KEY (`id`), UNIQUE KEY `uk_another_column_id` "
214+ + "(`another_column_id`));\n " , result .toString ());
192215 }
193216}
0 commit comments