Skip to content

Commit

Permalink
test(indention): added tests for custom indention
Browse files Browse the repository at this point in the history
  • Loading branch information
skolmer committed Nov 13, 2016
1 parent 741696a commit 0adba59
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 92 deletions.
182 changes: 91 additions & 91 deletions __tests__/data/schema.json
@@ -1,93 +1,93 @@
{
"type": "object",
"properties": {
"$schema": {
"type": "string"
},
"\n <user name=\"${0}\">${1}</user>\n ": {
"type": "string",
"minLength": 1,
"pattern": "(?=.*?\\$\\{0\\})(?=.*?\\$\\{1\\})"
},
"\n <users>\n ${0}\n </users>\n": {
"type": "string",
"minLength": 1,
"pattern": "(?=.*?\\$\\{0\\})"
},
"custom group": {
"type": "object",
"properties": {
"Hello ${0}, you have ${1} in your bank account.": {
"type": "string",
"minLength": 1,
"pattern": "(?=.*?\\$\\{0\\})(?=.*?\\$\\{1\\})"
}
},
"required": [
"Hello ${0}, you have ${1} in your bank account."
]
},
"custom group 2": {
"type": "object",
"properties": {
"Hello ${0}, you have ${1} in your bank account.": {
"type": "string",
"minLength": 1,
"pattern": "(?=.*?\\$\\{0\\})(?=.*?\\$\\{1\\})"
}
},
"required": [
"Hello ${0}, you have ${1} in your bank account."
]
},
"custom inline group": {
"type": "object",
"properties": {
"Hallo!": {
"type": "string",
"minLength": 1
},
"Hello!": {
"type": "string",
"minLength": 1
},
"Welcome!": {
"type": "string",
"minLength": 1
}
},
"required": [
"Hallo!",
"Hello!",
"Welcome!"
]
},
"grouped.js": {
"type": "object",
"properties": {
"Hello ${0}, you have ${1} in your bank account.": {
"type": "string",
"minLength": 1,
"pattern": "(?=.*?\\$\\{0\\})(?=.*?\\$\\{1\\})"
},
"Hello!": {
"type": "string",
"minLength": 1
}
},
"required": [
"Hello ${0}, you have ${1} in your bank account.",
"Hello!"
]
}
},
"required": [
"\n <user name=\"${0}\">${1}</user>\n ",
"\n <users>\n ${0}\n </users>\n",
"custom group",
"custom group 2",
"custom inline group",
"grouped.js"
],
"additionalProperties": false
"type": "object",
"properties": {
"$schema": {
"type": "string"
},
"\n <user name=\"${0}\">${1}</user>\n ": {
"type": "string",
"minLength": 1,
"pattern": "(?=.*?\\$\\{0\\})(?=.*?\\$\\{1\\})"
},
"\n <users>\n ${0}\n </users>\n": {
"type": "string",
"minLength": 1,
"pattern": "(?=.*?\\$\\{0\\})"
},
"custom group": {
"type": "object",
"properties": {
"Hello ${0}, you have ${1} in your bank account.": {
"type": "string",
"minLength": 1,
"pattern": "(?=.*?\\$\\{0\\})(?=.*?\\$\\{1\\})"
}
},
"required": [
"Hello ${0}, you have ${1} in your bank account."
]
},
"custom group 2": {
"type": "object",
"properties": {
"Hello ${0}, you have ${1} in your bank account.": {
"type": "string",
"minLength": 1,
"pattern": "(?=.*?\\$\\{0\\})(?=.*?\\$\\{1\\})"
}
},
"required": [
"Hello ${0}, you have ${1} in your bank account."
]
},
"custom inline group": {
"type": "object",
"properties": {
"Hallo!": {
"type": "string",
"minLength": 1
},
"Hello!": {
"type": "string",
"minLength": 1
},
"Welcome!": {
"type": "string",
"minLength": 1
}
},
"required": [
"Hallo!",
"Hello!",
"Welcome!"
]
},
"grouped.js": {
"type": "object",
"properties": {
"Hello ${0}, you have ${1} in your bank account.": {
"type": "string",
"minLength": 1,
"pattern": "(?=.*?\\$\\{0\\})(?=.*?\\$\\{1\\})"
},
"Hello!": {
"type": "string",
"minLength": 1
}
},
"required": [
"Hello ${0}, you have ${1} in your bank account.",
"Hello!"
]
}
},
"required": [
"\n <user name=\"${0}\">${1}</user>\n ",
"\n <users>\n ${0}\n </users>\n",
"custom group",
"custom group 2",
"custom inline group",
"grouped.js"
],
"additionalProperties": false
}
44 changes: 44 additions & 0 deletions __tests__/generateTranslationSchema.test.js
Expand Up @@ -205,4 +205,48 @@ describe('i18n-tag-schema', () => {
expect(JSON.parse(json)).toEqual({})
fs.unlinkSync(schemaPath)
})

it('should have tabs as default indention', async () => {
const filter = '\\.jsx?$'
const rootPath = path.resolve(__dirname, './data')
const schemaPath = path.resolve(__dirname, './data/schema.json')
await generateTranslationSchema({
rootPath,
schemaPath,
filter,
logger: { toConsole: true }
})
const json = fs.readFileSync(schemaPath, 'utf-8')
expect(json).toContain('\n\t"type": "object"')
})

it('should allow 2 spaces as tabs', async () => {
const filter = '\\.jsx?$'
const rootPath = path.resolve(__dirname, './data')
const schemaPath = path.resolve(__dirname, './data/schema.json')
await generateTranslationSchema({
rootPath,
schemaPath,
filter,
logger: { toConsole: true },
indention: 2
})
const json = fs.readFileSync(schemaPath, 'utf-8')
expect(json).toContain('\n "type": "object"')
})

it('should allow 4 spaces as tabs', async () => {
const filter = '\\.jsx?$'
const rootPath = path.resolve(__dirname, './data')
const schemaPath = path.resolve(__dirname, './data/schema.json')
await generateTranslationSchema({
rootPath,
schemaPath,
filter,
logger: { toConsole: true },
indention: 4
})
const json = fs.readFileSync(schemaPath, 'utf-8')
expect(json).toContain('\n "type": "object"')
})
})
2 changes: 1 addition & 1 deletion lib/utils.js
Expand Up @@ -13,7 +13,7 @@ const getOrCreateGroup = (templates, group) => {
}

export const getTabChar = (spaces) => {
if(isNaN(spaces) || spaces < -0) return '\t'
if(isNaN(spaces) || spaces < 0) return '\t'
return ' '.repeat(spaces)
}

Expand Down

0 comments on commit 0adba59

Please sign in to comment.