Skip to content

Instantly share code, notes, and snippets.

@gouf
Created December 9, 2018 06:43
Show Gist options
  • Save gouf/d88e905cd7d0f0280f932956a0934f8e to your computer and use it in GitHub Desktop.
Save gouf/d88e905cd7d0f0280f932956a0934f8e to your computer and use it in GitHub Desktop.
某ページの表記方法を改変
// Ref:
// * [Mocha - the fun, simple, flexible JavaScript test framework](https://mochajs.org/)
// * [Chai](https://www.chaijs.com/)
// Run commands as bellow:
// yarn install
// yarn run mocha --watch
var expect = require('chai').expect
function stripDigits(string) {
var match = string.match(/^0{2,}(.+)/)
return match ? match[1] : string
}
// 某ページの一覧表示が固定長で数字が並ぶ表示で見づらい
// 改善するためのコードスニペットをテストする
describe('Strip redundant 0', function() {
// 識別コード以外に金額にもたくさんの0が付与されてるのでそれを削りたい
it('return 12', function() {
var target = '00000000012'
var result = stripDigits(target)
expect(result).to.be.equal('12')
})
it('return 0', function() {
var target = '00000000000'
var result = stripDigits(target)
expect(result).to.be.equal('0')
})
// その他文字列は処理対象外になる
it('return 配偶者控除等無し', function() {
var target = '配偶者控除等無し'
var result = stripDigits(target)
expect(result).to.be.equal('配偶者控除等無し')
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment