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