|
2 | 2 |
|
3 | 3 | using Valkey.Glide.Commands.Options; |
4 | 4 |
|
| 5 | +using static Valkey.Glide.Errors; |
| 6 | + |
5 | 7 | namespace Valkey.Glide.IntegrationTests; |
6 | 8 |
|
7 | 9 | public class BitmapCommandTests(TestConfiguration config) |
@@ -52,6 +54,19 @@ public async Task GetBit_OffsetBeyondString_ReturnsFalse(BaseClient client) |
52 | 54 | Assert.False(bit); |
53 | 55 | } |
54 | 56 |
|
| 57 | + [Theory(DisableDiscoveryEnumeration = true)] |
| 58 | + [MemberData(nameof(Config.TestClients), MemberType = typeof(TestConfiguration))] |
| 59 | + public async Task GetBit_NegativeOffset_ThrowsException(BaseClient client) |
| 60 | + { |
| 61 | + string key = Guid.NewGuid().ToString(); |
| 62 | + |
| 63 | + // Set a string |
| 64 | + await client.StringSetAsync(key, "A"); |
| 65 | + |
| 66 | + // Test negative offset - should throw an exception |
| 67 | + await Assert.ThrowsAsync<RequestException>(async () => await client.StringGetBitAsync(key, -1)); |
| 68 | + } |
| 69 | + |
55 | 70 | [Theory(DisableDiscoveryEnumeration = true)] |
56 | 71 | [MemberData(nameof(Config.TestClients), MemberType = typeof(TestConfiguration))] |
57 | 72 | public async Task SetBit_SetsAndReturnsOriginalValue(BaseClient client) |
@@ -90,6 +105,16 @@ public async Task SetBit_NonExistentKey_CreatesKey(BaseClient client) |
90 | 105 | Assert.True(currentBit); |
91 | 106 | } |
92 | 107 |
|
| 108 | + [Theory(DisableDiscoveryEnumeration = true)] |
| 109 | + [MemberData(nameof(Config.TestClients), MemberType = typeof(TestConfiguration))] |
| 110 | + public async Task SetBit_NegativeOffset_ThrowsException(BaseClient client) |
| 111 | + { |
| 112 | + string key = Guid.NewGuid().ToString(); |
| 113 | + |
| 114 | + // Test negative offset - should throw an exception |
| 115 | + await Assert.ThrowsAsync<RequestException>(async () => await client.StringSetBitAsync(key, -1, true)); |
| 116 | + } |
| 117 | + |
93 | 118 | [Theory(DisableDiscoveryEnumeration = true)] |
94 | 119 | [MemberData(nameof(Config.TestClients), MemberType = typeof(TestConfiguration))] |
95 | 120 | public async Task GetSetBit_CombinedOperations_WorksTogether(BaseClient client) |
@@ -493,30 +518,29 @@ public async Task BitField_OffsetMultiplier_WorksCorrectly(BaseClient client) |
493 | 518 |
|
494 | 519 | [Theory(DisableDiscoveryEnumeration = true)] |
495 | 520 | [MemberData(nameof(Config.TestClients), MemberType = typeof(TestConfiguration))] |
496 | | - public async Task BitField_AutoOptimization_UsesReadOnlyForGetOperations(BaseClient client) |
| 521 | + public async Task BitField_WithReadOnlyAndMixedOperations_WorksCorrectly(BaseClient client) |
497 | 522 | { |
498 | 523 | string key = Guid.NewGuid().ToString(); |
499 | 524 |
|
500 | 525 | // Set initial value "A" (ASCII 65 = 01000001) |
501 | 526 | await client.StringSetAsync(key, "A"); |
502 | 527 |
|
503 | | - // Test with only GET operations - should automatically use BITFIELD_RO |
| 528 | + // Test with only GET operations |
504 | 529 | var readOnlySubCommands = new BitFieldOptions.IBitFieldSubCommand[] |
505 | 530 | { |
506 | 531 | new BitFieldOptions.BitFieldGet(BitFieldOptions.Encoding.Unsigned(8), new BitFieldOptions.BitOffset(0)), |
507 | 532 | new BitFieldOptions.BitFieldGet(BitFieldOptions.Encoding.Unsigned(4), new BitFieldOptions.BitOffset(0)), |
508 | 533 | new BitFieldOptions.BitFieldGet(BitFieldOptions.Encoding.Unsigned(4), new BitFieldOptions.BitOffset(4)) |
509 | 534 | }; |
510 | 535 |
|
511 | | - // This should internally use BITFIELD_RO since all commands are GET |
512 | 536 | long[] results = await client.StringBitFieldAsync(key, readOnlySubCommands); |
513 | 537 |
|
514 | 538 | Assert.Equal(3, results.Length); |
515 | 539 | Assert.Equal(65, results[0]); // Full 8 bits: 01000001 = 65 |
516 | 540 | Assert.Equal(4, results[1]); // First 4 bits: 0100 = 4 |
517 | 541 | Assert.Equal(1, results[2]); // Next 4 bits: 0001 = 1 |
518 | 542 |
|
519 | | - // Test with mixed operations - should use regular BITFIELD |
| 543 | + // Test with mixed operations |
520 | 544 | var mixedSubCommands = new BitFieldOptions.IBitFieldSubCommand[] |
521 | 545 | { |
522 | 546 | new BitFieldOptions.BitFieldGet(BitFieldOptions.Encoding.Unsigned(8), new BitFieldOptions.BitOffset(0)), |
|
0 commit comments