|
| 1 | +/** |
| 2 | + * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | + * |
| 4 | + * This source code is licensed under the MIT license found in the |
| 5 | + * LICENSE file in the root directory of this source tree. |
| 6 | + * |
| 7 | + * @flow strict-local |
| 8 | + * @format |
| 9 | + */ |
| 10 | + |
| 11 | +import '@react-native/fantom/src/setUpDefaultReactNativeEnvironment'; |
| 12 | + |
| 13 | +import processFontVariationSettings from '../processFontVariationSettings'; |
| 14 | + |
| 15 | +describe('processFontVariationSettings', () => { |
| 16 | + it('passes string settings through unchanged', () => { |
| 17 | + expect(processFontVariationSettings("'wght' 550, 'opsz' 18")).toBe( |
| 18 | + "'wght' 550, 'opsz' 18", |
| 19 | + ); |
| 20 | + }); |
| 21 | + |
| 22 | + it('serializes object settings in deterministic axis order', () => { |
| 23 | + expect(processFontVariationSettings({wght: 552.5, opsz: 17.25})).toBe( |
| 24 | + "'opsz' 17.25, 'wght' 552.5", |
| 25 | + ); |
| 26 | + }); |
| 27 | + |
| 28 | + it('serializes an empty object as an explicit clear', () => { |
| 29 | + expect(processFontVariationSettings({})).toBe(''); |
| 30 | + }); |
| 31 | + |
| 32 | + it('supports printable four-character tags containing a single quote', () => { |
| 33 | + expect(processFontVariationSettings({["a'b "]: 1})).toBe('"a\'b " 1'); |
| 34 | + }); |
| 35 | + |
| 36 | + it('preserves backslashes in printable four-character tags', () => { |
| 37 | + expect(processFontVariationSettings({['a\\bc']: 1})).toBe("'a\\bc' 1"); |
| 38 | + }); |
| 39 | + |
| 40 | + it('rejects tags that cannot be delimited without escaping', () => { |
| 41 | + expect(() => processFontVariationSettings({[`a'"b`]: 1})).toThrow( |
| 42 | + 'Font variation axis tags containing both quote characters must use the string form: "a\'\\"b"', |
| 43 | + ); |
| 44 | + }); |
| 45 | + |
| 46 | + it('rejects invalid axis tags', () => { |
| 47 | + expect(() => processFontVariationSettings({weight: 550})).toThrow( |
| 48 | + 'Font variation axis tags must be exactly four printable ASCII characters: "weight"', |
| 49 | + ); |
| 50 | + expect(() => processFontVariationSettings({['a\nbc']: 1})).toThrow( |
| 51 | + 'Font variation axis tags must be exactly four printable ASCII characters: "a\\nbc"', |
| 52 | + ); |
| 53 | + }); |
| 54 | + |
| 55 | + it('rejects non-finite axis values', () => { |
| 56 | + expect(() => processFontVariationSettings({wght: NaN})).toThrow( |
| 57 | + 'Font variation axis values must be finite numbers: NaN', |
| 58 | + ); |
| 59 | + expect(() => processFontVariationSettings({wght: Infinity})).toThrow( |
| 60 | + 'Font variation axis values must be finite numbers: Infinity', |
| 61 | + ); |
| 62 | + }); |
| 63 | +}); |
0 commit comments