-
Notifications
You must be signed in to change notification settings - Fork 583
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #459 from nurolopher/master
Comments on migrations files
- Loading branch information
Showing
4 changed files
with
78 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
library/src/main/java/com/orm/util/MigrationFileParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.orm.util; | ||
|
||
/** | ||
* Created by Nursultan Turdaliev on 12/4/15. | ||
*/ | ||
public class MigrationFileParser { | ||
|
||
private String content; | ||
|
||
/** | ||
* @param content | ||
*/ | ||
public MigrationFileParser(String content){ | ||
this.content = content.replaceAll("(\\/\\*([\\s\\S]*?)\\*\\/)|(--(.)*)|(\n)",""); | ||
} | ||
|
||
public String[] getStatements(){ | ||
return this.content.split(";"); | ||
} | ||
|
||
} |
48 changes: 48 additions & 0 deletions
48
library/src/test/java/com/orm/util/MigrationFileParserTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.orm.util; | ||
|
||
import com.orm.util.MigrationFileParser; | ||
|
||
import org.junit.Test; | ||
import org.junit.Before; | ||
|
||
import java.lang.String; | ||
|
||
import static junit.framework.Assert.assertEquals; | ||
|
||
public class MigrationFileParserTest{ | ||
MigrationFileParser emptyFile; | ||
|
||
@Test | ||
public void testSingleLineStatement() | ||
{ | ||
MigrationFileParser singleLineComment = new MigrationFileParser("insert into table--comment"); | ||
|
||
String statements[] = singleLineComment.getStatements(); | ||
assertEquals("Testing single line statement size",1,statements.length); | ||
assertEquals("Testing single line statement content","insert into table",statements[0]); | ||
|
||
singleLineComment = new MigrationFileParser("insert into table--comment\n"); | ||
|
||
singleLineComment.getStatements(); | ||
assertEquals("Testing single line statement size",1,statements.length); | ||
assertEquals("Testing single line statement content","insert into table",statements[0]); | ||
} | ||
@Test | ||
public void testMultiLineComment(){ | ||
MigrationFileParser multiLineComment = new MigrationFileParser("insert into table /**comment \n new line 2 \n new line 3 */hello"); | ||
|
||
String statements[] = multiLineComment.getStatements(); | ||
assertEquals("Testing multiline statement size",1,statements.length); | ||
assertEquals("Testing multiline comment","insert into table hello",statements[0]); | ||
} | ||
|
||
@Test | ||
public void testMixedComment(){ | ||
MigrationFileParser mixedComment = new MigrationFileParser("insert into/*multiline\n **comment*/--comment"); | ||
|
||
String statements[] = mixedComment.getStatements(); | ||
|
||
assertEquals("Testing mixed comment statement size",1,statements.length); | ||
assertEquals("Testing mixed comment statments", "insert into", statements[0]); | ||
} | ||
} |