Comparing version 1.0.0 to 1.0.1
{ | ||
"name": "smart-line", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "a smart line with formatting features", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -21,3 +21,5 @@ # smart-line | ||
line.left('xyz'); | ||
assert.equal(line,'xyz abc '); | ||
assert.equal(line,'xyz '); | ||
line.left('abc',7); | ||
assert.equal(line,'xyz abc '); | ||
``` | ||
@@ -24,0 +26,0 @@ |
const routines = require('..'); | ||
const smartLine = require('..').line; | ||
const assert = require('assert'); | ||
describe('Test align routines', function(){ | ||
beforeEach(function(){ | ||
describe('Test align routines', ()=>{ | ||
beforeEach(()=>{ | ||
source = '1234567890'; | ||
@@ -10,3 +10,3 @@ }); | ||
// insert align | ||
it('should insert align a smaller string', function(){ | ||
it('should insert align a smaller string', ()=>{ | ||
var rc = routines.insertalign(source,'abcd',4,3); | ||
@@ -16,3 +16,3 @@ assert(rc==='123abc7890'); | ||
it('should insert a larger string', function(){ | ||
it('should insert a larger string', ()=>{ | ||
var rc = routines.insertalign(source,'abcdefghijklmnop',3,15); | ||
@@ -23,3 +23,3 @@ assert(rc==='12abcdefgh'); | ||
// right align | ||
it('should right align a smaller string',function(){ | ||
it('should right align a smaller string',()=>{ | ||
var r = 'abcd'; | ||
@@ -30,3 +30,3 @@ var rc = routines.rightalign(source,r,4,3); | ||
it('should right align a larger string', function(){ | ||
it('should right align a larger string', ()=>{ | ||
var rc = routines.rightalign(source, 'abcdefghijklm',1,5); | ||
@@ -36,3 +36,3 @@ assert(rc==='ijklm67890'); | ||
it('should pad in case a shorter string provided with larger count',function(){ | ||
it('should pad in case a shorter string provided with larger count',()=>{ | ||
var rc = routines.rightalign(source,'abc',3,5); | ||
@@ -42,3 +42,3 @@ assert(rc==='12 abc890'); | ||
it('should correctly assume length',function(){ | ||
it('should correctly assume length',()=>{ | ||
var rc = routines.rightalign(source,'jaja',6); | ||
@@ -48,3 +48,3 @@ assert(rc==='12345jaja0'); | ||
it('should default to right align at the end of the string', function(){ | ||
it('should default to right align at the end of the string', ()=>{ | ||
var rc = routines.rightalign(source,'abc'); | ||
@@ -54,3 +54,3 @@ assert(rc==='1234567abc'); | ||
it('should trim the left if would write passed the end of string', function(){ | ||
it('should trim the left if would write passed the end of string', ()=>{ | ||
var rc = routines.rightalign(source,'abcdefghijklm',5,7); | ||
@@ -60,3 +60,3 @@ assert(rc==='1234hijklm'); | ||
it('should trim the left if target is shorter than source',function(){ | ||
it('should trim the left if target is shorter than source',()=>{ | ||
var rc = routines.rightalign('0000','123456',1); | ||
@@ -67,3 +67,3 @@ assert(rc==='3456'); | ||
// left align | ||
it('should left align by default',function(){ | ||
it('should left align by default',()=>{ | ||
var rc = routines.leftalign(source,'abc'); | ||
@@ -73,3 +73,3 @@ assert(rc==='abc4567890'); | ||
it('should left align in the middle',function(){ | ||
it('should left align in the middle',()=>{ | ||
var rc = routines.leftalign(source,'abc',3); | ||
@@ -79,3 +79,3 @@ assert(rc==='12abc67890'); | ||
it('should left align in the middle and cutoff chars',function(){ | ||
it('should left align in the middle and cutoff chars',()=>{ | ||
var rc = routines.leftalign(source,'abcd',3,3); | ||
@@ -85,3 +85,3 @@ assert(rc==='12abc67890'); | ||
it('should left align a larger string',function(){ | ||
it('should left align a larger string',()=>{ | ||
var rc = routines.leftalign(source,'abcdefg',7); | ||
@@ -91,3 +91,3 @@ assert(rc==='123456abcd'); | ||
it('should pad on the right if source smaller than count',function(){ | ||
it('should pad on the right if source smaller than count',()=>{ | ||
var rc = routines.leftalign(source,'abc',null,5); | ||
@@ -98,3 +98,3 @@ assert(rc==='abc 67890'); | ||
// center align | ||
it('should center align even length',function(){ | ||
it('should center align even length',()=>{ | ||
var rc = routines.centeralign(source,'abcd'); | ||
@@ -104,3 +104,3 @@ assert(rc==='123abcd890'); | ||
it('should center align odd length',function(){ | ||
it('should center align odd length',()=>{ | ||
var rc = routines.centeralign(source,'abc'); | ||
@@ -110,3 +110,3 @@ assert(rc==='123abc7890'); | ||
it('should left align if source larger than target',function(){ | ||
it('should left align if source larger than target',()=>{ | ||
var rc = routines.centeralign(source,'abcdefghijklmn'); | ||
@@ -126,4 +126,4 @@ assert(rc==='abcdefghij'); | ||
describe('Test the line object',function(){ | ||
it('should pass insert and left align correctly', function(){ | ||
describe('Test the line object',()=>{ | ||
it('should pass insert and left align correctly', ()=>{ | ||
var line = new smartLine(10); | ||
@@ -134,4 +134,13 @@ line.insert('abc',6); | ||
}); | ||
it('should pass the center and right align correctly',function(){ | ||
it ('should be able to left align anywhere on the line',()=>{ | ||
var line = new smartLine(10); | ||
line.left('xyz'); | ||
assert.equal(line,'xyz '); | ||
line.left('abc',7); | ||
assert.equal(line,'xyz abc '); | ||
}); | ||
it('should pass the center and right align correctly',()=>{ | ||
var line = new smartLine(10); | ||
line.center('abc'); | ||
@@ -149,12 +158,12 @@ line.right('xyz'); | ||
describe('Test fixedString', function(){ | ||
it('should create a short string defaulting the char',function(){ | ||
describe('Test fixedString', ()=>{ | ||
it('should create a short string defaulting the char',()=>{ | ||
assert(routines.fixedString(3)===' '); | ||
}); | ||
it('should create a string of other characters', function(){ | ||
it('should create a string of other characters', ()=>{ | ||
assert(routines.fixedString(3,'#')==='###'); | ||
}); | ||
it('should return an empty string if count < 1',function(){ | ||
it('should return an empty string if count < 1',()=>{ | ||
assert(routines.fixedString(0)===''); | ||
@@ -161,0 +170,0 @@ assert(routines.fixedString(-1)===''); |
8018
198
40