2025-02-13 14:53:05 +01:00
|
|
|
import unittest
|
|
|
|
|
|
|
|
from sqlglot.tokens import Tokenizer
|
|
|
|
|
|
|
|
|
|
|
|
class TestTokens(unittest.TestCase):
|
|
|
|
def test_comment_attachment(self):
|
|
|
|
tokenizer = Tokenizer()
|
|
|
|
sql_comment = [
|
2025-02-13 14:56:25 +01:00
|
|
|
("/*comment*/ foo", ["comment"]),
|
|
|
|
("/*comment*/ foo --test", ["comment", "test"]),
|
|
|
|
("--comment\nfoo --test", ["comment", "test"]),
|
|
|
|
("foo --comment", ["comment"]),
|
|
|
|
("foo", []),
|
|
|
|
("foo /*comment 1*/ /*comment 2*/", ["comment 1", "comment 2"]),
|
2025-02-13 14:53:05 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
for sql, comment in sql_comment:
|
2025-02-13 14:56:25 +01:00
|
|
|
self.assertEqual(tokenizer.tokenize(sql)[0].comments, comment)
|