Tofu/tests/text/splitIngredientLine.test.js

22 lines
846 B
JavaScript

import test from 'node:test'
import assert from 'node:assert/strict'
import { splitIngredientLine } from '#tofu/tools/text/splitIngredientLine.js'
test('splits on commas and trims each name', () => {
assert.deepEqual(splitIngredientLine('gnocchis, beurre,sauge '), ['gnocchis', 'beurre', 'sauge'])
})
test('drops empty parts', () => {
assert.deepEqual(splitIngredientLine('farine,, , lait,'), ['farine', 'lait'])
})
test('keeps a line without comma as a single name', () => {
assert.deepEqual(splitIngredientLine(' pommes de terre '), ['pommes de terre'])
})
test('returns an empty list for an empty or invalid line', () => {
assert.deepEqual(splitIngredientLine(''), [])
assert.deepEqual(splitIngredientLine(' '), [])
assert.deepEqual(splitIngredientLine(null), [])
assert.deepEqual(splitIngredientLine(undefined), [])
})