github.com/endophage/docker@v1.4.2-0.20161027011718-242853499895/pkg/term/ascii_test.go (about)

     1  package term
     2  
     3  import "testing"
     4  
     5  func TestToBytes(t *testing.T) {
     6  	codes, err := ToBytes("ctrl-a,a")
     7  	if err != nil {
     8  		t.Fatal(err)
     9  	}
    10  	if len(codes) != 2 {
    11  		t.Fatalf("Expected 2 codes, got %d", len(codes))
    12  	}
    13  	if codes[0] != 1 || codes[1] != 97 {
    14  		t.Fatalf("Expected '1' '97', got '%d' '%d'", codes[0], codes[1])
    15  	}
    16  
    17  	codes, err = ToBytes("shift-z")
    18  	if err == nil {
    19  		t.Fatalf("Expected error, got none")
    20  	}
    21  
    22  	codes, err = ToBytes("ctrl-@,ctrl-[,~,ctrl-o")
    23  	if err != nil {
    24  		t.Fatal(err)
    25  	}
    26  	if len(codes) != 4 {
    27  		t.Fatalf("Expected 4 codes, got %d", len(codes))
    28  	}
    29  	if codes[0] != 0 || codes[1] != 27 || codes[2] != 126 || codes[3] != 15 {
    30  		t.Fatalf("Expected '0' '27' '126', '15', got '%d' '%d' '%d' '%d'", codes[0], codes[1], codes[2], codes[3])
    31  	}
    32  
    33  	codes, err = ToBytes("DEL,+")
    34  	if err != nil {
    35  		t.Fatal(err)
    36  	}
    37  	if len(codes) != 2 {
    38  		t.Fatalf("Expected 2 codes, got %d", len(codes))
    39  	}
    40  	if codes[0] != 127 || codes[1] != 43 {
    41  		t.Fatalf("Expected '127 '43'', got '%d' '%d'", codes[0], codes[1])
    42  	}
    43  }