|
| 1 | +import { formatFlags } from './formatting-utils'; |
| 2 | + |
| 3 | +describe('formatFlags', () => { |
| 4 | + it('should properly show string values', () => { |
| 5 | + expect(formatFlags('', 'myflag', 'myvalue')).toBe(' --myflag=myvalue'); |
| 6 | + }); |
| 7 | + it('should properly show number values', () => { |
| 8 | + expect(formatFlags('', 'myflag', 123)).toBe(' --myflag=123'); |
| 9 | + }); |
| 10 | + it('should properly show boolean values', () => { |
| 11 | + expect(formatFlags('', 'myflag', true)).toBe(' --myflag=true'); |
| 12 | + }); |
| 13 | + it('should properly show array values', () => { |
| 14 | + expect(formatFlags('', 'myflag', [1, 23, 'abc'])).toBe( |
| 15 | + ' --myflag=[1,23,abc]' |
| 16 | + ); |
| 17 | + }); |
| 18 | + it('should properly show object values', () => { |
| 19 | + expect(formatFlags('', 'myflag', { abc: 'def', ghi: { jkl: 42 } })).toBe( |
| 20 | + ' --myflag={"abc":"def","ghi":{"jkl":42}}' |
| 21 | + ); |
| 22 | + }); |
| 23 | + it('should not break on invalid inputs', () => { |
| 24 | + expect(formatFlags('', 'myflag', (abc) => abc)).toBe( |
| 25 | + ' --myflag=(abc) => abc' |
| 26 | + ); |
| 27 | + expect(formatFlags('', 'myflag', NaN)).toBe(' --myflag=NaN'); |
| 28 | + }); |
| 29 | + it('should decompose positional values', () => { |
| 30 | + expect(formatFlags('', '_', ['foo', 'bar', 42, 'baz'])).toBe( |
| 31 | + ' foo bar 42 baz' |
| 32 | + ); |
| 33 | + }); |
| 34 | + it('should handle indentation', () => { |
| 35 | + expect(formatFlags('_____', 'myflag', 'myvalue')).toBe( |
| 36 | + '_____ --myflag=myvalue' |
| 37 | + ); |
| 38 | + }); |
| 39 | + it('should handle indentation with positionals', () => { |
| 40 | + expect(formatFlags('_____', '_', ['foo', 'bar', 42, 'baz'])).toBe( |
| 41 | + '_____ foo bar 42 baz' |
| 42 | + ); |
| 43 | + }); |
| 44 | +}); |
0 commit comments