Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ir/quote.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ var reservedWords = map[string]bool{
"within": true,
}

// NeedsQuoting checks if an identifier needs to be quoted
func NeedsQuoting(identifier string) bool {
// needsQuoting checks if an identifier needs to be quoted
func needsQuoting(identifier string) bool {
if identifier == "" {
return false
}
Expand Down Expand Up @@ -150,7 +150,7 @@ func NeedsQuoting(identifier string) bool {

// QuoteIdentifier adds quotes to an identifier if needed
func QuoteIdentifier(identifier string) string {
if NeedsQuoting(identifier) {
if needsQuoting(identifier) {
return `"` + identifier + `"`
}
return identifier
Expand Down
63 changes: 0 additions & 63 deletions ir/quote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,56 +5,6 @@ import (
"testing"
)

func TestNeedsQuoting(t *testing.T) {
type testCase struct {
name string
identifier string
expected bool
}
tests := []testCase{
{"simple lowercase", "users", false},
{"reserved word", "user", true},
{"limit keyword", "limit", true},
{"bigint type", "bigint", true},
{"boolean type", "boolean", true},
{"update command", "update", true},
{"delete command", "delete", true},
{"insert command", "insert", true},
{"returning clause", "returning", true},
{"offset keyword", "offset", true},
{"inner join", "inner", true},
{"outer join", "outer", true},
{"camelCase", "firstName", true},
{"UPPERCASE", "USERS", true},
{"MixedCase", "MyApp", true},
{"with underscore", "user_name", false},
{"starts with underscore", "_private", false},
{"starts with number", "1table", true},
{"contains dash", "user-table", true},
{"empty string", "", false},
}

// adding all keywords as test cases to ensure all values are checked, there may be some duplicates
// in the tests above to ensure that there is also the opportunity to visually inspect a subset
// of the test cases.
for reservedWord := range reservedWords {
tests = append(tests, testCase{
name: fmt.Sprintf("reserved word: %q", reservedWord),
identifier: reservedWord,
expected: true,
})
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := NeedsQuoting(tt.identifier)
if result != tt.expected {
t.Errorf("NeedsQuoting(%q) = %v; want %v", tt.identifier, result, tt.expected)
}
})
}
}

func TestQuoteIdentifier(t *testing.T) {
type testCase struct {
name string
Expand All @@ -64,19 +14,6 @@ func TestQuoteIdentifier(t *testing.T) {

tests := []testCase{
{"simple lowercase", "users", "users"},
{"reserved word", "user", `"user"`},
{"limit keyword", "limit", `"limit"`},
{"bigint type", "bigint", `"bigint"`},
{"boolean type", "boolean", `"boolean"`},
{"update command", "update", `"update"`},
{"delete command", "delete", `"delete"`},
{"insert command", "insert", `"insert"`},
{"returning clause", "returning", `"returning"`},
{"offset keyword", "offset", `"offset"`},
{"inner join", "inner", `"inner"`},
{"outer join", "outer", `"outer"`},
{"for clause", "for", `"for"`},
{"filter keyword", "filter", `"filter"`},
{"camelCase", "firstName", `"firstName"`},
{"UPPERCASE", "USERS", `"USERS"`},
{"MixedCase", "MyApp", `"MyApp"`},
Expand Down