Skip to content

Commit

Permalink
build(csv-parse): build and write test after info ts definition
Browse files Browse the repository at this point in the history
  • Loading branch information
wdavidw committed May 26, 2023
1 parent 2dd2a92 commit 4cd4600
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
4 changes: 4 additions & 0 deletions packages/csv-parse/dist/cjs/index.d.cts
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,10 @@ export interface Info {
* Number of non uniform records when `relax_column_count` is true.
*/
readonly invalid_field_length: number;
/**
* Normalized verion of `options.columns` when `options.columns` is true, boolean otherwise.
*/
readonly columns: boolean | { name: string }[] | { disabled: true }[];
}

export type CsvErrorCode =
Expand Down
4 changes: 4 additions & 0 deletions packages/csv-parse/dist/esm/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,10 @@ export interface Info {
* Number of non uniform records when `relax_column_count` is true.
*/
readonly invalid_field_length: number;
/**
* Normalized verion of `options.columns` when `options.columns` is true, boolean otherwise.
*/
readonly columns: boolean | { name: string }[] | { disabled: true }[];
}

export type CsvErrorCode =
Expand Down
5 changes: 3 additions & 2 deletions packages/csv-parse/test/api.types.sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,13 @@ describe('API Types', () => {

it('Info', () => {
const info: Info = {
bytes: 1,
columns: true,
comment_lines: 1,
empty_lines: 1,
invalid_field_length: 1,
lines: 1,
records: 1,
bytes: 1,
invalid_field_length: 1,
};
return info;
})
Expand Down
23 changes: 22 additions & 1 deletion packages/csv-parse/test/api.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ describe('API Types', () => {
describe('Info', () => {

const fakeinfo = {
bytes: 1,
bytes: 1, columns: true,
comment_lines: 1, empty_lines: 1,
invalid_field_length: 1, lines: 1, records: 1
}
Expand Down Expand Up @@ -128,6 +128,27 @@ describe('API Types', () => {
const invalid_field_length: number = info.invalid_field_length
invalid_field_length
})

it('columns may be a boolean or an array', () => {
// Boolean
const infoBoolean: Info = {
bytes: 1, columns: true,
comment_lines: 1, empty_lines: 1,
invalid_field_length: 1, lines: 1, records: 1
}
// Array with name = <string>
const infoName: Info = {
bytes: 1, columns: [{name: 'a column'}],
comment_lines: 1, empty_lines: 1,
invalid_field_length: 1, lines: 1, records: 1
}
// Array with disabled = true
const infoDisabled: Info = {
bytes: 1, columns: [{disabled: true}],
comment_lines: 1, empty_lines: 1,
invalid_field_length: 1, lines: 1, records: 1
}
})

})

Expand Down

0 comments on commit 4cd4600

Please sign in to comment.