diff --git a/test/color.spec.js b/test/color.spec.js index be5ae0e..093c385 100644 --- a/test/color.spec.js +++ b/test/color.spec.js @@ -51,5 +51,53 @@ describe('color', () => { `${steelblue}`.should.eql('#4682b4'); `${mid1}`.should.eql('rgba(70, 130, 180, 0.53)'); `${mid2}`.should.eql('rgba(70, 130, 180, 0.77)'); + + // s=0 + const grey = new Color('hsl(207, 0%, 49%)'); + // h=0 + const red1 = new Color('hsl(0, 100%, 50%)'); + // h=360 + const red2 = new Color('hsl(360, 100%, 50%)'); + + `${grey}`.should.eql('#7d7d7d'); + `${red1}`.should.eql('#f00'); + `${red2}`.should.eql('#f00'); + }); + + it('invalid color', () => { + let color; + try { + color = new Color(200); + } catch (e) { + e.message.should.eql('color is required!'); + } + try { + color = new Color('rgb(300, 130, 180)'); + } catch (e) { + e.message.should.eql('{r: 300, g: 130, b: 180, a: 1} is invalid.'); + } + try { + color = new Color('cmyk(0%,0%,0%,0%)'); + } catch (e) { + e.message.should.eql('cmyk(0%,0%,0%,0%) is not a supported color format.'); + } + (typeof color).should.eql('undefined'); }); + + it('mix()', () => { + const red = new Color('red'); + const pink = new Color('pink'); + const mid1 = red.mix(pink, 0); + const mid2 = red.mix(pink, 1); + + `${mid1}`.should.eql('#f00'); + `${mid2}`.should.eql('#ffc0cb'); + + try { + red.mix(pink, 2); + } catch (e) { + e.message.should.eql('Valid numbers is only between 0 and 1.'); + } + }); + }); diff --git a/test/decode_url.spec.js b/test/decode_url.spec.js index f3fa942..d6bc3c3 100644 --- a/test/decode_url.spec.js +++ b/test/decode_url.spec.js @@ -84,4 +84,9 @@ describe('decodeURL', () => { const content = '#f%C3%B3o-b%C3%A1r'; decodeURL(content).should.eql('#fóo-bár'); }); + + it('data url', () => { + const content = 'data:image/png;base64'; + decodeURL(content).should.eql('data:image/png;base64'); + }); }); diff --git a/test/is_external_link.spec.js b/test/is_external_link.spec.js index d72e0a0..2b06821 100644 --- a/test/is_external_link.spec.js +++ b/test/is_external_link.spec.js @@ -56,4 +56,11 @@ describe('isExternalLink', () => { isExternalLink('https://bar.com/', ctx.config.url, ctx.config.external_link.exclude).should.eql(false); isExternalLink('https://baz.com/', ctx.config.url, ctx.config.external_link.exclude).should.eql(true); }); + + it('invalid sitehost', () => { + ctx.config.url = ''; + isExternalLink('https://localhost:4000', ctx.config.url).should.eql(false); + ctx.config.url = 'https://example.com'; + }); + }); diff --git a/test/pattern.spec.js b/test/pattern.spec.js index f3c8476..75fa3d5 100644 --- a/test/pattern.spec.js +++ b/test/pattern.spec.js @@ -59,10 +59,23 @@ describe('Pattern', () => { pattern.match('foo').should.eql({}); }); + it('Pattern', () => { + const pattern = new Pattern('posts/:id'); + new Pattern(pattern).should.eql(pattern); + }); + it('rule is required', () => { (() => { // eslint-disable-next-line no-new new Pattern(); }).should.throw('rule must be a function, a string or a regular expression.'); }); + + it('test function', () => { + const pattern = new Pattern('posts/:id'); + + pattern.test('/posts/89').should.eql(true); + pattern.test('/post/89').should.eql(false); + }); + }); diff --git a/test/permalink.spec.js b/test/permalink.spec.js index b84d14a..d30b5db 100644 --- a/test/permalink.spec.js +++ b/test/permalink.spec.js @@ -19,6 +19,18 @@ describe('Permalink', () => { permalink.regex.should.eql(/^(.+?)_(.+?)_(.+?)_(.+?)$/); permalink.params.should.eql(['year', 'i_month', 'i_day', 'title']); + permalink = new Permalink(':year/:month/:day/:title', { + segments: { + year: '(\\d{4})', + month: '(\\d{2})', + day: '(\\d{2})' + } + }); + + permalink.rule.should.eql(':year/:month/:day/:title'); + permalink.regex.should.eql(/^(\d{4})\/(\d{2})\/(\d{2})\/(.+?)$/); + permalink.params.should.eql(['year', 'month', 'day', 'title']); + permalink = new Permalink(':year/:month/:day/:title', { segments: { year: /(\d{4})/, @@ -53,6 +65,7 @@ describe('Permalink', () => { day: '31', title: 'test' }); + (typeof permalink.parse('test')).should.eql('undefined'); }); it('stringify()', () => { diff --git a/test/spawn.spec.js b/test/spawn.spec.js index 372f805..0a6476b 100644 --- a/test/spawn.spec.js +++ b/test/spawn.spec.js @@ -115,4 +115,11 @@ describe('spawn', () => { }); it('stdio = inherit', () => spawn('echo', ['something'], { stdio: 'inherit' })); + + it('exit with code', () => { + if (isWindows) { + return spawn('cmd.exe', ['/c', 'exit', '1'], { stdio: 'inherit' }).should.rejectedWith('Spawn failed'); + } + return spawn('sh', ['/c', 'exit', '1'], { stdio: 'inherit' }).should.rejectedWith('Spawn failed'); + }); }); diff --git a/test/strip_indent.spec.js b/test/strip_indent.spec.js new file mode 100644 index 0000000..90d3065 --- /dev/null +++ b/test/strip_indent.spec.js @@ -0,0 +1,11 @@ +'use strict'; + +const stripIndent = require('../dist/strip_indent'); + +describe('stripIndent', () => { + it('default', () => { + const text = '\tunicorn\n\t\tcake'; + + stripIndent(text).should.eql('unicorn\n\tcake'); + }); +});