| 640 | } |
| 641 | |
| 642 | func TestStringGetBit(t *testing.T) { |
| 643 | key := []byte("get-bits") |
| 644 | callFunc := func(txn *Transaction) { |
| 645 | s, err := GetString(txn, key) |
| 646 | assert.NoError(t, err) |
| 647 | s.SetBit(4, 1) |
| 648 | } |
| 649 | MockTest(t, callFunc) |
| 650 | |
| 651 | type args struct { |
| 652 | off int |
| 653 | } |
| 654 | type want struct { |
| 655 | retval int |
| 656 | } |
| 657 | tests := []struct { |
| 658 | name string |
| 659 | args args |
| 660 | want want |
| 661 | }{ |
| 662 | { |
| 663 | name: "one", |
| 664 | args: args{ |
| 665 | off: 1, |
| 666 | }, |
| 667 | want: want{ |
| 668 | retval: 0, |
| 669 | }, |
| 670 | }, |
| 671 | { |
| 672 | name: "two", |
| 673 | args: args{ |
| 674 | off: 100, |
| 675 | }, |
| 676 | want: want{ |
| 677 | retval: 0, |
| 678 | }, |
| 679 | }, |
| 680 | { |
| 681 | name: "three", |
| 682 | args: args{ |
| 683 | off: 4, |
| 684 | }, |
| 685 | want: want{ |
| 686 | retval: 8, |
| 687 | }, |
| 688 | }, |
| 689 | } |
| 690 | |
| 691 | for _, tt := range tests { |
| 692 | t.Run(tt.name, func(t *testing.T) { |
| 693 | callFunc := func(txn *Transaction) { |
| 694 | s, err := GetString(txn, key) |
| 695 | assert.NoError(t, err) |
| 696 | want, err := s.GetBit(tt.args.off) |
| 697 | assert.NoError(t, err) |
| 698 | assert.Equal(t, tt.want.retval, want) |
| 699 | } |