feat: added support for adding plurality to ingredients

This commit is contained in:
Leyla Becker 2026-02-22 19:53:18 -06:00
parent 750bfb912f
commit 8855d6ba19
9 changed files with 468 additions and 8 deletions

View file

@ -518,4 +518,98 @@ describe('density with approximate values', () => {
expect(weightAttrs.length).toBe(1);
expect(weightAttrs[0].weightDefault).toMatch(/^~/);
});
});
// ─── Count Noun Pluralization ───────────────────────────────
describe('count noun pluralization', () => {
it('generates noun span for known singular noun', () => {
const html = render('- onion 1');
expect(html).toContain('class="count-noun"');
expect(html).toContain('data-singular="onion"');
expect(html).toContain('data-plural="onions"');
});
it('generates noun span for known plural noun', () => {
const html = render('- eggs 3');
expect(html).toContain('class="count-noun"');
expect(html).toContain('data-singular="egg"');
expect(html).toContain('data-plural="eggs"');
});
it('displays singular form when count is 1', () => {
const html = render('- onion 1');
expect(html).toMatch(/<span class="count-noun"[^>]*>onion<\/span>/);
});
it('displays plural form when count is not 1', () => {
const html = render('- egg 3');
expect(html).toMatch(/<span class="count-noun"[^>]*>eggs<\/span>/);
});
it('displays plural form when count is 0', () => {
const html = render('- egg 0');
expect(html).toMatch(/<span class="count-noun"[^>]*>eggs<\/span>/);
});
it('uses max value for ranges (plural)', () => {
const html = render('- onion 1-2');
// max value is 2 -> plural
expect(html).toMatch(/<span class="count-noun"[^>]*>onions<\/span>/);
});
it('adds data-has-noun on the count measurement span', () => {
const html = render('- onion 1');
expect(html).toContain('data-has-noun="true"');
});
it('does not add data-has-noun for unknown nouns', () => {
const html = render('- toaster 1');
expect(html).not.toContain('data-has-noun');
expect(html).not.toContain('count-noun');
});
it('handles multi-word nouns like bell pepper', () => {
const html = render('- bell pepper 2');
expect(html).toContain('data-singular="bell pepper"');
expect(html).toContain('data-plural="bell peppers"');
expect(html).toMatch(/<span class="count-noun"[^>]*>bell peppers<\/span>/);
});
it('handles multi-word nouns like egg yolk', () => {
const html = render('- egg yolk 1');
expect(html).toContain('data-singular="egg yolk"');
expect(html).toMatch(/<span class="count-noun"[^>]*>egg yolk<\/span>/);
});
it('corrects plural to singular for count 1', () => {
const html = render('- eggs 1');
expect(html).toMatch(/<span class="count-noun"[^>]*>egg<\/span>/);
});
it('corrects singular to plural for count > 1', () => {
const html = render('- onion 4');
expect(html).toMatch(/<span class="count-noun"[^>]*>onions<\/span>/);
});
it('works in tools section', () => {
const md = [
'## Ingredients',
'- egg 2',
].join('\n');
const html = render(md);
expect(html).toContain('class="count-noun"');
expect(html).toMatch(/<span class="count-noun"[^>]*>eggs<\/span>/);
});
it('preserves text before the noun', () => {
const html = render('- white onion 1');
// "white " should appear before the noun span
expect(html).toMatch(/white <span class="count-noun"/);
});
it('does not generate noun span for non-count measurements', () => {
const html = render('- onion 200g');
expect(html).not.toContain('count-noun');
});
});