...

Source file src/code.rocketnine.space/tslocum/cview/box_test.go

Documentation: code.rocketnine.space/tslocum/cview

     1  package cview
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  const (
     8  	testBoxTitleA = "Hello, world!"
     9  	testBoxTitleB = "Goodnight, moon!"
    10  )
    11  
    12  func TestBox(t *testing.T) {
    13  	t.Parallel()
    14  
    15  	// Initialize
    16  
    17  	b := NewBox()
    18  	if b.GetTitle() != "" {
    19  		t.Errorf("failed to initialize Box: incorrect initial state: expected blank title, got %s", b.GetTitle())
    20  	} else if b.border {
    21  		t.Errorf("failed to initialize Box: incorrect initial state: expected no border, got border")
    22  	}
    23  
    24  	// Set title
    25  
    26  	b.SetTitle(testBoxTitleA)
    27  	if b.GetTitle() != testBoxTitleA {
    28  		t.Errorf("failed to update Box: incorrect title: expected %s, got %s", testBoxTitleA, b.GetTitle())
    29  	}
    30  
    31  	b.SetTitle(testBoxTitleB)
    32  	if b.GetTitle() != testBoxTitleB {
    33  		t.Errorf("failed to update Box: incorrect title: expected %s, got %s", testBoxTitleB, b.GetTitle())
    34  	}
    35  
    36  	// Set border
    37  
    38  	b.SetBorder(true)
    39  	if !b.border {
    40  		t.Errorf("failed to update Box: incorrect state: expected border, got no border")
    41  	}
    42  
    43  	b.SetBorder(false)
    44  	if b.border {
    45  		t.Errorf("failed to update Box: incorrect state: expected no border, got border")
    46  	}
    47  
    48  	// Draw
    49  
    50  	app, err := newTestApp(b)
    51  	if err != nil {
    52  		t.Errorf("failed to initialize Application: %s", err)
    53  	}
    54  
    55  	b.Draw(app.screen)
    56  }
    57  

View as plain text