-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose
parseColumnType
function (#316)
- Loading branch information
Showing
21 changed files
with
2,110 additions
and
11 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
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
56 changes: 56 additions & 0 deletions
56
packages/client-common/__tests__/unit/parse_column_types.test.ts
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,56 @@ | ||
import { parseFixedStringType } from '../../src/parse' | ||
|
||
describe('Columns types parser', () => { | ||
describe('FixedString', () => { | ||
it('should parse FixedString', async () => { | ||
const args: [string, number][] = [ | ||
['FixedString(1)', 1], | ||
['FixedString(42)', 42], | ||
['FixedString(100)', 100], | ||
['FixedString(32768)', 32768], | ||
] | ||
args.forEach(([columnType, sizeBytes]) => { | ||
const result = parseFixedStringType({ | ||
columnType, | ||
sourceType: columnType, | ||
}) | ||
expect(result) | ||
.withContext( | ||
`Expected ${columnType} to be parsed as a FixedString with size ${sizeBytes}`, | ||
) | ||
.toEqual({ type: 'FixedString', sizeBytes, sourceType: columnType }) | ||
}) | ||
}) | ||
|
||
it('should throw on invalid FixedString type', async () => { | ||
const args: [string][] = [ | ||
['FixedString'], | ||
['FixedString('], | ||
['FixedString()'], | ||
['String'], | ||
] | ||
args.forEach(([columnType]) => { | ||
expect(() => | ||
parseFixedStringType({ columnType, sourceType: columnType }), | ||
) | ||
.withContext(`Expected ${columnType} to throw`) | ||
.toThrowError('Invalid FixedString type') | ||
}) | ||
}) | ||
|
||
it('should throw on invalid FixedString size', async () => { | ||
const args: [string][] = [ | ||
['FixedString(0)'], | ||
['FixedString(x)'], | ||
[`FixedString(')`], | ||
] | ||
args.forEach(([columnType]) => { | ||
expect(() => | ||
parseFixedStringType({ columnType, sourceType: columnType }), | ||
) | ||
.withContext(`Expected ${columnType} to throw`) | ||
.toThrowError('Invalid FixedString size in bytes') | ||
}) | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.