Skip to content

Commit

Permalink
test: add operators unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinigami92 committed Mar 8, 2024
1 parent 2a2f53a commit 94abb1c
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/operations/operators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export function dropOperatorFamily(
const ifExistsStr = ifExists ? ' IF EXISTS' : '';
const cascadeStr = cascade ? ' CASCADE' : '';

return `DROP OPERATOR FAMILY ${ifExistsStr} ${operatorFamilyNameStr} USING ${indexMethod}${cascadeStr};`;
return `DROP OPERATOR FAMILY${ifExistsStr} ${operatorFamilyNameStr} USING ${indexMethod}${cascadeStr};`;
};

return _drop;
Expand Down
80 changes: 80 additions & 0 deletions test/operations/operators/createOperator.spec.ts
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");');
});
});
});
});
});
40 changes: 40 additions & 0 deletions test/operations/operators/dropOperator.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { describe, expect, it } from 'vitest';
import { dropOperator } from '../../../src/operations/operators';
import { options1 } from '../../utils';

describe('operations', () => {
describe('operators', () => {
describe('dropOperator', () => {
const dropOperatorFn = dropOperator(options1);

it('should return a function', () => {
expect(dropOperatorFn).toBeTypeOf('function');
});

it('should return sql statement', () => {
const statement = dropOperatorFn('^', {
left: 'integer',
right: 'integer',
});

expect(statement).toBeTypeOf('string');
expect(statement).toStrictEqual(
'DROP OPERATOR ^("integer", "integer");'
);
});

it('should return sql statement with dropOptions', () => {
const statement = dropOperatorFn('~', {
right: 'bit',
ifExists: true,
cascade: true,
});

expect(statement).toBeTypeOf('string');
expect(statement).toStrictEqual(
'DROP OPERATOR IF EXISTS ~("none", "bit") CASCADE;'
);
});
});
});
});
36 changes: 36 additions & 0 deletions test/operations/operators/dropOperatorFamily.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { describe, expect, it } from 'vitest';
import { dropOperatorFamily } from '../../../src/operations/operators';
import { options1 } from '../../utils';

describe('operations', () => {
describe('operators', () => {
describe('dropOperatorFamily', () => {
const dropOperatorFamilyFn = dropOperatorFamily(options1);

it('should return a function', () => {
expect(dropOperatorFamilyFn).toBeTypeOf('function');
});

it('should return sql statement', () => {
const statement = dropOperatorFamilyFn('float_ops', 'btree');

expect(statement).toBeTypeOf('string');
expect(statement).toStrictEqual(
'DROP OPERATOR FAMILY "float_ops" USING btree;'
);
});

it('should return sql statement with dropOptions', () => {
const statement = dropOperatorFamilyFn('float_ops', 'btree', {
ifExists: true,
cascade: true,
});

expect(statement).toBeTypeOf('string');
expect(statement).toStrictEqual(
'DROP OPERATOR FAMILY IF EXISTS "float_ops" USING btree CASCADE;'
);
});
});
});
});

0 comments on commit 94abb1c

Please sign in to comment.