import { describe, expect, it } from 'vitest' import { figures } from './figure' import { region } from './money' /** * Where the corner's flag is found, and what the list writes beside each code. * * The flag key is the one thing a build has to agree with this control about. * Get it wrong and nothing fails: the corner draws regional indicators for * every currency and looks like a deliberate choice. */ describe('the region a currency belongs to', () => { it('is the ISO 3166 region ISO 4217 built the code out of', () => { expect(region('USD')).toBe('US') expect(region('JPY')).toBe('JP') expect(region('GBP')).toBe('GB') }) it('answers for the euro, whose region is the Union', () => { // `EU` is a real ISO 3166 code, so nothing here is a special case. expect(region('EUR')).toBe('EU') }) it('upper-cases, so a code recorded either way lands on one key', () => { expect(region('usd')).toBe(region('USD')) }) }) describe('the symbol beside each code', () => { it('comes out of the same table as the figures the panel draws', () => { // The whole reason the control takes a reading rather than a currency and a // language: a list that wrote `US$` where the figures write `$` would be // two answers to one question. const write = figures({ locale: 'en-US', currency: 'USD' }) expect(write.sign('USD')).toBe('$') expect(write.money(1).startsWith(write.sign('USD'))).toBe(true) }) it('is written in the reader’s language, not the currency’s', () => { // The same currency, two readers. An American writes the yen `¥` and // qualifies the dollar; a Japanese reader does the reverse. const us = figures({ locale: 'en-US', currency: 'USD' }) const jp = figures({ locale: 'ja-JP', currency: 'JPY' }) expect(us.sign('JPY')).toBe('¥') expect(jp.sign('USD')).toBe('$') expect(us.sign('CAD')).not.toBe(us.sign('USD')) }) })