...

Source file src/github.com/jedib0t/go-pretty/v6/text/format_test.go

Documentation: github.com/jedib0t/go-pretty/v6/text

     1  package text
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  func ExampleFormat_Apply() {
    11  	fmt.Printf("FormatDefault: %#v\n", FormatDefault.Apply("jon Snow"))
    12  	fmt.Printf("FormatLower  : %#v\n", FormatLower.Apply("jon Snow"))
    13  	fmt.Printf("FormatTitle  : %#v\n", FormatTitle.Apply("jon Snow"))
    14  	fmt.Printf("FormatUpper  : %#v\n", FormatUpper.Apply("jon Snow"))
    15  	fmt.Println()
    16  	fmt.Printf("FormatDefault (w/EscSeq): %#v\n", FormatDefault.Apply(Bold.Sprint("jon Snow")))
    17  	fmt.Printf("FormatLower   (w/EscSeq): %#v\n", FormatLower.Apply(Bold.Sprint("jon Snow")))
    18  	fmt.Printf("FormatTitle   (w/EscSeq): %#v\n", FormatTitle.Apply(Bold.Sprint("jon Snow")))
    19  	fmt.Printf("FormatUpper   (w/EscSeq): %#v\n", FormatUpper.Apply(Bold.Sprint("jon Snow")))
    20  
    21  	// Output: FormatDefault: "jon Snow"
    22  	// FormatLower  : "jon snow"
    23  	// FormatTitle  : "Jon Snow"
    24  	// FormatUpper  : "JON SNOW"
    25  	//
    26  	// FormatDefault (w/EscSeq): "\x1b[1mjon Snow\x1b[0m"
    27  	// FormatLower   (w/EscSeq): "\x1b[1mjon snow\x1b[0m"
    28  	// FormatTitle   (w/EscSeq): "\x1b[1mJon Snow\x1b[0m"
    29  	// FormatUpper   (w/EscSeq): "\x1b[1mJON SNOW\x1b[0m"
    30  }
    31  
    32  func TestFormat_Apply(t *testing.T) {
    33  	text := "A big croc0dile; Died - Empty_fanged ツ \u2008."
    34  	assert.Equal(t, text, FormatDefault.Apply(text))
    35  	assert.Equal(t, "a big croc0dile; died - empty_fanged ツ \u2008.", FormatLower.Apply(text))
    36  	assert.Equal(t, "A Big Croc0dile; Died - Empty_fanged ツ \u2008.", FormatTitle.Apply(text))
    37  	assert.Equal(t, "A BIG CROC0DILE; DIED - EMPTY_FANGED ツ \u2008.", FormatUpper.Apply(text))
    38  
    39  	// test with escape sequences
    40  	text = Colors{Bold}.Sprint(text)
    41  	assert.Equal(t, "\x1b[1mA big croc0dile; Died - Empty_fanged ツ \u2008.\x1b[0m", FormatDefault.Apply(text))
    42  	assert.Equal(t, "\x1b[1ma big croc0dile; died - empty_fanged ツ \u2008.\x1b[0m", FormatLower.Apply(text))
    43  	assert.Equal(t, "\x1b[1mA Big Croc0dile; Died - Empty_fanged ツ \u2008.\x1b[0m", FormatTitle.Apply(text))
    44  	assert.Equal(t, "\x1b[1mA BIG CROC0DILE; DIED - EMPTY_FANGED ツ \u2008.\x1b[0m", FormatUpper.Apply(text))
    45  }
    46  

View as plain text