github.com/iDigitalFlame/xmt@v0.5.4/util/builder_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 util
    18  
    19  import "testing"
    20  
    21  func TestBuilder(t *testing.T) {
    22  	var b Builder
    23  	for i := 0; i < 32; i++ {
    24  		b.WriteString("hello ")
    25  		b.Write([]byte("world!"))
    26  		b.InsertByte('!')
    27  		if n := b.Len(); n > b.Cap() {
    28  			t.Fatalf(`TestBuilder(): Builder capacity value "%d" is not greater than the expected size!`, n)
    29  		}
    30  		if n := b.Len(); n != len("!hello world!") {
    31  			t.Fatalf(`TestBuilder(): Builder length value "%d" does not match the expected size!`, n)
    32  		}
    33  		if v := b.String(); v != "!hello world!" {
    34  			t.Fatalf(`TestBuilder(): Builder string output value "%s" does not match the expected value!`, v)
    35  		}
    36  		if v := b.Output(); v != "!hello world!" {
    37  			t.Fatalf(`TestBuilder(): Builder output value "%s" does not match the expected value!`, v)
    38  		}
    39  		if n := b.Len(); n != 0 {
    40  			t.Fatalf(`TestBuilder(): Builder size value "%d" does not match the expected value of zero!`, n)
    41  		}
    42  	}
    43  }