소스 검색

Replace tolower (#1064)

* session: save an allocation in isUseStatement

* session: add a test for isUseStatement
Vincent Rischmann 7 년 전
부모
커밋
a2c732f85a
2개의 변경된 파일28개의 추가작업 그리고 1개의 파일을 삭제
  1. 1 1
      session.go
  2. 27 0
      session_test.go

+ 1 - 1
session.go

@@ -953,7 +953,7 @@ func isUseStatement(stmt string) bool {
 		return false
 	}
 
-	return strings.ToLower(stmt[0:3]) == "use"
+	return strings.EqualFold(stmt[0:3], "use")
 }
 
 // Iter executes the query and returns an iterator capable of iterating

+ 27 - 0
session_test.go

@@ -263,3 +263,30 @@ func TestConsistencyNames(t *testing.T) {
 		}
 	}
 }
+
+func TestIsUseStatement(t *testing.T) {
+	testCases := []struct {
+		input string
+		exp   bool
+	}{
+		{"USE foo", true},
+		{"USe foo", true},
+		{"UsE foo", true},
+		{"Use foo", true},
+		{"uSE foo", true},
+		{"uSe foo", true},
+		{"usE foo", true},
+		{"use foo", true},
+		{"SELECT ", false},
+		{"UPDATE ", false},
+		{"INSERT ", false},
+		{"", false},
+	}
+
+	for _, tc := range testCases {
+		v := isUseStatement(tc.input)
+		if v != tc.exp {
+			t.Fatalf("expected %v but got %v for statement %q", tc.exp, v, tc.input)
+		}
+	}
+}