import {expect} from '@esm-bundle/chai';import {scanInfoMatchesKey} from './subscriptions';
test('scanInfoMatchesKey', () => { expect(scanInfoMatchesKey({options: {}}, '', 'a')).to.be.true; expect(scanInfoMatchesKey({options: {indexName: 'idx'}}, 'idx', 'a')).to.be .true; expect(scanInfoMatchesKey({options: {indexName: 'idx'}}, '', 'a')).to.be .false; expect(scanInfoMatchesKey({options: {}}, 'idx', 'a')).to.be.false;
expect(scanInfoMatchesKey({options: {prefix: 'p'}}, '', 'a')).to.be.false;
expect(scanInfoMatchesKey({options: {startKey: 'sk'}}, '', 'a')).to.be.false; expect(scanInfoMatchesKey({options: {startKey: 'sk'}}, '', 'skate')).to.be .true; expect(scanInfoMatchesKey({options: {startKey: 'a'}}, '', 'b')).to.be.true;
expect( scanInfoMatchesKey( {options: {prefix: 'a', indexName: 'idx'}}, 'idx', '\u0000a\u0000b', ), ).to.be.true; expect( scanInfoMatchesKey( {options: {prefix: 'sb', indexName: 'idx'}}, 'idx', '\u0000sa\u0000p', ), ).to.be.false;
expect( scanInfoMatchesKey( {options: {prefix: 'sa', indexName: 'idx', startSecondaryKey: 'sab'}}, 'idx', '\u0000sab\u0000p', ), ).to.be.true; expect( scanInfoMatchesKey( {options: {prefix: 'sa', indexName: 'idx', startSecondaryKey: 'sab'}}, 'idx', '\u0000sac\u0000p', ), ).to.be.true; expect( scanInfoMatchesKey( {options: {prefix: 'sa', indexName: 'idx', startSecondaryKey: 'sac'}}, 'idx', '\u0000sab\u0000p', ), ).to.be.false;
expect( scanInfoMatchesKey( { options: { prefix: 'sa', indexName: 'idx', startSecondaryKey: 'sab', startKey: 'pa', }, }, 'idx', '\u0000sac\u0000pa', ), ).to.be.true; expect( scanInfoMatchesKey( { options: { prefix: 'sa', indexName: 'idx', startSecondaryKey: 'sab', startKey: 'pab', }, }, 'idx', '\u0000sac\u0000pab', ), ).to.be.true; expect( scanInfoMatchesKey( { options: { prefix: 'sa', indexName: 'idx', startSecondaryKey: 'sab', startKey: 'pab', }, }, 'idx', '\u0000sac\u0000pac', ), ).to.be.true; expect( scanInfoMatchesKey( { options: { prefix: 'sa', indexName: 'idx', startSecondaryKey: 'sab', startKey: 'pac', }, }, 'idx', '\u0000sac\u0000pab', ), ).to.be.false;});
test('scanInfoMatchesKey limit optimizations', () => { expect( scanInfoMatchesKey( { options: { startKey: 'pac2', limit: 10, }, }, '', 'pac2', ), ).to.be.true;
expect( scanInfoMatchesKey( { options: { startKey: 'pac2', limit: 10, }, inclusiveLimitKey: 'pac8', }, '', 'pac2', ), ).to.be.true;
expect( scanInfoMatchesKey( { options: { startKey: 'pac2', limit: 10, }, }, '', 'pac4', ), ).to.be.true;
expect( scanInfoMatchesKey( { options: { startKey: 'pac2', limit: 10, }, inclusiveLimitKey: 'pac8', }, '', 'pac4', ), ).to.be.true;
expect( scanInfoMatchesKey( { options: { startKey: 'pac2', limit: 10, }, inclusiveLimitKey: 'pac8', }, '', 'pac8', ), ).to.be.true;
expect( scanInfoMatchesKey( { options: { startKey: 'pac2', limit: 10, }, inclusiveLimitKey: 'pac8', }, '', 'pac9', ), ).to.be.false;
expect( scanInfoMatchesKey( { options: { startKey: 'pac2', limit: 10, }, }, '', 'pac1', ), ).to.be.false;
expect( scanInfoMatchesKey( { options: { startKey: 'pac2', limit: 10, }, inclusiveLimitKey: 'pac8', }, '', 'pac1', ), ).to.be.false;
expect( scanInfoMatchesKey( { options: { startKey: 'pac2', startExclusive: true, limit: 10, }, }, '', 'pac2', ), ).to.be.false;
expect( scanInfoMatchesKey( { options: { startKey: 'pac2', startExclusive: true, limit: 10, }, inclusiveLimitKey: 'pac8', }, '', 'pac2', ), ).to.be.false;
expect( scanInfoMatchesKey( { options: { startKey: 'pac2', }, inclusiveLimitKey: 'pac8', }, '', 'pac9', ), ).to.be.true;
expect( scanInfoMatchesKey( { options: { prefix: 'pac', limit: 10, }, inclusiveLimitKey: 'pac8', }, '', 'pac1', ), ).to.be.true;
expect( scanInfoMatchesKey( { options: { prefix: 'pac', limit: 10, }, inclusiveLimitKey: 'pac8', }, '', 'pac8', ), ).to.be.true;
expect( scanInfoMatchesKey( { options: { prefix: 'pac', limit: 10, }, inclusiveLimitKey: 'pac8', }, '', 'pac9', ), ).to.be.false;
expect( scanInfoMatchesKey( { options: { prefix: 'pac', limit: 10, }, inclusiveLimitKey: 'pac8', }, '', 'pab', ), ).to.be.false;
expect( scanInfoMatchesKey( { options: { prefix: 'pac', }, inclusiveLimitKey: 'pac8', }, '', 'pac9', ), ).to.be.true;
expect( scanInfoMatchesKey( { options: { prefix: 'pac2', startKey: 'pac22', limit: 10, }, }, '', 'pac22', ), ).to.be.true; expect( scanInfoMatchesKey( { options: { prefix: 'pac2', startKey: 'pac22', limit: 10, }, inclusiveLimitKey: 'pac28', }, '', 'pac22', ), ).to.be.true;
expect( scanInfoMatchesKey( { options: { prefix: 'pac2', startKey: 'pac22', limit: 10, }, }, '', 'pac24', ), ).to.be.true;
expect( scanInfoMatchesKey( { options: { prefix: 'pac2', startKey: 'pac22', limit: 10, }, inclusiveLimitKey: 'pac28', }, '', 'pac24', ), ).to.be.true;
expect( scanInfoMatchesKey( { options: { prefix: 'pac2', startKey: 'pac22', limit: 10, }, inclusiveLimitKey: 'pac28', }, '', 'pac28', ), ).to.be.true;
expect( scanInfoMatchesKey( { options: { prefix: 'pac2', startKey: 'pac22', limit: 10, }, inclusiveLimitKey: 'pac28', }, '', 'pac29', ), ).to.be.false;
expect( scanInfoMatchesKey( { options: { prefix: 'pac2', startKey: 'pac22', limit: 10, }, }, '', 'pac21', ), ).to.be.false;
expect( scanInfoMatchesKey( { options: { prefix: 'pac2', startKey: 'pac22', limit: 10, }, inclusiveLimitKey: 'pac28', }, '', 'pac21', ), ).to.be.false;
expect( scanInfoMatchesKey( { options: { prefix: 'pac2', startKey: 'pac22', startExclusive: true, limit: 10, }, }, '', 'pac22', ), ).to.be.false;
expect( scanInfoMatchesKey( { options: { prefix: 'pac2', startKey: 'pac22', startExclusive: true, limit: 10, }, inclusiveLimitKey: 'pac28', }, '', 'pac22', ), ).to.be.false;
expect( scanInfoMatchesKey( { options: { prefix: 'pac2', startKey: 'pac22', }, inclusiveLimitKey: 'pac28', }, '', 'pac29', ), ).to.be.true;
expect( scanInfoMatchesKey( { options: { prefix: 'pac2', startKey: 'pab1', }, inclusiveLimitKey: 'pac28', }, '', 'pab2', ), ).to.be.false;});