-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #476 from yegortokmakov/doublequote
Option to use double quotes (") as escape character
- Loading branch information
Showing
6 changed files
with
192 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
import { existsSync, readFileSync, rmdirSync } from 'fs'; | ||
|
||
import { convertFromDirectory } from '../../index'; | ||
|
||
describe('Use double quotes for string escapes', () => { | ||
const typeOutputDirectory = './src/__tests__/doublequotesEscape/interfaces'; | ||
|
||
test('default behavior / single quotes', async () => { | ||
if (existsSync(typeOutputDirectory)) { | ||
rmdirSync(typeOutputDirectory, { recursive: true }); | ||
} | ||
const result = await convertFromDirectory({ | ||
schemaDirectory: './src/__tests__/doublequotesEscape/schemas', | ||
typeOutputDirectory | ||
}); | ||
|
||
expect(result).toBe(true); | ||
|
||
const readmeContent = readFileSync(`${typeOutputDirectory}/Allow.ts`).toString(); | ||
|
||
expect(readmeContent).toBe(`/** | ||
* This file was automatically generated by joi-to-typescript | ||
* Do not modify this file manually | ||
*/ | ||
export type Blank = string; | ||
export type BlankNull = string | null | ''; | ||
/** | ||
* This is date | ||
*/ | ||
export type DateOptions = Date | null; | ||
/** | ||
* Test Schema Name | ||
*/ | ||
export type Name = string; | ||
export type NormalList = 'red' | 'green' | 'blue'; | ||
export type NormalRequiredList = 'red' | 'green' | 'blue'; | ||
/** | ||
* nullable | ||
*/ | ||
export type NullName = string | null; | ||
export type NullNumber = number | null; | ||
export type Numbers = 1 | 2 | 3 | 4 | 5; | ||
`); | ||
}); | ||
|
||
test('doublequoteEscape: false / single quotes', async () => { | ||
if (existsSync(typeOutputDirectory)) { | ||
rmdirSync(typeOutputDirectory, { recursive: true }); | ||
} | ||
const result = await convertFromDirectory({ | ||
schemaDirectory: './src/__tests__/doublequotesEscape/schemas', | ||
typeOutputDirectory, | ||
doublequoteEscape: false, | ||
}); | ||
|
||
expect(result).toBe(true); | ||
|
||
const readmeContent = readFileSync(`${typeOutputDirectory}/Allow.ts`).toString(); | ||
|
||
expect(readmeContent).toBe(`/** | ||
* This file was automatically generated by joi-to-typescript | ||
* Do not modify this file manually | ||
*/ | ||
export type Blank = string; | ||
export type BlankNull = string | null | ''; | ||
/** | ||
* This is date | ||
*/ | ||
export type DateOptions = Date | null; | ||
/** | ||
* Test Schema Name | ||
*/ | ||
export type Name = string; | ||
export type NormalList = 'red' | 'green' | 'blue'; | ||
export type NormalRequiredList = 'red' | 'green' | 'blue'; | ||
/** | ||
* nullable | ||
*/ | ||
export type NullName = string | null; | ||
export type NullNumber = number | null; | ||
export type Numbers = 1 | 2 | 3 | 4 | 5; | ||
`); | ||
}); | ||
|
||
test('doublequoteEscape: true / double quotes', async () => { | ||
if (existsSync(typeOutputDirectory)) { | ||
rmdirSync(typeOutputDirectory, { recursive: true }); | ||
} | ||
const result = await convertFromDirectory({ | ||
schemaDirectory: './src/__tests__/doublequotesEscape/schemas', | ||
typeOutputDirectory, | ||
doublequoteEscape: true, | ||
}); | ||
|
||
expect(result).toBe(true); | ||
|
||
const readmeContent = readFileSync(`${typeOutputDirectory}/Allow.ts`).toString(); | ||
|
||
expect(readmeContent).toBe(`/** | ||
* This file was automatically generated by joi-to-typescript | ||
* Do not modify this file manually | ||
*/ | ||
export type Blank = string; | ||
export type BlankNull = string | null | ""; | ||
/** | ||
* This is date | ||
*/ | ||
export type DateOptions = Date | null; | ||
/** | ||
* Test Schema Name | ||
*/ | ||
export type Name = string; | ||
export type NormalList = "red" | "green" | "blue"; | ||
export type NormalRequiredList = "red" | "green" | "blue"; | ||
/** | ||
* nullable | ||
*/ | ||
export type NullName = string | null; | ||
export type NullNumber = number | null; | ||
export type Numbers = 1 | 2 | 3 | 4 | 5; | ||
`); | ||
}); | ||
|
||
}); |
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,11 @@ | ||
import Joi from 'joi'; | ||
|
||
export const Name = Joi.string().optional().description('Test Schema Name').allow('').meta({ className: 'Name' }); | ||
export const NullName = Joi.string().optional().description('nullable').allow(null); | ||
export const BlankNull = Joi.string().optional().allow(null, ''); | ||
export const Blank = Joi.string().allow(''); | ||
export const NormalList = Joi.string().allow('red', 'green', 'blue'); | ||
export const NormalRequiredList = Joi.string().allow('red', 'green', 'blue').required(); | ||
export const Numbers = Joi.number().optional().allow(1, 2, 3, 4, 5); | ||
export const NullNumber = Joi.number().optional().allow(null); | ||
export const DateOptions = Joi.date().allow(null).description('This is date'); |
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