github.com/Ptt-official-app/go-bbs@v0.12.0/ansi_test.go (about)

     1  package bbs
     2  
     3  import (
     4  	"strings"
     5  	"testing"
     6  )
     7  
     8  const strWithANSI = "\x1b[1;31m→ \x1b[33mpichu2\x1b[m\x1b[33m:推"
     9  
    10  func TestFilterStringANSI(t *testing.T) {
    11  	src := strWithANSI
    12  	expected := "→ pichu2:推"
    13  
    14  	dst := FilterStringANSI(src)
    15  
    16  	if strings.Compare(expected, dst) != 0 {
    17  		t.Errorf("FilterStringANSI doesn't filter ANSI CSI code, \nexpected: \n%s, \ngot: \n%s", expected, dst)
    18  	}
    19  }
    20  
    21  func BenchmarkStringANSI(b *testing.B) {
    22  	src := strWithANSI
    23  
    24  	b.ResetTimer()
    25  
    26  	for i := 0; i < b.N; i++ {
    27  		_ = FilterStringANSI(src)
    28  	}
    29  }