-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add operators unit tests (#1022)
- Loading branch information
1 parent
2a2f53a
commit 928773e
Showing
12 changed files
with
704 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { addToOperatorFamily } from '../../../src/operations/operators'; | ||
import { options1 } from '../../utils'; | ||
|
||
describe('operations', () => { | ||
describe('operators', () => { | ||
describe('addToOperatorFamily', () => { | ||
const addToOperatorFamilyFn = addToOperatorFamily(options1); | ||
|
||
it('should return a function', () => { | ||
expect(addToOperatorFamilyFn).toBeTypeOf('function'); | ||
}); | ||
|
||
it.todo('should return sql statement', () => { | ||
const statement = addToOperatorFamilyFn('integer_ops', 'btree', [ | ||
{ | ||
name: '<', | ||
number: 1, | ||
type: 'operator', | ||
params: [{ type: 'int4' }, { type: 'int2' }], | ||
}, | ||
{ | ||
name: '<=', | ||
number: 2, | ||
type: 'operator', | ||
params: [{ type: 'int4' }, { type: 'int2' }], | ||
}, | ||
{ | ||
name: '=', | ||
number: 3, | ||
type: 'operator', | ||
params: [{ type: 'int4' }, { type: 'int2' }], | ||
}, | ||
{ | ||
name: '>=', | ||
number: 4, | ||
type: 'operator', | ||
params: [{ type: 'int4' }, { type: 'int2' }], | ||
}, | ||
{ | ||
name: '>', | ||
number: 5, | ||
type: 'operator', | ||
params: [{ type: 'int4' }, { type: 'int2' }], | ||
}, | ||
{ | ||
name: 'btint42cmp', | ||
number: 1, | ||
type: 'function', | ||
params: [{ type: 'int4' }, { type: 'int2' }], | ||
}, | ||
]); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toStrictEqual( | ||
`ALTER OPERATOR FAMILY "integer_ops" USING btree ADD | ||
OPERATOR 1 "<"(int4, int2), | ||
OPERATOR 2 "<="(int4, int2), | ||
OPERATOR 3 "="(int4, int2), | ||
OPERATOR 4 ">="(int4, int2), | ||
OPERATOR 5 ">"(int4, int2), | ||
FUNCTION 1 "btint42cmp"(int4, int2);` | ||
); | ||
}); | ||
|
||
it.todo('should return sql statement with schema', () => { | ||
const statement = addToOperatorFamilyFn( | ||
{ name: 'integer_ops', schema: 'myschema' }, | ||
'btree', | ||
[ | ||
{ | ||
name: '<', | ||
number: 1, | ||
type: 'operator', | ||
params: [{ type: 'int4' }, { type: 'int2' }], | ||
}, | ||
{ | ||
name: '<=', | ||
number: 2, | ||
type: 'operator', | ||
params: [{ type: 'int4' }, { type: 'int2' }], | ||
}, | ||
{ | ||
name: '=', | ||
number: 3, | ||
type: 'operator', | ||
params: [{ type: 'int4' }, { type: 'int2' }], | ||
}, | ||
{ | ||
name: '>=', | ||
number: 4, | ||
type: 'operator', | ||
params: [{ type: 'int4' }, { type: 'int2' }], | ||
}, | ||
{ | ||
name: '>', | ||
number: 5, | ||
type: 'operator', | ||
params: [{ type: 'int4' }, { type: 'int2' }], | ||
}, | ||
{ | ||
name: 'btint42cmp', | ||
number: 1, | ||
type: 'function', | ||
params: [{ type: 'int4' }, { type: 'int2' }], | ||
}, | ||
] | ||
); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toStrictEqual( | ||
`ALTER OPERATOR FAMILY "myschema"."integer_ops" USING btree ADD | ||
OPERATOR 1 "<"(int4, int2), | ||
OPERATOR 2 "<="(int4, int2), | ||
OPERATOR 3 "="(int4, int2), | ||
OPERATOR 4 ">="(int4, int2), | ||
OPERATOR 5 ">"(int4, int2), | ||
FUNCTION 1 "btint42cmp"(int4, int2);` | ||
); | ||
}); | ||
|
||
describe('reverse', () => { | ||
it('should contain a reverse function', () => { | ||
expect(addToOperatorFamilyFn.reverse).toBeTypeOf('function'); | ||
}); | ||
|
||
it.todo('should return sql statement', () => { | ||
const statement = addToOperatorFamilyFn.reverse( | ||
'integer_ops', | ||
'btree', | ||
[ | ||
{ | ||
name: '<', | ||
number: 1, | ||
type: 'operator', | ||
params: [{ type: 'int4' }, { type: 'int2' }], | ||
}, | ||
{ | ||
name: '<=', | ||
number: 2, | ||
type: 'operator', | ||
params: [{ type: 'int4' }, { type: 'int2' }], | ||
}, | ||
{ | ||
name: '=', | ||
number: 3, | ||
type: 'operator', | ||
params: [{ type: 'int4' }, { type: 'int2' }], | ||
}, | ||
{ | ||
name: '>=', | ||
number: 4, | ||
type: 'operator', | ||
params: [{ type: 'int4' }, { type: 'int2' }], | ||
}, | ||
{ | ||
name: '>', | ||
number: 5, | ||
type: 'operator', | ||
params: [{ type: 'int4' }, { type: 'int2' }], | ||
}, | ||
{ | ||
name: 'btint42cmp', | ||
number: 1, | ||
type: 'function', | ||
params: [{ type: 'int4' }, { type: 'int2' }], | ||
}, | ||
] | ||
); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toBe( | ||
`ALTER OPERATOR FAMILY "integer_ops" USING btree DROP | ||
OPERATOR 1 "<"(int4, int2), | ||
OPERATOR 2 "<="(int4, int2), | ||
OPERATOR 3 "="(int4, int2), | ||
OPERATOR 4 ">="(int4, int2), | ||
OPERATOR 5 ">"(int4, int2), | ||
FUNCTION 1 "btint42cmp"(int4, int2);` | ||
); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { createOperator } from '../../../src/operations/operators'; | ||
import { options1 } from '../../utils'; | ||
|
||
describe('operations', () => { | ||
describe('operators', () => { | ||
describe('createOperator', () => { | ||
const createOperatorFn = createOperator(options1); | ||
|
||
it('should return a function', () => { | ||
expect(createOperatorFn).toBeTypeOf('function'); | ||
}); | ||
|
||
it('should return sql statement', () => { | ||
const statement = createOperatorFn('===', { | ||
left: 'box', | ||
right: 'box', | ||
procedure: 'area_equal_function', | ||
}); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toStrictEqual( | ||
'CREATE OPERATOR === (PROCEDURE = "area_equal_function", LEFTARG = "box", RIGHTARG = "box");' | ||
); | ||
}); | ||
|
||
it('should return sql statement with operatorOptions', () => { | ||
const statement = createOperatorFn('===', { | ||
left: 'box', | ||
right: 'box', | ||
procedure: 'area_equal_function', | ||
commutator: '===', | ||
negator: '!==', | ||
restrict: 'area_restriction_function', | ||
join: 'area_join_function', | ||
hashes: true, | ||
merges: true, | ||
}); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toStrictEqual( | ||
'CREATE OPERATOR === (PROCEDURE = "area_equal_function", LEFTARG = "box", RIGHTARG = "box", COMMUTATOR = ===, NEGATOR = !==, RESTRICT = "area_restriction_function", JOIN = "area_join_function", HASHES, MERGES);' | ||
); | ||
}); | ||
|
||
it('should return sql statement with schema', () => { | ||
const statement = createOperatorFn( | ||
{ name: '===', schema: 'myschema' }, | ||
{ | ||
left: 'box', | ||
right: 'box', | ||
procedure: 'area_equal_function', | ||
} | ||
); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toStrictEqual( | ||
'CREATE OPERATOR myschema.=== (PROCEDURE = "area_equal_function", LEFTARG = "box", RIGHTARG = "box");' | ||
); | ||
}); | ||
|
||
describe('reverse', () => { | ||
it('should contain a reverse function', () => { | ||
expect(createOperatorFn.reverse).toBeTypeOf('function'); | ||
}); | ||
|
||
it('should return sql statement', () => { | ||
const statement = createOperatorFn.reverse('===', { | ||
left: 'box', | ||
right: 'box', | ||
procedure: 'area_equal_function', | ||
}); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toBe('DROP OPERATOR ===("box", "box");'); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { createOperatorClass } from '../../../src/operations/operators'; | ||
import { options1 } from '../../utils'; | ||
|
||
describe('operations', () => { | ||
describe('operators', () => { | ||
describe('createOperatorClass', () => { | ||
const createOperatorClassFn = createOperatorClass(options1); | ||
|
||
it('should return a function', () => { | ||
expect(createOperatorClassFn).toBeTypeOf('function'); | ||
}); | ||
|
||
it.todo('should return sql statement', () => { | ||
const statement = createOperatorClassFn( | ||
'gist__int_ops', | ||
'_int4', | ||
'gist', | ||
[ | ||
{ | ||
name: '&&', | ||
number: 3, | ||
type: 'operator', | ||
}, | ||
], | ||
{ | ||
default: true, | ||
} | ||
); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toStrictEqual( | ||
`CREATE OPERATOR CLASS "gist__int_ops" DEFAULT FOR TYPE "_int4" USING "gist" AS | ||
FUNCTION 3 "&&"();` | ||
); | ||
}); | ||
|
||
it.todo('should return sql statement with operatorOptions', () => {}); | ||
|
||
it.todo('should return sql statement with schema', () => {}); | ||
|
||
describe('reverse', () => { | ||
it('should contain a reverse function', () => { | ||
expect(createOperatorClassFn.reverse).toBeTypeOf('function'); | ||
}); | ||
|
||
it.todo('should return sql statement', () => {}); | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.