github.com/gogf/gf/v2@v2.7.4/text/gstr/gstr_z_unit_domain_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  // go test *.go -bench=".*"
     8  
     9  package gstr_test
    10  
    11  import (
    12  	"testing"
    13  
    14  	"github.com/gogf/gf/v2/test/gtest"
    15  	"github.com/gogf/gf/v2/text/gstr"
    16  )
    17  
    18  func Test_IsSubDomain(t *testing.T) {
    19  	gtest.C(t, func(t *gtest.T) {
    20  		main := "goframe.org"
    21  		t.Assert(gstr.IsSubDomain("goframe.org", main), true)
    22  		t.Assert(gstr.IsSubDomain("s.goframe.org", main), true)
    23  		t.Assert(gstr.IsSubDomain("s.s.goframe.org", main), true)
    24  		t.Assert(gstr.IsSubDomain("s.s.goframe.org:8080", main), true)
    25  		t.Assert(gstr.IsSubDomain("johng.cn", main), false)
    26  		t.Assert(gstr.IsSubDomain("s.johng.cn", main), false)
    27  		t.Assert(gstr.IsSubDomain("s.s.johng.cn", main), false)
    28  	})
    29  	gtest.C(t, func(t *gtest.T) {
    30  		main := "*.goframe.org"
    31  		t.Assert(gstr.IsSubDomain("goframe.org", main), true)
    32  		t.Assert(gstr.IsSubDomain("s.goframe.org", main), true)
    33  		t.Assert(gstr.IsSubDomain("s.goframe.org:80", main), true)
    34  		t.Assert(gstr.IsSubDomain("s.s.goframe.org", main), false)
    35  		t.Assert(gstr.IsSubDomain("johng.cn", main), false)
    36  		t.Assert(gstr.IsSubDomain("s.johng.cn", main), false)
    37  		t.Assert(gstr.IsSubDomain("s.s.johng.cn", main), false)
    38  	})
    39  	gtest.C(t, func(t *gtest.T) {
    40  		main := "*.*.goframe.org"
    41  		t.Assert(gstr.IsSubDomain("goframe.org", main), true)
    42  		t.Assert(gstr.IsSubDomain("s.goframe.org", main), true)
    43  		t.Assert(gstr.IsSubDomain("s.s.goframe.org", main), true)
    44  		t.Assert(gstr.IsSubDomain("s.s.goframe.org:8000", main), true)
    45  		t.Assert(gstr.IsSubDomain("s.s.s.goframe.org", main), false)
    46  		t.Assert(gstr.IsSubDomain("johng.cn", main), false)
    47  		t.Assert(gstr.IsSubDomain("s.johng.cn", main), false)
    48  		t.Assert(gstr.IsSubDomain("s.s.johng.cn", main), false)
    49  	})
    50  	gtest.C(t, func(t *gtest.T) {
    51  		main := "*.*.goframe.org:8080"
    52  		t.Assert(gstr.IsSubDomain("goframe.org", main), true)
    53  		t.Assert(gstr.IsSubDomain("s.goframe.org", main), true)
    54  		t.Assert(gstr.IsSubDomain("s.s.goframe.org", main), true)
    55  		t.Assert(gstr.IsSubDomain("s.s.goframe.org:8000", main), true)
    56  		t.Assert(gstr.IsSubDomain("s.s.s.goframe.org", main), false)
    57  		t.Assert(gstr.IsSubDomain("johng.cn", main), false)
    58  		t.Assert(gstr.IsSubDomain("s.johng.cn", main), false)
    59  		t.Assert(gstr.IsSubDomain("s.s.johng.cn", main), false)
    60  	})
    61  
    62  	gtest.C(t, func(t *gtest.T) {
    63  		main := "*.*.goframe.org:8080"
    64  		t.Assert(gstr.IsSubDomain("goframe.org", main), true)
    65  		t.Assert(gstr.IsSubDomain("s.goframe.org", main), true)
    66  		t.Assert(gstr.IsSubDomain("s.s.goframe.org", main), true)
    67  		t.Assert(gstr.IsSubDomain("s.s.goframe.org:8000", main), true)
    68  		t.Assert(gstr.IsSubDomain("s.s.s.goframe.org", main), false)
    69  		t.Assert(gstr.IsSubDomain("johng.cn", main), false)
    70  		t.Assert(gstr.IsSubDomain("s.johng.cn", main), false)
    71  		t.Assert(gstr.IsSubDomain("s.s.johng.cn", main), false)
    72  	})
    73  	gtest.C(t, func(t *gtest.T) {
    74  		main := "s.goframe.org"
    75  		t.Assert(gstr.IsSubDomain("goframe.org", main), false)
    76  	})
    77  }