Skip to content

Commit

Permalink
tests: split tests by option
Browse files Browse the repository at this point in the history
  • Loading branch information
wdavidw committed May 2, 2019
1 parent 3048179 commit 14ef24f
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 31 deletions.
13 changes: 0 additions & 13 deletions test/colors.coffee

This file was deleted.

13 changes: 13 additions & 0 deletions test/option.char.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

should = require 'should'
import pad from '../src'

describe 'option.char', ->

it 'should pad right', ->
pad('yeah', 6, '-').should.eql 'yeah--'
pad('yeah', 6, char: '-').should.eql 'yeah--'

it 'should pad left', ->
pad(6, '234', '0').should.eql '000234'
pad(6, '234', char: '0').should.eql '000234'
13 changes: 13 additions & 0 deletions test/option.colors.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

should = require 'should'
import pad from '../src'

describe 'option.colors', ->

it 'should pad right', ->
pad('\u001b[33mabc\u001b[39m', 6, colors: true)
.should.eql '\u001b[33mabc\u001b[39m '

it 'should pad left with an additionnal option', ->
pad(6, '\u001b[33mabc\u001b[39m', char: '-', colors: true)
.should.eql '---\u001b[33mabc\u001b[39m'
11 changes: 11 additions & 0 deletions test/option.fixed_width.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

should = require 'should'
import pad from '../src'

describe 'option.fixed_width', ->

it 'characters with more than one colum', ->
# 2 chinese characters
chars = Buffer.from("e6938de4bd9c", 'hex').toString()
pad(6, chars).length.should.eql 4
pad(6, chars, fixed_width: true).length.should.eql 6
11 changes: 11 additions & 0 deletions test/option.strip.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

should = require 'should'
import pad from '../src'

describe 'option.strip', ->

it 'strip if text longer than length', ->
pad(2, 'abcdef', strip: true).should.eql 'ef'

it 'strip if text longer than length', ->
pad('abcdef', 2, strip: true).should.eql 'ab'
18 changes: 0 additions & 18 deletions test/pad.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,6 @@ describe 'pad', ->
it 'should pad left', ->
pad(6, 'abc').should.eql ' abc'

it 'should pad right', ->
pad('yeah', 6, '-').should.eql 'yeah--'

it 'should pad left', ->
pad(6, '234', '0').should.eql '000234'

it 'accept length inferior to text', ->
pad(0, 'foo').should.eql 'foo'

it 'strip if text longer than length', ->
pad(2, 'abcdef', strip: true).should.eql 'ef'

it 'strip if text longer than length', ->
pad('abcdef', 2, strip: true).should.eql 'ab'

it 'characters with more than one colum', ->
# 2 chinese characters
chars = Buffer.from("e6938de4bd9c", 'hex').toString()
pad(6, chars).length.should.eql 4
pad(6, chars, fixed_width: true).length.should.eql 6

0 comments on commit 14ef24f

Please sign in to comment.