go-vise

Constrained Size Output Virtual Machine
Info | Log | Files | Refs | README | LICENSE

split_test.go (2988B)


      1 package render
      2 
      3 import (
      4 //	"bytes"
      5 //	"log"
      6 	"testing"
      7 )
      8 
      9 func TestSplitBookmark(t *testing.T) {
     10 	vals := []string{"inky", "pinky", "blinky", "clyde"}
     11 	r := bookmark(vals)
     12 	expect := []uint32{0, 5, 11, 18, 24}
     13 	for i, v := range expect {
     14 		if r[i] != v {
     15 			t.Fatalf("expected val %v cursor %v, got %v", i, v, r[i])
     16 		}
     17 	}
     18 }
     19 
     20 func TestSplitPaginate(t *testing.T) {
     21 	vals := []string{"inky", "pinky", "blinky", "clyde"}
     22 	v := bookmark(vals)
     23 	r, err := paginate(v, 15, 0, 0)
     24 	if err != nil {
     25 		t.Fatal(err)
     26 	}
     27 	if len(r) != 2 {
     28 		t.Fatalf("expected bookmark len 2, got %v", len(r))
     29 	}
     30 	expect := []uint32{0, 5}
     31 	if len(r[0]) != len(expect) {
     32 		t.Fatalf("expected page 1 len %v, got %v", len(expect), len(r[0]))
     33 	}
     34 	for i, v := range expect {
     35 		if r[0][i] != v {
     36 			t.Fatalf("expected page 1 val %v cursor %v, got %v", i, v, r[0][i])
     37 		}
     38 	}
     39 	expect = []uint32{11, 18, 24}
     40 	if len(r[1]) != len(expect) {
     41 		t.Fatalf("expected page 2 len %v, got %v", len(expect), len(r[1]))
     42 	}
     43 	for i, v := range expect {
     44 		if r[1][i] != v {
     45 			t.Fatalf("expected page 2 val %v cursor %v, got %v", i, v, r[1][i])
     46 		}
     47 	}
     48 }
     49 
     50 //func TestSplitMenuPaginate(t *testing.T) {
     51 //	menuCfg := DefaultBrowseConfig()
     52 //	menu := NewMenu().WithBrowseConfig(menuCfg)
     53 //	menu.Put("0", "foo")
     54 //	menu.Put("1", "bar")
     55 //	
     56 //	vals := []string{"inky", "pinky", "blinky", "clyde", "tinkywinky", "dipsy", "lala", "pu"}
     57 //	v := bookmark(vals)
     58 ////	vv, err := paginate(v, 15, 0, 0)
     59 ////	if err != nil {
     60 ////		t.Fatal(err)
     61 ////	}
     62 //
     63 //	menu = menu.WithPages()
     64 //	menuSizes, err := menu.Sizes()
     65 //	log.Printf("sizes %v", menuSizes)
     66 //	if err != nil {
     67 //		t.Fatal(err)
     68 //	}
     69 //	r, err := paginate(v, 30, menuSizes[1], menuSizes[2])
     70 //	if err != nil {
     71 //		t.Fatal(err)
     72 //	}
     73 //	expect := [][]uint32{
     74 //		[]uint32{0, 5, 11},
     75 //		[]uint32{18},
     76 //		[]uint32{24},
     77 //		[]uint32{35, 41, 46},
     78 //	}
     79 //	if len(r) != len(expect) {
     80 //		t.Fatalf("expected page 1 len %v, got %v", len(expect), len(r))
     81 //	}
     82 //	for i, v := range expect {
     83 //		for j, vv := range v {
     84 //			if r[i][j] != vv {
     85 //				t.Fatalf("value mismatch in [%v][%v]", i, j)
     86 //			}
     87 //		}
     88 //	}
     89 //
     90 //	s := explode(vals, r)
     91 //	expectBytes := append([]byte("inky"), byte(0x00))
     92 //	expectBytes = append(expectBytes, []byte("pinky")...)
     93 //	expectBytes = append(expectBytes, byte(0x00))
     94 //	expectBytes = append(expectBytes, []byte("blinky")...)
     95 //	expectBytes = append(expectBytes, byte(0x0a))
     96 //	expectBytes = append(expectBytes, []byte("clyde")...)
     97 //	expectBytes = append(expectBytes, byte(0x0a))
     98 //	expectBytes = append(expectBytes, []byte("tinkywinky")...)
     99 //	expectBytes = append(expectBytes, byte(0x0a))
    100 //	expectBytes = append(expectBytes, []byte("dipsy")...)
    101 //	expectBytes = append(expectBytes, byte(0x00))
    102 //	expectBytes = append(expectBytes, []byte("lala")...)
    103 //	expectBytes = append(expectBytes, byte(0x00))
    104 //	expectBytes = append(expectBytes, []byte("pu")...)
    105 //	
    106 //	if !bytes.Equal([]byte(s), expectBytes) {
    107 //		t.Fatalf("expected:\n\t%s\ngot:\n\t%x\n", expectBytes, s)
    108 //	}
    109 //}