github.com/wangyougui/gf/v2@v2.6.5/encoding/gjson/gjson_z_unit_internal_test.go (about)

     1  // Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
     2  //
     3  // This Source Code Form is subject to the terms of the MIT License.
     4  // If a copy of the MIT was not distributed with this file,
     5  // You can obtain one at https://github.com/wangyougui/gf.
     6  
     7  package gjson
     8  
     9  import (
    10  	"testing"
    11  
    12  	"github.com/wangyougui/gf/v2/test/gtest"
    13  )
    14  
    15  func Test_checkDataType(t *testing.T) {
    16  	gtest.C(t, func(t *gtest.T) {
    17  		data := []byte(`
    18  bb           = """
    19                     dig := dig;                         END;"""
    20  `)
    21  		t.Assert(checkDataType(data), "toml")
    22  	})
    23  
    24  	gtest.C(t, func(t *gtest.T) {
    25  		data := []byte(`
    26  # 模板引擎目录
    27  viewpath = "/home/www/templates/"
    28  # MySQL数据库配置
    29  [redis]
    30  dd = 11
    31  [redis]
    32      disk  = "127.0.0.1:6379,0"
    33      cache = "127.0.0.1:6379,1"
    34  `)
    35  		t.Assert(checkDataType(data), "toml")
    36  	})
    37  
    38  	gtest.C(t, func(t *gtest.T) {
    39  		data := []byte(`
    40  "gf.gvalid.rule.required"             = "The :attribute field is required"
    41  "gf.gvalid.rule.required-if"          = "The :attribute field is required"
    42  "gf.gvalid.rule.required-unless"      = "The :attribute field is required"
    43  "gf.gvalid.rule.required-with"        = "The :attribute field is required"
    44  "gf.gvalid.rule.required-with-all"    = "The :attribute field is required"
    45  "gf.gvalid.rule.required-without"     = "The :attribute field is required"
    46  "gf.gvalid.rule.required-without-all" = "The :attribute field is required"
    47  "gf.gvalid.rule.date"                 = "The :attribute value is not a valid date"
    48  "gf.gvalid.rule.date-format"          = "The :attribute value does not match the format :format"
    49  "gf.gvalid.rule.email"                = "The :attribute value must be a valid email address"
    50  "gf.gvalid.rule.phone"                = "The :attribute value must be a valid phone number"
    51  "gf.gvalid.rule.telephone"            = "The :attribute value must be a valid telephone number"
    52  "gf.gvalid.rule.passport"             = "The :attribute value is not a valid passport format"
    53  "gf.gvalid.rule.password"             = "The :attribute value is not a valid passport format"
    54  "gf.gvalid.rule.password2"            = "The :attribute value is not a valid passport format"
    55  "gf.gvalid.rule.password3"            = "The :attribute value is not a valid passport format"
    56  "gf.gvalid.rule.postcode"             = "The :attribute value is not a valid passport format"
    57  "gf.gvalid.rule.resident-id"          = "The :attribute value is not a valid resident id number"
    58  "gf.gvalid.rule.bank-card"            = "The :attribute value must be a valid bank card number"
    59  "gf.gvalid.rule.qq"                   = "The :attribute value must be a valid QQ number"
    60  "gf.gvalid.rule.ip"                   = "The :attribute value must be a valid IP address"
    61  "gf.gvalid.rule.ipv4"                 = "The :attribute value must be a valid IPv4 address"
    62  "gf.gvalid.rule.ipv6"                 = "The :attribute value must be a valid IPv6 address"
    63  "gf.gvalid.rule.mac"                  = "The :attribute value must be a valid MAC address"
    64  "gf.gvalid.rule.url"                  = "The :attribute value must be a valid URL address"
    65  "gf.gvalid.rule.domain"               = "The :attribute value must be a valid domain format"
    66  "gf.gvalid.rule.length"               = "The :attribute value length must be between :min and :max"
    67  "gf.gvalid.rule.min-length"           = "The :attribute value length must be equal or greater than :min"
    68  "gf.gvalid.rule.max-length"           = "The :attribute value length must be equal or lesser than :max"
    69  "gf.gvalid.rule.between"              = "The :attribute value must be between :min and :max"
    70  "gf.gvalid.rule.min"                  = "The :attribute value must be equal or greater than :min"
    71  "gf.gvalid.rule.max"                  = "The :attribute value must be equal or lesser than :max"
    72  "gf.gvalid.rule.json"                 = "The :attribute value must be a valid JSON string"
    73  "gf.gvalid.rule.xml"                  = "The :attribute value must be a valid XML string"
    74  "gf.gvalid.rule.array"                = "The :attribute value must be an array"
    75  "gf.gvalid.rule.integer"              = "The :attribute value must be an integer"
    76  "gf.gvalid.rule.float"                = "The :attribute value must be a float"
    77  "gf.gvalid.rule.boolean"              = "The :attribute value field must be true or false"
    78  "gf.gvalid.rule.same"                 = "The :attribute value must be the same as field :field"
    79  "gf.gvalid.rule.different"            = "The :attribute value must be different from field :field"
    80  "gf.gvalid.rule.in"                   = "The :attribute value is not in acceptable range"
    81  "gf.gvalid.rule.not-in"               = "The :attribute value is not in acceptable range"
    82  "gf.gvalid.rule.regex"                = "The :attribute value is invalid"
    83  `)
    84  		// fmt.Println(gregex.IsMatch(`^[\s\t\n\r]*[\w\-]+\s*:\s*".+"`, data))
    85  		// fmt.Println(gregex.IsMatch(`^[\s\t\n\r]*[\w\-]+\s*:\s*\w+`, data))
    86  		// fmt.Println(gregex.IsMatch(`[\s\t\n\r]+[\w\-]+\s*:\s*".+"`, data))
    87  		// fmt.Println(gregex.IsMatch(`[\n\r]+[\w\-\s\t]+\s*:\s*\w+`, data))
    88  		// fmt.Println(gregex.MatchString(`[\n\r]+[\w\-\s\t]+\s*:\s*\w+`, string(data)))
    89  		t.Assert(checkDataType(data), "toml")
    90  	})
    91  
    92  	gtest.C(t, func(t *gtest.T) {
    93  		data := []byte(`
    94  [default]
    95  db.engine         = mysql
    96  db.max.idle.conns = 5
    97  db.max.open.conns = 100
    98  allow_ips         =
    99  api.key           =
   100  api.secret        =
   101  enable_tls        = false
   102  concurrency.queue = 500
   103  auth_secret       = 63358e6f3daf0e5775ec3fb4d2516b01d41530bf30960aa76972f6ce7e08552f
   104  ca_file           =
   105  cert_file         =
   106  key_file          =
   107  host_port         = 8088
   108  log_path          = /Users/zhaosuji/go/src/git.medlinker.com/foundations/gocron/log
   109  #k8s-api地址(只提供内网访问)
   110  k8s-inner-api = http://127.0.0.1:8081/kube/add
   111  conf_dir = ./config
   112  app_conf = ./config/app.ini
   113  `)
   114  		t.Assert(checkDataType(data), "ini")
   115  	})
   116  
   117  	gtest.C(t, func(t *gtest.T) {
   118  		data := []byte(`
   119  # API Server
   120  [server]
   121      address = ":8199"
   122  
   123  # Jenkins
   124  [jenkins]
   125      url          = "https://jenkins-swimlane.com"
   126      nodeJsStaticBuildCmdTpl = """
   127  npm i --registry=https://registry.npm.taobao.org
   128  wget http://consul.infra:8500/v1/kv/app_{{.SwimlaneName}}/{{.RepoName}}/.env.qa?raw=true -O ./env.qa
   129  npm run build:qa
   130  """
   131  `)
   132  		t.Assert(checkDataType(data), "toml")
   133  	})
   134  }