github.com/iDigitalFlame/xmt@v0.5.4/util/text/match_test.go (about)

     1  // Copyright (C) 2020 - 2023 iDigitalFlame
     2  //
     3  // This program is free software: you can redistribute it and/or modify
     4  // it under the terms of the GNU General Public License as published by
     5  // the Free Software Foundation, either version 3 of the License, or
     6  // any later version.
     7  //
     8  // This program is distributed in the hope that it will be useful,
     9  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    10  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    11  // GNU General Public License for more details.
    12  //
    13  // You should have received a copy of the GNU General Public License
    14  // along with this program.  If not, see <https://www.gnu.org/licenses/>.
    15  //
    16  
    17  package text
    18  
    19  import (
    20  	"strconv"
    21  	"testing"
    22  )
    23  
    24  func TestMatcher(t *testing.T) {
    25  	for i := 0; i < 32; i++ {
    26  		m := Matcher("test1-%d-%h-%5n-%5c-%5u-%5l-%5s-%d-%h-test1-" + strconv.Itoa(i))
    27  		if !m.Match().MatchString(m.String()) {
    28  			t.Fatalf(`TestMatcher(): Matcher "%s" did not match it's generated Regexp!`, m)
    29  		}
    30  	}
    31  	for i := 0; i < 32; i++ {
    32  		m := Matcher("test1-%5l-%5d-%5fl-%5fu-%5fn-test2-" + strconv.Itoa(i))
    33  		if !m.Match().MatchString(m.String()) {
    34  			t.Fatalf(`TestMatcher(): Matcher "%s" did not match it's generated Regexp!`, m)
    35  		}
    36  	}
    37  	for i := 0; i < 32; i++ {
    38  		m := Matcher("test1-%5c-%5fc-%5fh-%5fd-%5n-%5fn-test3-" + strconv.Itoa(i))
    39  		if !m.Match().MatchString(m.String()) {
    40  			t.Fatalf(`TestMatcher(): Matcher "%s" did not match it's generated Regexp!`, m)
    41  		}
    42  	}
    43  }
    44  func TestMatcherAny(t *testing.T) {
    45  	for i := 0; i < 32; i++ {
    46  		m := Matcher("%s-test1-%5h-%5n-%5c-%5u-%5l-%5s-%d-%h-test1-" + strconv.Itoa(i))
    47  		if !MatchAny.MatchString(m.String()) {
    48  			t.Fatalf(`TestMatcherAny(): Matcher "%s" did not match MatchAny!`, m)
    49  		}
    50  	}
    51  }
    52  func TestMatcherNone(t *testing.T) {
    53  	for i := 0; i < 32; i++ {
    54  		m := Matcher("%s-test1-%5h-%5n-%5c-%5u-%5l-%5s-%d-%h-test1-" + strconv.Itoa(i))
    55  		if MatchNone.MatchString(m.String()) {
    56  			t.Fatalf(`TestMatcherNone(): Matcher "%s" matched MatchNone!`, m)
    57  		}
    58  	}
    59  }
    60  func TestMatcherInverse(t *testing.T) {
    61  	for i := 0; i < 32; i++ {
    62  		m := Matcher("%s-test1-%5h-%5n-%5c-%5u-%5l-%5s-%d-%h-test1-" + strconv.Itoa(i))
    63  		if m.MatchEx(false).MatchString(m.String()) {
    64  			t.Fatalf(`TestMatcherInverse(): Matcher "%s" matched it's generated inverse Regexp!`, m)
    65  		}
    66  	}
    67  }