@@ -120,69 +120,9 @@ mod __detail {
120120}
121121
122122#[ cfg( test) ]
123- mod tests {
123+ mod column_ref_from_str_tests {
124124 use super :: ColumnRef ;
125- use crate :: query:: querybuilder:: syntax:: column:: __detail:: find_case_insensitive_as;
126-
127- // ------------------------------------------------------------
128- // Tests for find_case_insensitive_as
129- // ------------------------------------------------------------
130- #[ test]
131- fn test_find_as_basic_uppercase ( ) {
132- let idx = find_case_insensitive_as ( "col AS x" ) . unwrap ( ) ;
133- assert_eq ! ( & "col AS x" [ idx..idx + 2 ] , "AS" ) ;
134- }
135-
136- #[ test]
137- fn test_find_as_lowercase ( ) {
138- let idx = find_case_insensitive_as ( "col as x" ) . unwrap ( ) ;
139- assert_eq ! ( & "col as x" [ idx..idx + 2 ] , "as" ) ;
140- }
141-
142- #[ test]
143- fn test_find_as_mixed_case ( ) {
144- let idx = find_case_insensitive_as ( "col As x" ) . unwrap ( ) ;
145- assert_eq ! ( & "col As x" [ idx..idx + 2 ] , "As" ) ;
146- }
147-
148- #[ test]
149- fn test_find_as_with_multiple_spaces ( ) {
150- let idx = find_case_insensitive_as ( "col AS x" ) . unwrap ( ) ;
151- assert_eq ! ( & "col AS x" [ idx..idx + 2 ] , "AS" ) ;
152- }
153-
154- #[ test]
155- fn test_find_as_requires_space_before_and_after ( ) {
156- assert ! ( find_case_insensitive_as( "colASx" ) . is_none( ) ) ;
157- assert ! ( find_case_insensitive_as( "col ASx" ) . is_none( ) ) ;
158- assert ! ( find_case_insensitive_as( "colAS x" ) . is_none( ) ) ;
159- assert ! ( find_case_insensitive_as( "ASx" ) . is_none( ) ) ;
160- assert ! ( find_case_insensitive_as( "xAS" ) . is_none( ) ) ;
161- }
162-
163- #[ test]
164- fn test_find_as_at_start_or_end ( ) {
165- assert ! ( find_case_insensitive_as( " AS x" ) . is_some( ) ) ;
166- assert ! ( find_case_insensitive_as( "x AS " ) . is_some( ) ) ;
167- }
168-
169- #[ test]
170- fn test_find_as_no_match ( ) {
171- assert ! ( find_case_insensitive_as( "column something" ) . is_none( ) ) ;
172- assert ! ( find_case_insensitive_as( "" ) . is_none( ) ) ;
173- assert ! ( find_case_insensitive_as( "a s" ) . is_none( ) ) ;
174- assert ! ( find_case_insensitive_as( "col AX x" ) . is_none( ) ) ;
175- }
176-
177- #[ test]
178- fn test_find_as_with_table_column ( ) {
179- let idx = find_case_insensitive_as ( "table.col as alias" ) . unwrap ( ) ;
180- assert_eq ! ( & "table.col as alias" [ idx..idx + 2 ] , "as" ) ;
181- }
182125
183- // ------------------------------------------------------------
184- // Tests for From<&str> for ColumnRef
185- // ------------------------------------------------------------
186126 #[ test]
187127 fn test_column_ref_simple_column ( ) {
188128 let c = ColumnRef :: from ( "name" ) ;
@@ -287,3 +227,61 @@ mod tests {
287227 assert_eq ! ( c. alias, None ) ;
288228 }
289229}
230+
231+ #[ cfg( test) ]
232+ mod column_ref_alias_as_detection_tests {
233+ use crate :: query:: querybuilder:: syntax:: column:: __detail:: find_case_insensitive_as;
234+
235+ #[ test]
236+ fn test_find_as_basic_uppercase ( ) {
237+ let idx = find_case_insensitive_as ( "col AS x" ) . unwrap ( ) ;
238+ assert_eq ! ( & "col AS x" [ idx..idx + 2 ] , "AS" ) ;
239+ }
240+
241+ #[ test]
242+ fn test_find_as_lowercase ( ) {
243+ let idx = find_case_insensitive_as ( "col as x" ) . unwrap ( ) ;
244+ assert_eq ! ( & "col as x" [ idx..idx + 2 ] , "as" ) ;
245+ }
246+
247+ #[ test]
248+ fn test_find_as_mixed_case ( ) {
249+ let idx = find_case_insensitive_as ( "col As x" ) . unwrap ( ) ;
250+ assert_eq ! ( & "col As x" [ idx..idx + 2 ] , "As" ) ;
251+ }
252+
253+ #[ test]
254+ fn test_find_as_with_multiple_spaces ( ) {
255+ let idx = find_case_insensitive_as ( "col AS x" ) . unwrap ( ) ;
256+ assert_eq ! ( & "col AS x" [ idx..idx + 2 ] , "AS" ) ;
257+ }
258+
259+ #[ test]
260+ fn test_find_as_requires_space_before_and_after ( ) {
261+ assert ! ( find_case_insensitive_as( "colASx" ) . is_none( ) ) ;
262+ assert ! ( find_case_insensitive_as( "col ASx" ) . is_none( ) ) ;
263+ assert ! ( find_case_insensitive_as( "colAS x" ) . is_none( ) ) ;
264+ assert ! ( find_case_insensitive_as( "ASx" ) . is_none( ) ) ;
265+ assert ! ( find_case_insensitive_as( "xAS" ) . is_none( ) ) ;
266+ }
267+
268+ #[ test]
269+ fn test_find_as_at_start_or_end ( ) {
270+ assert ! ( find_case_insensitive_as( " AS x" ) . is_some( ) ) ;
271+ assert ! ( find_case_insensitive_as( "x AS " ) . is_some( ) ) ;
272+ }
273+
274+ #[ test]
275+ fn test_find_as_no_match ( ) {
276+ assert ! ( find_case_insensitive_as( "column something" ) . is_none( ) ) ;
277+ assert ! ( find_case_insensitive_as( "" ) . is_none( ) ) ;
278+ assert ! ( find_case_insensitive_as( "a s" ) . is_none( ) ) ;
279+ assert ! ( find_case_insensitive_as( "col AX x" ) . is_none( ) ) ;
280+ }
281+
282+ #[ test]
283+ fn test_find_as_with_table_column ( ) {
284+ let idx = find_case_insensitive_as ( "table.col as alias" ) . unwrap ( ) ;
285+ assert_eq ! ( & "table.col as alias" [ idx..idx + 2 ] , "as" ) ;
286+ }
287+ }
0 commit comments