This commit is contained in:
AntiPontifex 2023-10-24 15:42:41 -04:00
commit 7aa78e976b
4 changed files with 180 additions and 163 deletions

File diff suppressed because it is too large Load diff

View file

@ -23,12 +23,11 @@ async function main() {
if (file.extension() !== 'csv') continue if (file.extension() !== 'csv') continue
const csv = await dataStorage.load(file.basename()) const csv = await dataStorage.load(file.basename())
if (/\s+$/.test(csv))
return handleError(`Error: empty lines at the end of file not allowed (${filepath})`)
const rows = csv.split(/\r\n/) const rows = csv.split(/\r\n/)
const headers = rows[0].split(',') const headers = rows[0].split(',')
for (const [i, line] of rows.entries()) { for (const [i, line] of rows.entries()) {
if (!line.trim()) continue
if (line.indexOf('\n') > -1) if (line.indexOf('\n') > -1)
return handleError( return handleError(
`Error: row ${i + 1} has the wrong line ending character, should be CRLF (${filepath})` `Error: row ${i + 1} has the wrong line ending character, should be CRLF (${filepath})`

View file

@ -1,3 +1,3 @@
id,name,alt_names,network,owners,country,subdivision,city,broadcast_area,languages,categories,is_nsfw,launched,closed,replaced_by,website,logo id,name,alt_names,network,owners,country,subdivision,city,broadcast_area,languages,categories,is_nsfw,launched,closed,replaced_by,website,logo
PeoplesWeather.do,People°s Weather,,,,DO,,,c/DO,spa,,FALSE,,,,,https://i.imgur.com/7oNe8xj.png PeoplesWeather.do,People°s Weather,,,,DO,,,c/DO,spa,,FALSE,,,,,https://i.imgur.com/7oNe8xj.png
KSTVKids.ua,¡KS TV | Kids,,,,UA,,,c/UA,ukr,,FALSE,,,,,https://i.imgur.com/CmRfj78.png KSTVKids.ua,¡KS TV | Kids,,,,UA,,,c/UA,ukr,,FALSE,,,,,https://i.imgur.com/CmRfj78.png

1 id name alt_names network owners country subdivision city broadcast_area languages categories is_nsfw launched closed replaced_by website logo
2 PeoplesWeather.do People°s Weather DO c/DO spa FALSE https://i.imgur.com/7oNe8xj.png
3 KSTVKids.ua ¡KS TV | Kids UA c/UA ukr FALSE https://i.imgur.com/CmRfj78.png

View file

@ -6,20 +6,6 @@ type ExecError = {
} }
describe('db:validate', () => { describe('db:validate', () => {
it('shows an error if there is an empty line at the end of the file', () => {
try {
execSync('DATA_DIR=tests/__data__/input/validate/empty_line npm run db:validate', {
encoding: 'utf8'
})
process.exit(1)
} catch (error) {
expect((error as ExecError).status).toBe(1)
expect((error as ExecError).stdout).toContain(
'Error: empty lines at the end of file not allowed (channels.csv)'
)
}
})
it('shows an error if the number of columns in a row is incorrect', () => { it('shows an error if the number of columns in a row is incorrect', () => {
try { try {
execSync('DATA_DIR=tests/__data__/input/validate/wrong_num_cols npm run db:validate', { execSync('DATA_DIR=tests/__data__/input/validate/wrong_num_cols npm run db:validate', {