github.com/systematiccaos/gorm@v1.22.6/statement_test.go (about) 1 package gorm 2 3 import ( 4 "fmt" 5 "reflect" 6 "testing" 7 8 "github.com/systematiccaos/gorm/clause" 9 ) 10 11 func TestWhereCloneCorruption(t *testing.T) { 12 for whereCount := 1; whereCount <= 8; whereCount++ { 13 t.Run(fmt.Sprintf("w=%d", whereCount), func(t *testing.T) { 14 s := new(Statement) 15 for w := 0; w < whereCount; w++ { 16 s = s.clone() 17 s.AddClause(clause.Where{ 18 Exprs: s.BuildCondition(fmt.Sprintf("where%d", w)), 19 }) 20 } 21 22 s1 := s.clone() 23 s1.AddClause(clause.Where{ 24 Exprs: s.BuildCondition("FINAL1"), 25 }) 26 s2 := s.clone() 27 s2.AddClause(clause.Where{ 28 Exprs: s.BuildCondition("FINAL2"), 29 }) 30 31 if reflect.DeepEqual(s1.Clauses["WHERE"], s2.Clauses["WHERE"]) { 32 t.Errorf("Where conditions should be different") 33 } 34 }) 35 } 36 } 37 38 func TestNameMatcher(t *testing.T) { 39 for k, v := range map[string]string{ 40 "table.name": "name", 41 "`table`.`name`": "name", 42 "'table'.'name'": "name", 43 "'table'.name": "name", 44 } { 45 if matches := nameMatcher.FindStringSubmatch(k); len(matches) < 2 || matches[1] != v { 46 t.Errorf("failed to match value: %v, got %v, expect: %v", k, matches, v) 47 } 48 } 49 }