github.com/pingcap/tidb/parser@v0.0.0-20231013125129-93a834a6bf8d/mysql/const_test.go (about)

     1  // Copyright 2021 PingCAP, 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  // See the License for the specific language governing permissions and
    12  // limitations under the License.
    13  
    14  package mysql
    15  
    16  import (
    17  	"testing"
    18  
    19  	"github.com/stretchr/testify/require"
    20  )
    21  
    22  func TestSQLMode(t *testing.T) {
    23  	// ref https://dev.mysql.com/doc/internals/en/query-event.html#q-sql-mode-code,
    24  	hardCode := []struct {
    25  		code  SQLMode
    26  		value int
    27  	}{{
    28  		ModeRealAsFloat, 0x00000001,
    29  	}, {
    30  		ModePipesAsConcat, 0x00000002,
    31  	}, {
    32  		ModeANSIQuotes, 0x00000004,
    33  	}, {
    34  		ModeIgnoreSpace, 0x00000008,
    35  	}, {
    36  		ModeNotUsed, 0x00000010,
    37  	}, {
    38  		ModeOnlyFullGroupBy, 0x00000020,
    39  	}, {
    40  		ModeNoUnsignedSubtraction, 0x00000040,
    41  	}, {
    42  		ModeNoDirInCreate, 0x00000080,
    43  	}, {
    44  		ModePostgreSQL, 0x00000100,
    45  	}, {
    46  		ModeOracle, 0x00000200,
    47  	}, {
    48  		ModeMsSQL, 0x00000400,
    49  	}, {
    50  		ModeDb2, 0x00000800,
    51  	}, {
    52  		ModeMaxdb, 0x00001000,
    53  	}, {
    54  		ModeNoKeyOptions, 0x00002000,
    55  	}, {
    56  		ModeNoTableOptions, 0x00004000,
    57  	}, {
    58  		ModeNoFieldOptions, 0x00008000,
    59  	}, {
    60  		ModeMySQL323, 0x00010000,
    61  	}, {
    62  		ModeMySQL40, 0x00020000,
    63  	}, {
    64  		ModeANSI, 0x00040000,
    65  	}, {
    66  		ModeNoAutoValueOnZero, 0x00080000,
    67  	}, {
    68  		ModeNoBackslashEscapes, 0x00100000,
    69  	}, {
    70  		ModeStrictTransTables, 0x00200000,
    71  	}, {
    72  		ModeStrictAllTables, 0x00400000,
    73  	}, {
    74  		ModeNoZeroInDate, 0x00800000,
    75  	}, {
    76  		ModeNoZeroDate, 0x01000000,
    77  	}, {
    78  		ModeInvalidDates, 0x02000000,
    79  	}, {
    80  		ModeErrorForDivisionByZero, 0x04000000,
    81  	}, {
    82  		ModeTraditional, 0x08000000,
    83  	}, {
    84  		ModeNoAutoCreateUser, 0x10000000,
    85  	}, {
    86  		ModeHighNotPrecedence, 0x20000000,
    87  	}, {
    88  		ModeNoEngineSubstitution, 0x40000000,
    89  	}, {
    90  		ModePadCharToFullLength, 0x80000000,
    91  	}}
    92  
    93  	for _, ca := range hardCode {
    94  		require.Equal(t, ca.value, int(ca.code))
    95  	}
    96  }