Skip to content

Commit

Permalink
fix: shared chunk context
Browse files Browse the repository at this point in the history
  • Loading branch information
kazupon committed Oct 11, 2023
1 parent d6f14b9 commit 844b093
Show file tree
Hide file tree
Showing 2 changed files with 183 additions and 72 deletions.
56 changes: 44 additions & 12 deletions src/locale.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,51 +321,64 @@ test('ParseKeyword', () => {
/**
* Success cases
*/

type t1 = ParseKeyword<['co', 'standard', 'phonetic']>
expectTypeOf<ParseKeyword<['co', 'standard', 'phonetic']>>().toMatchTypeOf<
['co', 'standard-phonetic']
['co', 'standard-phonetic', []]
>()
type t2 = ParseKeyword<['co', 'standard']>
expectTypeOf<ParseKeyword<['co', 'standard']>>().toMatchTypeOf<
['co', 'standard']
['co', 'standard', []]
>()
expectTypeOf<ParseKeyword<['co']>>().toMatchTypeOf<
['co', '']
['co', '', []]
>()

/** Fail cases */
type t3 = ParseKeyword<['c']>
expectTypeOf<ParseKeyword<['c']>>().toMatchTypeOf<
never
[never, ['c']]
>()
})

test('ParseUnicodeExtension', () => {
/**
* Success cases
*/
type t1 = ParseUnicodeExtension<['co', 'standard']>
expectTypeOf<ParseUnicodeExtension<['co', 'standard']>>()
.toMatchTypeOf<
[{ type: 'u'; keywords: ['co', 'standard']; attributes: [] }, never]
[{ type: 'u'; keywords: ['co', 'standard']; attributes: [] }, never, []]
>()
type t2 = ParseUnicodeExtension<['foo', 'bar', 'co', 'standard']>
expectTypeOf<ParseUnicodeExtension<['foo', 'bar', 'co', 'standard']>>()
.toMatchTypeOf<
[
{ type: 'u'; keywords: ['co', 'standard']; attributes: ['foo', 'bar'] },
never,
[],
]
>()

/**
* Fail cases
*/
type t3 = ParseUnicodeExtension<['c']>
expectTypeOf<ParseUnicodeExtension<['c']>>().toMatchTypeOf<
[never, 8]
[
{ type: 'u'; keywords: []; attributes: [] },
never,
['c'],
]
>()
})

test('ParseTransformedExtension', () => {
/**
* Success cases
*/
type t1 = ParseTransformedExtension<
['en', 'Kana', 'US', 'jauer', 'h0', 'hybrid']
>
expectTypeOf<
ParseTransformedExtension<['en', 'Kana', 'US', 'jauer', 'h0', 'hybrid']>
>()
Expand All @@ -382,18 +395,34 @@ test('ParseTransformedExtension', () => {
fields: [['h0', 'hybrid']]
},
never,
[],
]
>()

/**
* Fail cases
*/
type t2 = ParseTransformedExtension<['en', 'US', 'h0']>
expectTypeOf<ParseTransformedExtension<['en', 'US', 'h0']>>()
.toMatchTypeOf<
[never, 10]
[
{
type: 't'
lang: {
lang: 'en'
script: never
region: 'US'
variants: []
}
fields: never
},
10,
['h0'],
]
>()
type t3 = ParseTransformedExtension<['en']>
expectTypeOf<ParseTransformedExtension<['en']>>().toMatchTypeOf<
[never, 11]
[never, 11, ['en']]
>()
})

Expand All @@ -411,6 +440,7 @@ test('ParsePuExtension', () => {
value: '1234-abcde'
},
never,
[],
]
>()

Expand All @@ -425,6 +455,7 @@ test('ParsePuExtension', () => {
[
never,
12,
[''],
]
>()

Expand All @@ -436,6 +467,7 @@ test('ParsePuExtension', () => {
[
never,
12,
['1あ'],
]
>()
})
Expand All @@ -447,7 +479,7 @@ test('ParseOtherExtension', () => {
expectTypeOf<
ParseOtherExtension<['1234', 'abcde']>
>()
.toMatchTypeOf<'1234-abcde'>()
.toMatchTypeOf<['1234-abcde', []]>()

/**
* Fail cases
Expand All @@ -456,11 +488,11 @@ test('ParseOtherExtension', () => {
expectTypeOf<
ParseOtherExtension<['']>
>()
.toMatchTypeOf<''>()
.toMatchTypeOf<['', ['']]>()

// not alphabet or digit
expectTypeOf<
ParseOtherExtension<['1あ']>
>()
.toMatchTypeOf<''>()
.toMatchTypeOf<['', ['1あ']]>()
})
Loading

0 comments on commit 844b093

Please sign in to comment.