github.com/kcmerrill/alfred@v0.0.0-20180727171036-06445dcb5e3d/pkg/alfred/utils_test.go (about)

     1  package alfred
     2  
     3  import "testing"
     4  
     5  func TestEvaluate(t *testing.T) {
     6  	result := evaluate("whoami", ".")
     7  	if result == "whoami" {
     8  		t.Fatalf("evaluate(whoami) should return the command, not the text")
     9  	}
    10  
    11  	result = evaluate("commanddoesnotexist", ".")
    12  	if result != "commanddoesnotexist" {
    13  		t.Fatalf("testCommand(commanddoesnotexist) should return the text, as the command does not exist")
    14  	}
    15  }
    16  
    17  func TestTestCommand(t *testing.T) {
    18  	result := testCommand("whoami", ".")
    19  	if result == false {
    20  		t.Fatalf("testCommand(whoami) should evaluate to true")
    21  	}
    22  }
    23  
    24  func TestExecute(t *testing.T) {
    25  	result, ok := execute("whoami", ".")
    26  	if result == "whoami" {
    27  		t.Fatalf("Expected whoami to return a non string")
    28  	}
    29  
    30  	if !ok {
    31  		t.Fatalf("Should not have resulted in an error.")
    32  	}
    33  }
    34  
    35  func TestPadding(t *testing.T) {
    36  	paddedRight := padRight("a", 5, "-")
    37  	if paddedRight != "a----" {
    38  		t.Fatalf("PadRight broken" + paddedRight)
    39  	}
    40  
    41  	paddedLeft := padLeft("a", 5, "-")
    42  	if paddedLeft != "----a" {
    43  		t.Fatalf("PadLeft broken" + paddedLeft)
    44  	}
    45  }