Skip to content

Commit 5829994

Browse files
committed
Add unt tests for matchMode
1 parent 5c4b5a2 commit 5829994

File tree

2 files changed

+104
-6
lines changed

2 files changed

+104
-6
lines changed

src/interpreter/plugin/LookupPlugin.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,6 @@ export class LookupPlugin extends FunctionPlugin implements FunctionPluginTypech
129129
return new CellError(ErrorType.VALUE, ErrorMessage.BadMode)
130130
}
131131

132-
if (matchMode !== 0) {
133-
// not supported yet
134-
// TODO: Implement match mode
135-
return new CellError(ErrorType.VALUE, ErrorMessage.BadMode)
136-
}
137-
138132
const lookupRange = lookupRangeValue instanceof SimpleRangeValue ? lookupRangeValue : SimpleRangeValue.fromScalar(lookupRangeValue)
139133
const returnRange = returnRangeValue instanceof SimpleRangeValue ? returnRangeValue : SimpleRangeValue.fromScalar(returnRangeValue)
140134
const searchOptions: SearchOptions = {

test/interpreter/function-xlookup.spec.ts

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,110 @@ describe('Function XLOOKUP', () => {
502502
})
503503
})
504504

505+
describe('with BinarySearch column search strategy, when provided with matchMode = ', () => {
506+
describe('-1, returns a lower bound if the search key is not present', () => {
507+
it('in unsorted horizontal range', () => {
508+
const engine = HyperFormula.buildFromArray([
509+
['=XLOOKUP(3, A2:E2, A3:E3, "NotFound", -1, 1)'],
510+
[2, 1, 4, 2, 5],
511+
[1, 2, 3, 4, 5],
512+
], { useColumnIndex: false })
513+
514+
expect(engine.getCellValue(adr('A1'))).toEqual(1)
515+
})
516+
517+
it('in unsorted vertical range', () => {
518+
const engine = HyperFormula.buildFromArray([
519+
['=XLOOKUP(3, A2:A6, B2:B6, "NotFound", -1, 1)'],
520+
[2, 1],
521+
[1, 2],
522+
[4, 3],
523+
[2, 4],
524+
[5, 5]
525+
], { useColumnIndex: false })
526+
527+
expect(engine.getCellValue(adr('A1'))).toEqual(1)
528+
})
529+
530+
it('in sorted horizontal range', () => {
531+
const engine = HyperFormula.buildFromArray([
532+
['=XLOOKUP(3, A2:E2, A2:E2, "NotFound", -1, 2)'],
533+
[1, 2, 2, 5, 6],
534+
], { useColumnIndex: false })
535+
536+
expect(engine.getCellValue(adr('A1'))).toEqual(2)
537+
})
538+
539+
it('in sorted vertical range', () => {
540+
const engine = HyperFormula.buildFromArray([
541+
['=XLOOKUP(3, A2:A6, A2:A6, "NotFound", -1, 2)'],
542+
[1],
543+
[2],
544+
[4],
545+
[5],
546+
[6]
547+
], { useColumnIndex: false })
548+
549+
expect(engine.getCellValue(adr('A1'))).toEqual(2)
550+
})
551+
})
552+
553+
describe('1, returns an upper bound if the search key is not present', () => {
554+
it('in unsorted horizontal range', () => {
555+
const engine = HyperFormula.buildFromArray([
556+
['=XLOOKUP(3, A2:E2, A3:E3, "NotFound", 1, 1)'],
557+
[2, 1, 4, 4, 5],
558+
[1, 2, 3, 4, 5],
559+
], { useColumnIndex: false })
560+
561+
expect(engine.getCellValue(adr('A1'))).toEqual(3)
562+
})
563+
564+
it('in unsorted vertical range', () => {
565+
const engine = HyperFormula.buildFromArray([
566+
['=XLOOKUP(3, A2:A6, B2:B6, "NotFound", 1, 1)'],
567+
[2, 1],
568+
[1, 2],
569+
[4, 3],
570+
[4, 4],
571+
[5, 5]
572+
], { useColumnIndex: false })
573+
574+
expect(engine.getCellValue(adr('A1'))).toEqual(3)
575+
})
576+
577+
it('in sorted horizontal range', () => {
578+
const engine = HyperFormula.buildFromArray([
579+
['=XLOOKUP(3, A2:E2, A2:E2, "NotFound", 1, 2)'],
580+
[1, 2, 4, 5, 6],
581+
], { useColumnIndex: false })
582+
583+
expect(engine.getCellValue(adr('A1'))).toEqual(4)
584+
})
585+
586+
it('in sorted vertical range', () => {
587+
const engine = HyperFormula.buildFromArray([
588+
['=XLOOKUP(3, A2:A6, A2:A6, "NotFound", 1, 2)'],
589+
[1],
590+
[2],
591+
[4],
592+
[5],
593+
[6]
594+
], { useColumnIndex: false })
595+
596+
expect(engine.getCellValue(adr('A1'))).toEqual(4)
597+
})
598+
})
599+
600+
describe('2, performs a wildcard match', () => {
601+
// TODO
602+
})
603+
})
604+
605+
describe('with ColumnIndex column search strategy, when provided with matchMode = ', () => {
606+
// TODO
607+
})
608+
505609
describe('acts similar to Microsoft Excel', () => {
506610
/**
507611
* Examples from

0 commit comments

Comments
 (0)