-
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(utils): test utils formatLines (#1059)
- Loading branch information
1 parent
fd7dba7
commit 3e02f32
Showing
1 changed file
with
54 additions
and
0 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
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`); | ||
}); | ||
}); | ||
}); |