github.com/dolthub/go-mysql-server@v0.18.0/sql/sql_mode_test.go (about) 1 // Copyright 2023 Dolthub, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package sql 16 17 import ( 18 "testing" 19 20 "github.com/stretchr/testify/assert" 21 ) 22 23 func TestSqlMode(t *testing.T) { 24 // Test that ANSI mode includes ANSI_QUOTES mode 25 sqlMode := NewSqlModeFromString("only_full_group_by,ansi") 26 assert.True(t, sqlMode.AnsiQuotes()) 27 assert.True(t, sqlMode.ModeEnabled("ansi")) 28 assert.True(t, sqlMode.ModeEnabled("ANSI")) 29 assert.True(t, sqlMode.ModeEnabled("ONLY_FULL_GROUP_BY")) 30 assert.False(t, sqlMode.ModeEnabled("fake_mode")) 31 assert.True(t, sqlMode.ParserOptions().AnsiQuotes) 32 assert.Equal(t, "ANSI,ONLY_FULL_GROUP_BY", sqlMode.String()) 33 34 // Test a mixed case SQL_MODE string where only ANSI_QUOTES is enabled 35 sqlMode = NewSqlModeFromString("AnSi_quotEs") 36 assert.True(t, sqlMode.AnsiQuotes()) 37 assert.True(t, sqlMode.ModeEnabled("ansi_quotes")) 38 assert.True(t, sqlMode.ModeEnabled("ANSI_quoTes")) 39 assert.False(t, sqlMode.ModeEnabled("fake_mode")) 40 assert.True(t, sqlMode.ParserOptions().AnsiQuotes) 41 assert.Equal(t, "ANSI_QUOTES", sqlMode.String()) 42 43 // Test when SQL_MODE does not include ANSI_QUOTES 44 sqlMode = NewSqlModeFromString("ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES") 45 assert.False(t, sqlMode.AnsiQuotes()) 46 assert.True(t, sqlMode.ModeEnabled("STRICT_TRANS_TABLES")) 47 assert.False(t, sqlMode.ModeEnabled("ansi_quotes")) 48 assert.False(t, sqlMode.ParserOptions().AnsiQuotes) 49 assert.Equal(t, "ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES", sqlMode.String()) 50 }