1+ import { toFixed } from "../src/format" ;
2+ import { ENUM_PINYIN_STYLE } from "../src/constant" ;
3+
4+ describe . only ( "toFixed function" , ( ) => {
5+ test ( "should return initials for ENUM_PINYIN_STYLE.INITIALS" , ( ) => {
6+ expect ( toFixed ( "zhong" , ENUM_PINYIN_STYLE . INITIALS ) ) . toBe ( "zh" ) ;
7+ expect ( toFixed ( "guo" , ENUM_PINYIN_STYLE . INITIALS ) ) . toBe ( "g" ) ;
8+ } ) ;
9+
10+ test ( "should return first letter for ENUM_PINYIN_STYLE.FIRST_LETTER" , ( ) => {
11+ expect ( toFixed ( "zhong" , ENUM_PINYIN_STYLE . FIRST_LETTER ) ) . toBe ( "z" ) ;
12+ expect ( toFixed ( "guo" , ENUM_PINYIN_STYLE . FIRST_LETTER ) ) . toBe ( "g" ) ;
13+ } ) ;
14+
15+ test ( "should return normal style for ENUM_PINYIN_STYLE.NORMAL" , ( ) => {
16+ expect ( toFixed ( "zhōng" , ENUM_PINYIN_STYLE . NORMAL ) ) . toBe ( "zhong" ) ;
17+ expect ( toFixed ( "guó" , ENUM_PINYIN_STYLE . NORMAL ) ) . toBe ( "guo" ) ;
18+ } ) ;
19+
20+ test ( "should return passport style for ENUM_PINYIN_STYLE.PASSPORT" , ( ) => {
21+ expect ( toFixed ( "lǜ" , ENUM_PINYIN_STYLE . PASSPORT ) ) . toBe ( "LYU" ) ;
22+ expect ( toFixed ( "nǚ" , ENUM_PINYIN_STYLE . PASSPORT ) ) . toBe ( "NYU" ) ;
23+ expect ( toFixed ( "lüe" , ENUM_PINYIN_STYLE . PASSPORT ) ) . toBe ( "LUE" ) ;
24+ } ) ;
25+
26+ test ( "should return tone3 style for ENUM_PINYIN_STYLE.TO3NE" , ( ) => {
27+ expect ( toFixed ( "zhōng" , ENUM_PINYIN_STYLE . TO3NE ) ) . toBe ( "zho1ng" ) ;
28+ expect ( toFixed ( "guó" , ENUM_PINYIN_STYLE . TO3NE ) ) . toBe ( "guo2" ) ;
29+ } ) ;
30+
31+ test ( "should return tone2 style for ENUM_PINYIN_STYLE.TONE2" , ( ) => {
32+ expect ( toFixed ( "zhōng" , ENUM_PINYIN_STYLE . TONE2 ) ) . toBe ( "zhong1" ) ;
33+ expect ( toFixed ( "guó" , ENUM_PINYIN_STYLE . TONE2 ) ) . toBe ( "guo2" ) ;
34+ } ) ;
35+
36+ test ( "should return tone style for ENUM_PINYIN_STYLE.TONE" , ( ) => {
37+ expect ( toFixed ( "zhōng" , ENUM_PINYIN_STYLE . TONE ) ) . toBe ( "zhōng" ) ;
38+ expect ( toFixed ( "guó" , ENUM_PINYIN_STYLE . TONE ) ) . toBe ( "guó" ) ;
39+ } ) ;
40+
41+ test ( "should return original pinyin for unknown style" , ( ) => {
42+ expect ( toFixed ( "zhong" , - 1 ) ) . toBe ( "zhong" ) ;
43+ } ) ;
44+ } ) ;
0 commit comments