1- //------------------------------------------------------------
2- // Copyright (c) Microsoft Corporation. All rights reserved.
3- //------------------------------------------------------------
4-
5- namespace Microsoft . Azure . Cosmos . Tests . Query . Parser
6- {
7- using System . Collections . Generic ;
8- using Microsoft . VisualStudio . TestTools . UnitTesting ;
9-
10- [ TestClass ]
11- public sealed class OrderByClauseSqlParserBaselineTests : SqlParserBaselineTests
12- {
13- [ TestMethod ]
14- public void SingleOrderBy ( )
15- {
16- List < SqlParserBaselineTestInput > inputs = new List < SqlParserBaselineTestInput > ( )
17- {
18- // Positive
19- CreateInput ( description : "Basic" , orderByClause : "ORDER BY 1" ) ,
20- CreateInput ( description : "Ascending" , orderByClause : "ORDER BY 1 asc" ) ,
21- CreateInput ( description : "Multi Item Array" , orderByClause : "ORDER BY 1 DESC" ) ,
22- CreateInput ( description : "Case Insensitive" , orderByClause : "OrDeR By 1 DeSc" ) ,
23-
24- // Negative
25- CreateInput ( description : "No spaces" , orderByClause : "ORDERBY 1" ) ,
26- CreateInput ( description : "Wrong Keyword" , orderByClause : "ORER BY 1" ) ,
27- } ;
28-
29- this . ExecuteTestSuite ( inputs ) ;
30- }
31-
32- [ TestMethod ]
33- public void MultiOrderBy ( )
34- {
35- List < SqlParserBaselineTestInput > inputs = new List < SqlParserBaselineTestInput > ( )
36- {
37- // Positive
38- CreateInput ( description : "Basic" , orderByClause : "ORDER BY 1, 2, 3" ) ,
39- CreateInput ( description : "Only one sort order" , orderByClause : "ORDER BY 1, 2 DESC, 3" ) ,
40- CreateInput ( description : "All sort order" , orderByClause : "ORDER BY 1 ASC, 2 DESC, 3 ASC" ) ,
41-
42- // Negative
43- CreateInput ( description : "Trailing comma" , orderByClause : "ORDER BY 1 ASC," ) ,
44- } ;
45-
46- this . ExecuteTestSuite ( inputs ) ;
47- }
48-
49- public static SqlParserBaselineTestInput CreateInput ( string description , string orderByClause )
50- {
51- return new SqlParserBaselineTestInput ( description , $ "SELECT * { orderByClause } ") ;
52- }
53- }
1+ //------------------------------------------------------------
2+ // Copyright (c) Microsoft Corporation. All rights reserved.
3+ //------------------------------------------------------------
4+
5+ namespace Microsoft . Azure . Cosmos . Tests . Query . Parser
6+ {
7+ using System . Collections . Generic ;
8+ using Microsoft . VisualStudio . TestTools . UnitTesting ;
9+
10+ [ TestClass ]
11+ public sealed class OrderByClauseSqlParserBaselineTests : SqlParserBaselineTests
12+ {
13+ [ TestMethod ]
14+ public void SingleOrderBy ( )
15+ {
16+ List < SqlParserBaselineTestInput > inputs = new List < SqlParserBaselineTestInput > ( )
17+ {
18+ // Positive
19+ CreateInput ( description : "Basic" , orderByClause : "ORDER BY 1" ) ,
20+ CreateInput ( description : "Ascending" , orderByClause : "ORDER BY 1 asc" ) ,
21+ CreateInput ( description : "Multi Item Array" , orderByClause : "ORDER BY 1 DESC" ) ,
22+ CreateInput ( description : "Case Insensitive" , orderByClause : "OrDeR By 1 DeSc" ) ,
23+
24+ // Negative
25+ CreateInput ( description : "No spaces" , orderByClause : "ORDERBY 1" ) ,
26+ CreateInput ( description : "Wrong Keyword" , orderByClause : "ORER BY 1" ) ,
27+ } ;
28+
29+ this . ExecuteTestSuite ( inputs ) ;
30+ }
31+
32+ [ TestMethod ]
33+ public void MultiOrderBy ( )
34+ {
35+ List < SqlParserBaselineTestInput > inputs = new List < SqlParserBaselineTestInput > ( )
36+ {
37+ // Positive
38+ CreateInput ( description : "Basic" , orderByClause : "ORDER BY 1, 2, 3" ) ,
39+ CreateInput ( description : "Only one sort order" , orderByClause : "ORDER BY 1, 2 DESC, 3" ) ,
40+ CreateInput ( description : "All sort order" , orderByClause : "ORDER BY 1 ASC, 2 DESC, 3 ASC" ) ,
41+
42+ // Negative
43+ CreateInput ( description : "Trailing comma" , orderByClause : "ORDER BY 1 ASC," ) ,
44+ } ;
45+
46+ this . ExecuteTestSuite ( inputs ) ;
47+ }
48+
49+ [ TestMethod ]
50+ public void SingleOrderByRank ( )
51+ {
52+ List < SqlParserBaselineTestInput > inputs = new List < SqlParserBaselineTestInput > ( )
53+ {
54+ // Positive
55+ CreateInput ( description : "Basic" , orderByClause : "ORDER BY RANK FullTextScore(c.text, [\" keyword\" ])" ) ,
56+ CreateInput ( description : "Ascending" , orderByClause : "ORDER BY RANK FullTextScore(c.text, [\" keyword\" ]) ASC" ) ,
57+ CreateInput ( description : "Descending" , orderByClause : "ORDER BY RANK FullTextScore(c.text, [\" keyword\" ]) DESC" ) ,
58+ CreateInput ( description : "Case Insensitive" , orderByClause : "OrDeR By rANk FullTextScore(c.text, [\" keyword\" ]) DeSc" ) ,
59+
60+ // Negative
61+ CreateInput ( description : "No spaces" , orderByClause : "ORDERBYRANK FullTextScore(c.text, [\" keyword\" ])" ) ,
62+ CreateInput ( description : "Wrong Keyword" , orderByClause : "ORDER BY RANKS FullTextScore(c.text, [\" keyword\" ])" ) ,
63+ CreateInput ( description : "Not a function call" , orderByClause : "ORDER BY RANK 1" )
64+ } ;
65+
66+ this . ExecuteTestSuite ( inputs ) ;
67+ }
68+
69+ [ TestMethod ]
70+ public void MultiOrderByRank ( )
71+ {
72+ List < SqlParserBaselineTestInput > inputs = new List < SqlParserBaselineTestInput > ( )
73+ {
74+ // Positive
75+ CreateInput ( description : "Basic" , orderByClause : "ORDER BY RANK FullTextScore(c.text, [\" keyword\" ]), FullTextScore(c.text2, [\" keyword\" ]), FullTextScore(c.text3, [\" keyword\" ])" ) ,
76+ CreateInput ( description : "Only one sort order" , orderByClause : "ORDER BY RANK FullTextScore(c.text, [\" keyword\" ]) ASC, FullTextScore(c.text2, [\" keyword\" ]) ASC, FullTextScore(c.text3, [\" keyword\" ]) ASC" ) ,
77+ CreateInput ( description : "All sort order" , orderByClause : "ORDER BY RANK FullTextScore(c.text, [\" keyword\" ]) ASC, FullTextScore(c.text2, [\" keyword\" ]) DESC, FullTextScore(c.text3, [\" keyword\" ]) ASC" ) ,
78+
79+ // Negative
80+ CreateInput ( description : "Trailing comma" , orderByClause : "ORDER BY RANK FullTextScore(c.text, [\" keyword\" ]) ASC," ) ,
81+ CreateInput ( description : "All fields not function call" , orderByClause : "ORDER BY RANK 1, 2, 3" ) ,
82+ CreateInput ( description : "Some fields not function call" , orderByClause : "ORDER BY RANK RANK FullTextScore(c.text, [\" keyword\" ]) ASC, 2, 3 ASC" )
83+ } ;
84+
85+ this . ExecuteTestSuite ( inputs ) ;
86+ }
87+
88+ public static SqlParserBaselineTestInput CreateInput ( string description , string orderByClause )
89+ {
90+ return new SqlParserBaselineTestInput ( description , $ "SELECT * { orderByClause } ") ;
91+ }
92+ }
5493}
0 commit comments