|
9 | 9 | addAndMergeAxesRange, |
10 | 10 | fetchAllCSS, |
11 | 11 | generateCSSLinks, |
| 12 | + parseCSS, |
12 | 13 | parseVariable, |
13 | 14 | sortAxes, |
14 | 15 | } from '../src/variable-parser'; |
@@ -233,6 +234,105 @@ describe('Variable Parser', () => { |
233 | 234 | }); |
234 | 235 | }); |
235 | 236 |
|
| 237 | + describe('Parse CSS with numbered subsets', () => { |
| 238 | + it('Handles numbered subsets without comments (new format)', () => { |
| 239 | + // Mock CSS data that mimics the new Google Fonts format without comments |
| 240 | + // but with numbered subsets in the URL filenames |
| 241 | + const cssWithoutComments: string[][] = [ |
| 242 | + [ |
| 243 | + 'wght.normal', |
| 244 | + `@font-face { |
| 245 | + font-family: 'Noto Sans JP Variable'; |
| 246 | + font-style: normal; |
| 247 | + font-weight: 100 900; |
| 248 | + src: url(https://fonts.gstatic.com/s/notosansjp/v55/variable-font.0.woff2) format('woff2'); |
| 249 | +} |
| 250 | +@font-face { |
| 251 | + font-family: 'Noto Sans JP Variable'; |
| 252 | + font-style: normal; |
| 253 | + font-weight: 100 900; |
| 254 | + src: url(https://fonts.gstatic.com/s/notosansjp/v55/variable-font.1.woff2) format('woff2'); |
| 255 | +} |
| 256 | +@font-face { |
| 257 | + font-family: 'Noto Sans JP Variable'; |
| 258 | + font-style: normal; |
| 259 | + font-weight: 100 900; |
| 260 | + src: url(https://fonts.gstatic.com/s/notosansjp/v55/variable-font.119.woff2) format('woff2'); |
| 261 | +}`, |
| 262 | + ], |
| 263 | + ]; |
| 264 | + |
| 265 | + const result = parseCSS(cssWithoutComments); |
| 266 | + |
| 267 | + // Should extract numbered subsets from URLs: [0], [1], and [119] |
| 268 | + expect(result.wght.normal['[0]']).toBe( |
| 269 | + 'https://fonts.gstatic.com/s/notosansjp/v55/variable-font.0.woff2', |
| 270 | + ); |
| 271 | + expect(result.wght.normal['[1]']).toBe( |
| 272 | + 'https://fonts.gstatic.com/s/notosansjp/v55/variable-font.1.woff2', |
| 273 | + ); |
| 274 | + expect(result.wght.normal['[119]']).toBe( |
| 275 | + 'https://fonts.gstatic.com/s/notosansjp/v55/variable-font.119.woff2', |
| 276 | + ); |
| 277 | + }); |
| 278 | + |
| 279 | + it('Handles numbered subsets with comments (old format)', () => { |
| 280 | + // Mock CSS data with comments (old format) |
| 281 | + const cssWithComments: string[][] = [ |
| 282 | + [ |
| 283 | + 'wght.normal', |
| 284 | + `/* [0] */ |
| 285 | +@font-face { |
| 286 | + font-family: 'Noto Sans JP Variable'; |
| 287 | + font-style: normal; |
| 288 | + font-weight: 100 900; |
| 289 | + src: url(https://fonts.gstatic.com/s/notosansjp/v55/variable-font.0.woff2) format('woff2'); |
| 290 | +} |
| 291 | +/* [1] */ |
| 292 | +@font-face { |
| 293 | + font-family: 'Noto Sans JP Variable'; |
| 294 | + font-style: normal; |
| 295 | + font-weight: 100 900; |
| 296 | + src: url(https://fonts.gstatic.com/s/notosansjp/v55/variable-font.1.woff2) format('woff2'); |
| 297 | +}`, |
| 298 | + ], |
| 299 | + ]; |
| 300 | + |
| 301 | + const result = parseCSS(cssWithComments); |
| 302 | + |
| 303 | + // Should use comment-based subset names [0] and [1] |
| 304 | + expect(result.wght.normal['[0]']).toBe( |
| 305 | + 'https://fonts.gstatic.com/s/notosansjp/v55/variable-font.0.woff2', |
| 306 | + ); |
| 307 | + expect(result.wght.normal['[1]']).toBe( |
| 308 | + 'https://fonts.gstatic.com/s/notosansjp/v55/variable-font.1.woff2', |
| 309 | + ); |
| 310 | + }); |
| 311 | + |
| 312 | + it('Falls back to default subset for non-numbered URLs', () => { |
| 313 | + // Mock CSS data with regular URLs (no numbered pattern) |
| 314 | + const cssRegular: string[][] = [ |
| 315 | + [ |
| 316 | + 'wght.normal', |
| 317 | + `/* latin */ |
| 318 | +@font-face { |
| 319 | + font-family: 'Roboto Flex'; |
| 320 | + font-style: normal; |
| 321 | + font-weight: 100 1000; |
| 322 | + src: url(https://fonts.gstatic.com/s/robotoflex/v30/regular.woff2) format('woff2'); |
| 323 | +}`, |
| 324 | + ], |
| 325 | + ]; |
| 326 | + |
| 327 | + const result = parseCSS(cssRegular); |
| 328 | + |
| 329 | + // Should use comment-based subset name 'latin' |
| 330 | + expect(result.wght.normal.latin).toBe( |
| 331 | + 'https://fonts.gstatic.com/s/robotoflex/v30/regular.woff2', |
| 332 | + ); |
| 333 | + }); |
| 334 | + }); |
| 335 | + |
236 | 336 | describe('Full parse and order', () => { |
237 | 337 | it('Parses successfully', async () => { |
238 | 338 | await parseVariable(false); |
|
0 commit comments