@@ -104,6 +104,76 @@ def fn():
104
104
expect ( extractStringEnum ( 'wassup' ) ) . toBe ( null ) ;
105
105
} ) ;
106
106
107
+ it ( 'should error helpfully on invalid value separators' , ( ) => {
108
+ expect ( ( ) => extractStringEnum ( 'Can be `x` sometimes `y' ) )
109
+ . toThrowErrorMatchingInlineSnapshot ( `
110
+ "Unexpected separator token while extracting string enum, expected a comma or "and" or "or" but found "s"
111
+ Context: \`x\` sometimes \`y
112
+ ^"
113
+ ` ) ;
114
+ } ) ;
115
+
116
+ it ( 'should error helpfully on unterminated enum strings' , ( ) => {
117
+ expect ( ( ) => extractStringEnum ( 'Can be `x` or `y' ) ) . toThrowErrorMatchingInlineSnapshot ( `
118
+ "Unexpected early termination of token sequence while extracting string enum, did you forget to close a quote?
119
+ Context: \`x\` or \`y"
120
+ ` ) ;
121
+ } ) ;
122
+
123
+ describe ( 'mixed ticks' , ( ) => {
124
+ it ( 'should extract an enum when mixed quotes are used' , ( ) => {
125
+ const values = extractStringEnum ( 'Can be `x"` or "`y"' ) ! ;
126
+ expect ( values ) . not . toBe ( null ) ;
127
+ expect ( values ) . toHaveLength ( 2 ) ;
128
+ expect ( values [ 0 ] . value ) . toBe ( 'x"' ) ;
129
+ expect ( values [ 1 ] . value ) . toBe ( '`y' ) ;
130
+ } ) ;
131
+ } ) ;
132
+
133
+ describe ( 'deprecated wrappers' , ( ) => {
134
+ it ( 'should handle strikethrough deprecation wrappers' , ( ) => {
135
+ const values = extractStringEnum ( 'Can be `x` or ~~`y`~~' ) ! ;
136
+ expect ( values ) . not . toBe ( null ) ;
137
+ expect ( values ) . toHaveLength ( 2 ) ;
138
+ expect ( values [ 0 ] . value ) . toBe ( 'x' ) ;
139
+ expect ( values [ 1 ] . value ) . toBe ( 'y' ) ;
140
+ } ) ;
141
+ } ) ;
142
+
143
+ describe ( 'lead-in descriptions' , ( ) => {
144
+ it ( 'should handle value lists that smoothly lead in to prose with a comma' , ( ) => {
145
+ const values = extractStringEnum ( 'Can be `x` or `y`, where `x` implies that...' ) ! ;
146
+ expect ( values ) . not . toBe ( null ) ;
147
+ expect ( values ) . toHaveLength ( 2 ) ;
148
+ expect ( values [ 0 ] . value ) . toBe ( 'x' ) ;
149
+ expect ( values [ 1 ] . value ) . toBe ( 'y' ) ;
150
+ } ) ;
151
+
152
+ it ( 'should handle value lists that smoothly lead in to prose with a fullstop' , ( ) => {
153
+ const values = extractStringEnum ( 'Can be `x` or `y`. The `x` value implies that...' ) ! ;
154
+ expect ( values ) . not . toBe ( null ) ;
155
+ expect ( values ) . toHaveLength ( 2 ) ;
156
+ expect ( values [ 0 ] . value ) . toBe ( 'x' ) ;
157
+ expect ( values [ 1 ] . value ) . toBe ( 'y' ) ;
158
+ } ) ;
159
+
160
+ it ( 'should handle value lists that smoothly lead in to prose with a semicolon' , ( ) => {
161
+ const values = extractStringEnum ( 'Can be `x` or `y`; the `x` value implies that...' ) ! ;
162
+ expect ( values ) . not . toBe ( null ) ;
163
+ expect ( values ) . toHaveLength ( 2 ) ;
164
+ expect ( values [ 0 ] . value ) . toBe ( 'x' ) ;
165
+ expect ( values [ 1 ] . value ) . toBe ( 'y' ) ;
166
+ } ) ;
167
+
168
+ it ( 'should handle value lists that smoothly lead in to prose with a hyphen' , ( ) => {
169
+ const values = extractStringEnum ( 'Can be `x` or `y` - the `x` value implies that...' ) ! ;
170
+ expect ( values ) . not . toBe ( null ) ;
171
+ expect ( values ) . toHaveLength ( 2 ) ;
172
+ expect ( values [ 0 ] . value ) . toBe ( 'x' ) ;
173
+ expect ( values [ 1 ] . value ) . toBe ( 'y' ) ;
174
+ } ) ;
175
+ } ) ;
176
+
107
177
describe ( 'with backticks' , ( ) => {
108
178
it ( 'should extract an enum of the format "can be x"' , ( ) => {
109
179
const values = extractStringEnum ( 'Can be `x`' ) ! ;
0 commit comments