UNPKG

1.17 kBJavaScriptView Raw
1/* global describe, it */
2describe('print names', () => {
3 const printNames = require('./print-names')
4
5 function isString (s) {
6 return typeof s === 'string'
7 }
8
9 function singleLine (s) {
10 return isString(s) &&
11 s.indexOf('\n') === -1
12 }
13
14 function singleComma (s) {
15 return isString(s) &&
16 s.split(',').length === 2
17 }
18
19 function joinArguments () {
20 return Array.prototype.join.call(arguments, ' ')
21 }
22
23 it('prints few labels in single line', () => {
24 function checkOutput () {
25 const str = joinArguments.apply(null, arguments)
26 console.assert(singleLine(str), str)
27 }
28 printNames('few', ['foo', 'bar'], checkOutput)
29 })
30
31 it('only has single comma', () => {
32 function checkOutput () {
33 const str = joinArguments.apply(null, arguments)
34 console.assert(singleComma(str), str)
35 }
36 printNames('few', ['foo', 'bar'], checkOutput)
37 })
38
39 it('prints many labels on separate lines', () => {
40 function checkOutput () {
41 const str = joinArguments.apply(null, arguments)
42 console.assert(!singleLine(str), str)
43 }
44 printNames('many', ['a', 'b', 'c', 'd', 'e', 'f'], checkOutput)
45 })
46})