(t *testing.T)
| 1100 | } |
| 1101 | |
| 1102 | func TestBitcount(t *testing.T) { |
| 1103 | server.Clear() |
| 1104 | c, err := proto.Dial(server.Addr()) |
| 1105 | ok(t, err) |
| 1106 | defer c.Close() |
| 1107 | s := server.Direct() |
| 1108 | |
| 1109 | { |
| 1110 | s.Set("countme", "a") // 'a' is 0x1100001 |
| 1111 | mustDo(t, c, |
| 1112 | "BITCOUNT", "countme", |
| 1113 | proto.Int(3), |
| 1114 | ) |
| 1115 | |
| 1116 | s.Set("countme", "aaaaa") // 'a' is 0x1100001 |
| 1117 | mustDo(t, c, |
| 1118 | "BITCOUNT", "countme", |
| 1119 | proto.Int(3*5), |
| 1120 | ) |
| 1121 | } |
| 1122 | // Non-existing |
| 1123 | must0(t, c, |
| 1124 | "BITCOUNT", "nosuch", |
| 1125 | ) |
| 1126 | |
| 1127 | { |
| 1128 | // a: 0x1100001 - 3 |
| 1129 | // b: 0x1100010 - 3 |
| 1130 | // c: 0x1100011 - 4 |
| 1131 | // d: 0x1100100 - 3 |
| 1132 | s.Set("foo", "abcd") |
| 1133 | test := func(s, e, res int) { |
| 1134 | t.Helper() |
| 1135 | mustDo(t, c, |
| 1136 | "BITCOUNT", "foo", strconv.Itoa(s), strconv.Itoa(e), |
| 1137 | proto.Int(res), |
| 1138 | ) |
| 1139 | } |
| 1140 | test(0, 0, 3) // "a" |
| 1141 | test(0, 3, 13) // "abcd" |
| 1142 | test(2, -2, 4) // "c" |
| 1143 | } |
| 1144 | |
| 1145 | // Wrong type of existing key |
| 1146 | { |
| 1147 | s.HSet("wrong", "aap", "noot") |
| 1148 | mustDo(t, c, |
| 1149 | "BITCOUNT", "wrong", |
| 1150 | proto.Error(msgWrongType), |
| 1151 | ) |
| 1152 | } |
| 1153 | |
| 1154 | // Wrong usage |
| 1155 | { |
| 1156 | mustDo(t, c, |
| 1157 | "BITCOUNT", |
| 1158 | proto.Error(errWrongNumber("bitcount")), |
| 1159 | ) |
nothing calls this directly
no test coverage detected