File tree Expand file tree Collapse file tree 1 file changed +40
-23
lines changed
crates/crates_io_database/tests Expand file tree Collapse file tree 1 file changed +40
-23
lines changed Original file line number Diff line number Diff line change @@ -51,24 +51,6 @@ async fn test_spec_order() {
5151 let test_db = TestDatabase :: new ( ) ;
5252 let mut conn = test_db. async_connect ( ) . await ;
5353
54- let query = r#"
55- with nums as (
56- select unnest(array[
57- '1.0.0-beta',
58- '1.0.0-alpha',
59- '1.0.0-rc.1',
60- '1.0.0',
61- '1.0.0-beta.2',
62- '1.0.0-alpha.1',
63- '1.0.0-alpha.beta',
64- '1.0.0-beta.11'
65- ]) as num
66- )
67- select num
68- from nums
69- order by semver_ord(num);
70- "# ;
71-
7254 #[ derive( QueryableByName ) ]
7355 struct Row {
7456 #[ diesel( sql_type = Text ) ]
@@ -81,12 +63,34 @@ async fn test_spec_order() {
8163 }
8264 }
8365
84- let nums = diesel:: sql_query ( query)
85- . load :: < Row > ( & mut conn)
86- . await
87- . unwrap ( ) ;
66+ let mut check = async |order| {
67+ let query = format ! (
68+ r#"
69+ with nums as (
70+ select unnest(array[
71+ '1.0.0-beta',
72+ '1.0.0-alpha',
73+ '1.0.0-rc.1',
74+ '1.0.0',
75+ '1.0.0-beta.2',
76+ '1.0.0-alpha.1',
77+ '1.0.0-alpha.beta',
78+ '1.0.0-beta.11'
79+ ]) as num
80+ )
81+ select num
82+ from nums
83+ order by semver_ord(num) {order};
84+ "#
85+ ) ;
8886
89- insta:: assert_debug_snapshot!( nums, @r"
87+ diesel:: sql_query ( query)
88+ . load :: < Row > ( & mut conn)
89+ . await
90+ . unwrap ( )
91+ } ;
92+
93+ insta:: assert_debug_snapshot!( check( "asc" ) . await , @r"
9094 [
9195 1.0.0-alpha,
9296 1.0.0-alpha.1,
@@ -98,4 +102,17 @@ async fn test_spec_order() {
98102 1.0.0,
99103 ]
100104 " ) ;
105+
106+ insta:: assert_debug_snapshot!( check( "desc" ) . await , @r"
107+ [
108+ 1.0.0,
109+ 1.0.0-rc.1,
110+ 1.0.0-beta.11,
111+ 1.0.0-beta.2,
112+ 1.0.0-beta,
113+ 1.0.0-alpha.beta,
114+ 1.0.0-alpha.1,
115+ 1.0.0-alpha,
116+ ]
117+ " ) ;
101118}
You can’t perform that action at this time.
0 commit comments