|
| 1 | +import { describe, expect, it } from 'vitest'; |
| 2 | +import { parseAddonOptions } from '../utils/common.ts'; |
| 3 | + |
| 4 | +describe('parseAddonOptions', () => { |
| 5 | + it('returns undefined on undefined', () => { |
| 6 | + expect(parseAddonOptions(undefined)).toEqual(undefined); |
| 7 | + }); |
| 8 | + it('returns undefined on empty string', () => { |
| 9 | + expect(parseAddonOptions('')).toEqual(undefined); |
| 10 | + }); |
| 11 | + it('parses options and values', () => { |
| 12 | + expect(parseAddonOptions('option:value')).toEqual(['option:value']); |
| 13 | + }); |
| 14 | + it('parses values with empty strings', () => { |
| 15 | + expect(parseAddonOptions('foo:')).toEqual(['foo:']); |
| 16 | + expect(parseAddonOptions('foo:+bar:+baz:')).toEqual(['foo:', 'bar:', 'baz:']); |
| 17 | + }); |
| 18 | + it('parses sentences', () => { |
| 19 | + expect(parseAddonOptions('foo:the quick brown fox')).toEqual(['foo:the quick brown fox']); |
| 20 | + }); |
| 21 | + it('parses lists', () => { |
| 22 | + expect(parseAddonOptions('foo:en,es,de')).toEqual(['foo:en,es,de']); |
| 23 | + }); |
| 24 | + it('parses values with colons', () => { |
| 25 | + expect(parseAddonOptions('option:foo:bar:baz')).toEqual(['option:foo:bar:baz']); |
| 26 | + }); |
| 27 | + it('errors on missing value', () => { |
| 28 | + expect(() => parseAddonOptions('foo')).toThrowError( |
| 29 | + "Malformed arguments: The following add-on options: 'foo' are missing their option name or value (e.g. 'addon=option1:value1+option2:value2')." |
| 30 | + ); |
| 31 | + }); |
| 32 | + it('errors when one of two options is missing a value', () => { |
| 33 | + expect(() => parseAddonOptions('foo:value1+bar')).toThrowError( |
| 34 | + "Malformed arguments: The following add-on options: 'bar' are missing their option name or value (e.g. 'addon=option1:value1+option2:value2')." |
| 35 | + ); |
| 36 | + }); |
| 37 | + it('errors on two missing values', () => { |
| 38 | + expect(() => parseAddonOptions('foo+bar')).toThrowError( |
| 39 | + "Malformed arguments: The following add-on options: 'foo', 'bar' are missing their option name or value (e.g. 'addon=option1:value1+option2:value2')." |
| 40 | + ); |
| 41 | + }); |
| 42 | +}); |
0 commit comments