MCPcopy
hub / github.com/sqldef/sqldef / TestTiDBComments

Function TestTiDBComments

parser/parser_test.go:645–699  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

643}
644
645func TestTiDBComments(t *testing.T) {
646 testCases := []struct {
647 name string
648 sql string
649 options map[string]string
650 }{
651 {
652 "clustered_index",
653 "CREATE TABLE t (id bigint NOT NULL, PRIMARY KEY (id) /*T![clustered_index] CLUSTERED */)",
654 nil,
655 },
656 {
657 "nonclustered_index",
658 "CREATE TABLE t (id bigint NOT NULL AUTO_INCREMENT, PRIMARY KEY (id) /*T![clustered_index] NONCLUSTERED */)",
659 nil,
660 },
661 {
662 "auto_id_cache",
663 "CREATE TABLE t (id bigint NOT NULL, PRIMARY KEY (id)) /*T![auto_id_cache] AUTO_ID_CACHE=1 */",
664 map[string]string{"AUTO_ID_CACHE": "1"},
665 },
666 {
667 "shard_row_id_bits",
668 "CREATE TABLE t (a int, b int) /*T! SHARD_ROW_ID_BITS=4 PRE_SPLIT_REGIONS=3 */",
669 map[string]string{"SHARD_ROW_ID_BITS": "4", "PRE_SPLIT_REGIONS": "3"},
670 },
671 {
672 "empty_ungated_comment",
673 "CREATE TABLE t (a int) /*T! */",
674 nil,
675 },
676 {
677 "unclosed_feature_bracket",
678 "CREATE TABLE t (a int) /*T![unclosed */",
679 nil,
680 },
681 }
682 for _, tc := range testCases {
683 t.Run(tc.name, func(t *testing.T) {
684 tree, err := ParseDDL(tc.sql, ParserModeMysql)
685 if err != nil {
686 t.Fatalf("parse error: %v", err)
687 }
688 ddl := tree.(*DDL)
689 if ddl.TableSpec == nil {
690 t.Fatal("expected TableSpec")
691 }
692 for key, expected := range tc.options {
693 if actual := ddl.TableSpec.Options[key]; actual != expected {
694 t.Errorf("option %q: expected %q, got %q", key, expected, actual)
695 }
696 }
697 })
698 }
699}
700
701// TestInvalidCustomOperators tests that invalid PostgreSQL custom operators produce errors
702func TestInvalidCustomOperators(t *testing.T) {

Callers

nothing calls this directly

Calls 4

ParseDDLFunction · 0.85
FatalfMethod · 0.65
FatalMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected