mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-08-13 12:54:12 +02:00
Preserve column before/after comments through .transform()
Refs #762 The before comment comes before the column definition - the after comment is anything after it but before its trailing comma.
This commit is contained in:
parent
b432e686ca
commit
b37b8cf8c8
6 changed files with 171 additions and 18 deletions
|
|
@ -4,7 +4,13 @@ import hypothesis.strategies as st
|
|||
import pytest
|
||||
from hypothesis import given
|
||||
|
||||
from sqlite_utils.create_table_parser import Check, ParseError, parse_checks
|
||||
from sqlite_utils.create_table_parser import (
|
||||
Check,
|
||||
ColumnComments,
|
||||
ParseError,
|
||||
parse_checks,
|
||||
parse_column_comments,
|
||||
)
|
||||
|
||||
|
||||
def test_parse_column_and_table_checks():
|
||||
|
|
@ -46,6 +52,26 @@ def test_comments_are_trivia_not_constraints():
|
|||
]
|
||||
|
||||
|
||||
def test_parse_comments_owned_by_columns():
|
||||
sql = """
|
||||
CREATE TABLE t (
|
||||
-- Before id
|
||||
id /* Between name and type */ INTEGER /* After id */,
|
||||
/* Between column definitions */
|
||||
value TEXT CHECK(value != '') /* After value */,
|
||||
/* Before a table constraint, not a column */
|
||||
CHECK(value != 'forbidden')
|
||||
)
|
||||
"""
|
||||
assert parse_column_comments(sql) == {
|
||||
"id": ColumnComments(before="-- Before id", after="/* After id */"),
|
||||
"value": ColumnComments(
|
||||
before="/* Between column definitions */",
|
||||
after="/* After value */",
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"expression,expected",
|
||||
[
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue