Simple and Powerful ORM for Go, support mysql,postgres,tidb,sqlite3,mssql,oracle https://xorm.io
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.1KB

  1. // Copyright 2019 The Xorm Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package xorm
  5. import (
  6. "strings"
  7. "testing"
  8. "github.com/stretchr/testify/assert"
  9. )
  10. func TestQuoteTo(t *testing.T) {
  11. test := func(t *testing.T, expected string, value string) {
  12. buf := &strings.Builder{}
  13. quoteTo(buf, "[]", value)
  14. assert.EqualValues(t, expected, buf.String())
  15. }
  16. test(t, "[mytable]", "mytable")
  17. test(t, "[mytable]", "`mytable`")
  18. test(t, "[mytable]", `[mytable]`)
  19. test(t, `["mytable"]`, `"mytable"`)
  20. test(t, "[myschema].[mytable]", "myschema.mytable")
  21. test(t, "[myschema].[mytable]", "`myschema`.mytable")
  22. test(t, "[myschema].[mytable]", "myschema.`mytable`")
  23. test(t, "[myschema].[mytable]", "`myschema`.`mytable`")
  24. test(t, "[myschema].[mytable]", `[myschema].mytable`)
  25. test(t, "[myschema].[mytable]", `myschema.[mytable]`)
  26. test(t, "[myschema].[mytable]", `[myschema].[mytable]`)
  27. test(t, `["myschema].[mytable"]`, `"myschema.mytable"`)
  28. buf := &strings.Builder{}
  29. quoteTo(buf, "", "noquote")
  30. assert.EqualValues(t, "noquote", buf.String())
  31. }