github.com/xyproto/orbiton/v2@v2.65.12-0.20240516144430-e10a419274ec/keyhist_test.go (about)

     1  package main
     2  
     3  import (
     4  	"log"
     5  	"testing"
     6  )
     7  
     8  func TestKeyHistory(t *testing.T) {
     9  	kh := NewKeyHistory()
    10  	if kh.Prev() != "" || kh.PrevPrev() != "" {
    11  		log.Fatalln(kh.String())
    12  	}
    13  	kh.Push("a")
    14  	kh.Push("b")
    15  	if kh.PrevPrev() != "a" || kh.Prev() != "b" {
    16  		log.Fatalln(kh.String())
    17  	}
    18  	kh.Push("c")
    19  	if kh.PrevPrev() != "b" || kh.Prev() != "c" {
    20  		log.Fatalln(kh.String())
    21  	}
    22  	if !kh.OnlyIn("a", "b", "c") {
    23  		t.Fail()
    24  	}
    25  	if !kh.OnlyIn("a", "b", "c", "d") {
    26  		t.Fail()
    27  	}
    28  	if !kh.OnlyIn("a", "b", "c", "d", "e", "f") {
    29  		t.Fail()
    30  	}
    31  }