diff options
| author | Ian Robertson <ian.robertson@capitalone.com> | 2019-01-14 09:38:51 -0500 |
|---|---|---|
| committer | Andi Albrecht <albrecht.andi@gmail.com> | 2019-03-10 08:53:11 +0100 |
| commit | 170010e7d709f2145169d23482d006dc56856256 (patch) | |
| tree | fda0d6b590dac5ef20c9af42e44a9169e99614bd | |
| parent | ad8d1d1e4c9b6bbd21c255b9421685944c4d96e0 (diff) | |
| download | sqlparse-170010e7d709f2145169d23482d006dc56856256.tar.gz | |
Add in slash comment functionality
| -rw-r--r-- | sqlparse/keywords.py | 4 | ||||
| -rw-r--r-- | tests/files/slashcomment.sql | 5 | ||||
| -rw-r--r-- | tests/test_split.py | 16 |
3 files changed, 23 insertions, 2 deletions
diff --git a/sqlparse/keywords.py b/sqlparse/keywords.py index 6e22c8e..d9fdb89 100644 --- a/sqlparse/keywords.py +++ b/sqlparse/keywords.py @@ -21,10 +21,10 @@ def is_keyword(value): SQL_REGEX = { 'root': [ - (r'(--|# )\+.*?(\r\n|\r|\n|$)', tokens.Comment.Single.Hint), + (r'(--|//|# )\+.*?(\r\n|\r|\n|$)', tokens.Comment.Single.Hint), (r'/\*\+[\s\S]*?\*/', tokens.Comment.Multiline.Hint), - (r'(--|# ).*?(\r\n|\r|\n|$)', tokens.Comment.Single), + (r'(--|//|# ).*?(\r\n|\r|\n|$)', tokens.Comment.Single), (r'/\*[\s\S]*?\*/', tokens.Comment.Multiline), (r'(\r\n|\r|\n)', tokens.Newline), diff --git a/tests/files/slashcomment.sql b/tests/files/slashcomment.sql new file mode 100644 index 0000000..90e3089 --- /dev/null +++ b/tests/files/slashcomment.sql @@ -0,0 +1,5 @@ +select * from user; +//select * from host; +select * from user; +select * // foo; +from foo; diff --git a/tests/test_split.py b/tests/test_split.py index a93e3d4..ccb84a8 100644 --- a/tests/test_split.py +++ b/tests/test_split.py @@ -52,6 +52,22 @@ def test_split_dashcomments_eol(s): assert len(stmts) == 1 +def test_split_slashcomments(load_file): + sql = load_file('slashcomment.sql') + stmts = sqlparse.parse(sql) + assert len(stmts) == 3 + assert ''.join(str(q) for q in stmts) == sql + + +@pytest.mark.parametrize('s', ['select foo; // comment\n', + 'select foo; // comment\r', + 'select foo; // comment\r\n', + 'select foo; // comment']) +def test_split_slashcomments_eol(s): + stmts = sqlparse.parse(s) + assert len(stmts) == 1 + + def test_split_begintag(load_file): sql = load_file('begintag.sql') stmts = sqlparse.parse(sql) |
