Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(utils): test utils formatLines #1059

Merged
merged 1 commit into from
Apr 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
54 changes: 54 additions & 0 deletions test/utils/formatLines.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { describe, expect, it } from 'vitest';
import { formatLines } from '../../src/utils';

describe('utils', () => {
describe('formatLines', () => {
it('should use a default replace of 2 whitespace', () => {
const actual = formatLines([]);

expect(actual).toBeTypeOf('string');
expect(actual).toBe(' ');
});

it('should join with comma and a default indent of 2 whitespace', () => {
const actual = formatLines([
'CLUSTER ON "a_cluster"',
'DEPENDS ON EXTENSION "a_extension"',
'SET (fillfactor = 70, fillfactor2 = 50)',
'RESET (reset1, reset2)',
]);

expect(actual).toBeTypeOf('string');
expect(actual).toBe(` CLUSTER ON "a_cluster",
DEPENDS ON EXTENSION "a_extension",
SET (fillfactor = 70, fillfactor2 = 50),
RESET (reset1, reset2)`);
});

it('should join with comma and a custom replacement', () => {
const actual = formatLines(
[
'CONSTRAINT "zipchk" CHECK (char_length(zipcode) = 5) DEFERRABLE INITIALLY IMMEDIATE',
'CONSTRAINT "zipchk" CHECK (zipcode <> 0) DEFERRABLE INITIALLY IMMEDIATE',
'CONSTRAINT "zipchk" EXCLUDE zipcode WITH = DEFERRABLE INITIALLY IMMEDIATE',
],
' ADD '
);

expect(actual).toBeTypeOf('string');
expect(actual)
.toBe(` ADD CONSTRAINT "zipchk" CHECK (char_length(zipcode) = 5) DEFERRABLE INITIALLY IMMEDIATE,
ADD CONSTRAINT "zipchk" CHECK (zipcode <> 0) DEFERRABLE INITIALLY IMMEDIATE,
ADD CONSTRAINT "zipchk" EXCLUDE zipcode WITH = DEFERRABLE INITIALLY IMMEDIATE`);
});

it('should replace newlines with a whitespace', () => {
const actual = formatLines(['a\r\nb', 'c\rd', 'e\nf']);

expect(actual).toBeTypeOf('string');
expect(actual).toBe(` a b,
c d,
e f`);
});
});
});