github.phpd.cn/thought-machine/please@v12.2.0+incompatible/src/output/interactive_display_test.go (about)

     1  package output
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  func TestLimitedPrintfSimple(t *testing.T) {
    10  	assert.Equal(t, "wibble wobble", lprintfPrepare(20, "wibble wobble"))
    11  	assert.Equal(t, "wibble wobble", lprintfPrepare(20, "%s %s", "wibble", "wobble"))
    12  }
    13  
    14  func TestLimitedPrintfMore(t *testing.T) {
    15  	assert.Equal(t, "wibble ...", lprintfPrepare(10, "wibble wobble"))
    16  	assert.Equal(t, "wibble ...", lprintfPrepare(10, "%s %s", "wibble", "wobble"))
    17  }
    18  
    19  func TestLimitedPrintfAnsi(t *testing.T) {
    20  	// Should be unchanged because without escape sequences it's under the limit.
    21  	assert.Equal(t, "\x1b[30mwibble wobble\x1b[1m", lprintfPrepare(20, "\x1b[30mwibble wobble\x1b[1m"))
    22  }
    23  
    24  func TestLimitedPrintfAnsiNotCountedWhenReducing(t *testing.T) {
    25  	assert.Equal(t, "\x1b[30mwibble ...\x1b[1m", lprintfPrepare(10, "%s %s", "\x1b[30mwibble", "wobble\x1b[1m"))
    26  }
    27  
    28  func TestNewlinesStillWritte(t *testing.T) {
    29  	// Test that newline still gets written (it doesn't count as horizontal space and is Very Important)
    30  	assert.Equal(t, "\x1b[30mwibble ...\x1b[1m\n", lprintfPrepare(10, "%s %s\n", "\x1b[30mwibble", "wobble\x1b[1m"))
    31  }