// TestCommitPending checks that bits will only be written if they are pending.
TestCommitPending checks that bits will only be written if they are pending.
// TestCommitPending checks that bits will only be written if they are pending .
func TestCommitPending(t *testing.T) {
	tests := []struct {
		bits        Bits
		len         int
		wantWritten int
		wantByte    byte
	}{
		{0xA, 4, 8, 0xA0},
		{0xA0, 8, 0, 0xA0},
	}
	for i, tt := range tests {
		var b bytes.Buffer
		t.Logf(`TestCommitPending %d`, i)
		w := NewWriter(&b, 1)
		w.WriteBits(tt.bits, tt.len)
		written, err := w.CommitPending()
		if err != nil {
			t.Fatalf(`err = %v, want nil`, err)
		}
		if written != tt.wantWritten {
			t.Errorf(`written = %v, want %v`, written, tt.wantWritten)
		}
		if actual, _ := b.ReadByte(); actual != tt.wantByte {
			t.Errorf(`written byte = %02X, want %02X`, actual, tt.wantByte)
		}
	}
}
func TestCommitPending ( t * testing . T ) { tests := [ ] struct { bits Bits len int wantWritten int wantByte byte } { { 0xA , 4 , 8 , 0xA0 } , { 0xA0 , 8 , 0 , 0xA0 } , } for i , tt := range tests { var b bytes . Buffer t . Logf ( `TestCommitPending %d` , i ) w := NewWriter ( & b , 1 ) w . WriteBits ( tt . bits , tt . len ) written , err := w . CommitPending ( ) if err != nil { t . Fatalf ( `err = %v, want nil` , err ) } if written != tt . wantWritten { t . Errorf ( `written = %v, want %v` , written , tt . wantWritten ) } if actual , _ := b . ReadByte ( ) ; actual != tt . wantByte { t . Errorf ( `written byte = %02X, want %02X` , actual , tt . wantByte ) } } }
TestCommitPending checks that bits will only be written if they are pending.
TestCommitPending checks that bits will only be written if they are pending .