github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/utils/virtualterm/export_test.go (about)

     1  package virtualterm_test
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  	"testing"
     7  
     8  	"github.com/lmorg/murex/test/count"
     9  	"github.com/lmorg/murex/utils/ansi/codes"
    10  	"github.com/lmorg/murex/utils/virtualterm"
    11  )
    12  
    13  func TestWriteSgrFgRedExportHtml(t *testing.T) {
    14  	count.Tests(t, 1)
    15  
    16  	term := virtualterm.NewTerminal(120, 1)
    17  	test := fmt.Sprintf("Normal%sBold%sRed%sReset", codes.Bold, codes.FgRed, codes.Reset)
    18  	exp1 := `<span class="">Normal</span><span class="sgr-bold">Bold</span><span class="sgr-bold sgr-red">Red</span><span class="">Reset</span><span class="">                                                                                                      
    19  </span>`
    20  	exp2 := `<span class="">Normal</span><span class="sgr-bold">Bold</span><span class="sgr-bold sgr-red">Red</span><span class="">Reset</span><span class="">                                                                                                      
    21  </span>`
    22  
    23  	term.Write([]rune(test))
    24  	act := strings.TrimSpace(term.ExportHtml())
    25  
    26  	if exp1 != act && exp2 != act {
    27  		t.Error("Expected output does not match actual output")
    28  		t.Logf("  Expected: '%s'", exp1)
    29  		t.Logf("  Actual:   '%s'", act)
    30  		t.Logf("  exp bytes: %v", []byte(exp1))
    31  		t.Logf("  act bytes: %v", []byte(act))
    32  	}
    33  }
    34  
    35  func TestWriteSgrFgColoursExportHtml(t *testing.T) {
    36  	count.Tests(t, 1)
    37  
    38  	term := virtualterm.NewTerminal(120, 1)
    39  	test := fmt.Sprintf("%sRed%sGreen%sBlue", codes.FgRed, codes.FgGreen, codes.FgBlue)
    40  	exp := `<span class=""></span><span class="sgr-red">Red</span><span class="sgr-green">Green</span><span class="sgr-blue">Blue</span><span class="">                                                                                                            
    41  </span>`
    42  
    43  	term.Write([]rune(test))
    44  	act := strings.TrimSpace(term.ExportHtml())
    45  
    46  	if exp != act {
    47  		t.Error("Expected output does not match actual output")
    48  		t.Logf("  Expected: '%s'", exp)
    49  		t.Logf("  Actual:   '%s'", act)
    50  		t.Logf("  exp bytes: %v", []byte(exp))
    51  		t.Logf("  act bytes: %v", []byte(act))
    52  	}
    53  }