github.com/searKing/golang/go@v1.2.117/database/sql/named_test.go (about)

     1  // Copyright 2022 The searKing Author. 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  
     5  package sql_test
     6  
     7  import (
     8  	"testing"
     9  
    10  	"github.com/searKing/golang/go/database/sql"
    11  )
    12  
    13  func TestCompliantName(t *testing.T) {
    14  	table := []struct {
    15  		Q, R string
    16  	}{
    17  		{
    18  			Q: `a`,
    19  			R: `a`,
    20  		},
    21  		{
    22  			Q: `t.a`,
    23  			R: `t_a`,
    24  		},
    25  		{
    26  			Q: `':foo'`,
    27  			R: `__foo_`,
    28  		},
    29  		{
    30  			Q: `'a:b:c' || first_name`,
    31  			R: `_a_b_c_____first_name`,
    32  		},
    33  		{
    34  			Q: `'::ABC:_:'`,
    35  			R: `___ABC____`,
    36  		},
    37  	}
    38  
    39  	for i, test := range table {
    40  		qr := sql.CompliantName(test.Q)
    41  		if qr != test.R {
    42  			t.Errorf("#%d. got %q, want %q", i, qr, test.R)
    43  		}
    44  	}
    45  }