1package clause_test
2
3import (
4	"reflect"
5	"strings"
6	"sync"
7	"testing"
8
9	"gorm.io/gorm"
10	"gorm.io/gorm/clause"
11	"gorm.io/gorm/schema"
12	"gorm.io/gorm/utils/tests"
13)
14
15var db, _ = gorm.Open(tests.DummyDialector{}, nil)
16
17func checkBuildClauses(t *testing.T, clauses []clause.Interface, result string, vars []interface{}) {
18	var (
19		buildNames    []string
20		buildNamesMap = map[string]bool{}
21		user, _       = schema.Parse(&tests.User{}, &sync.Map{}, db.NamingStrategy)
22		stmt          = gorm.Statement{DB: db, Table: user.Table, Schema: user, Clauses: map[string]clause.Clause{}}
23	)
24
25	for _, c := range clauses {
26		if _, ok := buildNamesMap[c.Name()]; !ok {
27			buildNames = append(buildNames, c.Name())
28			buildNamesMap[c.Name()] = true
29		}
30
31		stmt.AddClause(c)
32	}
33
34	stmt.Build(buildNames...)
35
36	if strings.TrimSpace(stmt.SQL.String()) != result {
37		t.Errorf("SQL expects %v got %v", result, stmt.SQL.String())
38	}
39
40	if !reflect.DeepEqual(stmt.Vars, vars) {
41		t.Errorf("Vars expects %+v got %v", stmt.Vars, vars)
42	}
43}
44