Skip to content

Commit

Permalink
💚 test(path): add array syntax tests
Browse files Browse the repository at this point in the history
Closes #7
  • Loading branch information
kazupon committed Sep 15, 2016
1 parent 08e4273 commit bccda7e
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 2 deletions.
22 changes: 20 additions & 2 deletions test/specs/fixture/locales.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,16 @@ export default {
list: 'Hello {0}, how are you? | Hi {0}, you look fine'
},
fallback: 'this is fallback | this is a plural fallback'
}
},
errors: [
'this is 0 error code message',
{
internal1: 'this is internal 1 error message'
},
[
'this is nested array error 1'
]
]
},
ja: {
message: {
Expand All @@ -45,6 +54,15 @@ export default {
list: 'こんにちは {0}, ごきげんいかが?| こんにちは {0}, ごきげんいかが?'
},
fallback: 'これはフォールバック | ザ・ワールド'
}
},
errors: [
'これはエラーコード0のエラーメッセージです。',
{
internal1: 'これは内部エラーコード1のエラーメッセージです。'
},
[
'これはネストされた配列のエラー1です。'
]
]
}
}
20 changes: 20 additions & 0 deletions test/specs/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,26 @@ describe('i18n', () => {
assert.equal(Vue.t('Hello'), 'Hello')
})
})

describe('array keypath', () => {
context('basic', () => {
it('should be translated', () => {
assert.equal(Vue.t('errors[0]'), locales.en.errors[0])
})
})

context('object', () => {
it('should be translated', () => {
assert.equal(Vue.t('errors[1].internal1'), locales.en.errors[1].internal1)
})
})

context('array', () => {
it('should be translated', () => {
assert.equal(Vue.t('errors[2][0]'), locales.en.errors[2][0])
})
})
})
})

describe('format arguments', () => {
Expand Down
18 changes: 18 additions & 0 deletions test/specs/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,24 @@ describe('path', () => {
})
})

describe('number key in object', () => {
it('should get value', () => {
assert.equal(
getValue({ errors: { '1': 'error number 1' } }, 'errors[1]'),
'error number 1'
)
})
})

describe('array', () => {
it('should get value', () => {
assert.equal(
getValue({ errors: ['error number 0'] }, 'errors[0]'),
'error number 0'
)
})
})

describe('not found', () => {
it('should not get null', () => {
assert.equal(getValue({}, 'a.b'), null)
Expand Down

0 comments on commit bccda7e

Please sign in to comment.