2022-10-27 12:23:24 +00:00
mod parse ;
use parse ::Parse ;
2022-12-30 08:23:19 +00:00
use surrealdb ::dbs ::Session ;
use surrealdb ::err ::Error ;
use surrealdb ::kvs ::Datastore ;
2022-10-27 12:23:24 +00:00
use surrealdb ::sql ::Value ;
2023-01-15 09:48:20 +00:00
#[ tokio::test ]
async fn function_array_all ( ) -> Result < ( ) , Error > {
let sql = r #"
RETURN array ::all ( [ ] ) ;
RETURN array ::all ( " some text " ) ;
RETURN array ::all ( [ 1 , 2 , " text " , 3 , NONE , 3 , 4 ] ) ;
" #;
let dbs = Datastore ::new ( " memory " ) . await ? ;
let ses = Session ::for_kv ( ) . with_ns ( " test " ) . with_db ( " test " ) ;
let res = & mut dbs . execute ( & sql , & ses , None , false ) . await ? ;
assert_eq! ( res . len ( ) , 3 ) ;
//
let tmp = res . remove ( 0 ) . result ? ;
2023-04-29 15:58:22 +00:00
let val = Value ::Bool ( true ) ;
2023-01-15 09:48:20 +00:00
assert_eq! ( tmp , val ) ;
//
2023-04-25 10:13:04 +00:00
let tmp = res . remove ( 0 ) . result ;
assert! ( matches! (
tmp . err ( ) ,
Some ( e ) if e . to_string ( ) = = " Incorrect arguments for function array::all(). Argument 1 was the wrong type. Expected a array but failed to convert 'some text' into a array "
) ) ;
2023-01-15 09:48:20 +00:00
//
let tmp = res . remove ( 0 ) . result ? ;
2023-04-29 15:58:22 +00:00
let val = Value ::Bool ( false ) ;
2023-01-15 09:48:20 +00:00
assert_eq! ( tmp , val ) ;
//
Ok ( ( ) )
}
#[ tokio::test ]
async fn function_array_any ( ) -> Result < ( ) , Error > {
let sql = r #"
RETURN array ::any ( [ ] ) ;
RETURN array ::any ( " some text " ) ;
RETURN array ::any ( [ 1 , 2 , " text " , 3 , NONE , 3 , 4 ] ) ;
" #;
let dbs = Datastore ::new ( " memory " ) . await ? ;
let ses = Session ::for_kv ( ) . with_ns ( " test " ) . with_db ( " test " ) ;
let res = & mut dbs . execute ( & sql , & ses , None , false ) . await ? ;
assert_eq! ( res . len ( ) , 3 ) ;
//
let tmp = res . remove ( 0 ) . result ? ;
2023-04-29 15:58:22 +00:00
let val = Value ::Bool ( false ) ;
2023-01-15 09:48:20 +00:00
assert_eq! ( tmp , val ) ;
//
2023-04-25 10:13:04 +00:00
let tmp = res . remove ( 0 ) . result ;
assert! ( matches! (
tmp . err ( ) ,
Some ( e ) if e . to_string ( ) = = " Incorrect arguments for function array::any(). Argument 1 was the wrong type. Expected a array but failed to convert 'some text' into a array "
) ) ;
2023-01-15 09:48:20 +00:00
//
let tmp = res . remove ( 0 ) . result ? ;
2023-04-29 15:58:22 +00:00
let val = Value ::Bool ( true ) ;
2023-01-15 09:48:20 +00:00
assert_eq! ( tmp , val ) ;
//
Ok ( ( ) )
}
2022-11-27 19:42:24 +00:00
#[ tokio::test ]
async fn function_array_combine ( ) -> Result < ( ) , Error > {
let sql = r #"
RETURN array ::combine ( [ ] , [ ] ) ;
RETURN array ::combine ( 3 , true ) ;
RETURN array ::combine ( [ 1 , 2 ] , [ 2 , 3 ] ) ;
" #;
let dbs = Datastore ::new ( " memory " ) . await ? ;
let ses = Session ::for_kv ( ) . with_ns ( " test " ) . with_db ( " test " ) ;
let res = & mut dbs . execute ( & sql , & ses , None , false ) . await ? ;
assert_eq! ( res . len ( ) , 3 ) ;
//
let tmp = res . remove ( 0 ) . result ? ;
let val = Value ::parse ( " [] " ) ;
assert_eq! ( tmp , val ) ;
//
2023-04-25 10:13:04 +00:00
let tmp = res . remove ( 0 ) . result ;
assert! ( matches! (
tmp . err ( ) ,
Some ( e ) if e . to_string ( ) = = " Incorrect arguments for function array::combine(). Argument 1 was the wrong type. Expected a array but failed to convert 3 into a array "
) ) ;
2022-11-27 19:42:24 +00:00
//
let tmp = res . remove ( 0 ) . result ? ;
let val = Value ::parse ( " [ [1,2], [1,3], [2,2], [2,3] ] " ) ;
assert_eq! ( tmp , val ) ;
//
Ok ( ( ) )
}
#[ tokio::test ]
async fn function_array_complement ( ) -> Result < ( ) , Error > {
let sql = r #"
RETURN array ::complement ( [ ] , [ ] ) ;
RETURN array ::complement ( 3 , true ) ;
RETURN array ::complement ( [ 1 , 2 , 3 , 4 ] , [ 3 , 4 , 5 , 6 ] ) ;
" #;
let dbs = Datastore ::new ( " memory " ) . await ? ;
let ses = Session ::for_kv ( ) . with_ns ( " test " ) . with_db ( " test " ) ;
let res = & mut dbs . execute ( & sql , & ses , None , false ) . await ? ;
assert_eq! ( res . len ( ) , 3 ) ;
//
let tmp = res . remove ( 0 ) . result ? ;
let val = Value ::parse ( " [] " ) ;
assert_eq! ( tmp , val ) ;
//
2023-04-25 10:13:04 +00:00
let tmp = res . remove ( 0 ) . result ;
assert! ( matches! (
tmp . err ( ) ,
Some ( e ) if e . to_string ( ) = = " Incorrect arguments for function array::complement(). Argument 1 was the wrong type. Expected a array but failed to convert 3 into a array "
) ) ;
2022-11-27 19:42:24 +00:00
//
let tmp = res . remove ( 0 ) . result ? ;
let val = Value ::parse ( " [1,2] " ) ;
assert_eq! ( tmp , val ) ;
//
Ok ( ( ) )
}
#[ tokio::test ]
async fn function_array_concat ( ) -> Result < ( ) , Error > {
let sql = r #"
RETURN array ::concat ( [ ] , [ ] ) ;
RETURN array ::concat ( 3 , true ) ;
RETURN array ::concat ( [ 1 , 2 , 3 , 4 ] , [ 3 , 4 , 5 , 6 ] ) ;
" #;
let dbs = Datastore ::new ( " memory " ) . await ? ;
let ses = Session ::for_kv ( ) . with_ns ( " test " ) . with_db ( " test " ) ;
let res = & mut dbs . execute ( & sql , & ses , None , false ) . await ? ;
assert_eq! ( res . len ( ) , 3 ) ;
//
let tmp = res . remove ( 0 ) . result ? ;
let val = Value ::parse ( " [] " ) ;
assert_eq! ( tmp , val ) ;
//
2023-04-25 10:13:04 +00:00
let tmp = res . remove ( 0 ) . result ;
assert! ( matches! (
tmp . err ( ) ,
Some ( e ) if e . to_string ( ) = = " Incorrect arguments for function array::concat(). Argument 1 was the wrong type. Expected a array but failed to convert 3 into a array "
) ) ;
2022-11-27 19:42:24 +00:00
//
let tmp = res . remove ( 0 ) . result ? ;
let val = Value ::parse ( " [1,2,3,4,3,4,5,6] " ) ;
assert_eq! ( tmp , val ) ;
//
Ok ( ( ) )
}
#[ tokio::test ]
async fn function_array_difference ( ) -> Result < ( ) , Error > {
let sql = r #"
RETURN array ::difference ( [ ] , [ ] ) ;
RETURN array ::difference ( 3 , true ) ;
RETURN array ::difference ( [ 1 , 2 , 3 , 4 ] , [ 3 , 4 , 5 , 6 ] ) ;
" #;
let dbs = Datastore ::new ( " memory " ) . await ? ;
let ses = Session ::for_kv ( ) . with_ns ( " test " ) . with_db ( " test " ) ;
let res = & mut dbs . execute ( & sql , & ses , None , false ) . await ? ;
assert_eq! ( res . len ( ) , 3 ) ;
//
let tmp = res . remove ( 0 ) . result ? ;
let val = Value ::parse ( " [] " ) ;
assert_eq! ( tmp , val ) ;
//
2023-04-25 10:13:04 +00:00
let tmp = res . remove ( 0 ) . result ;
assert! ( matches! (
tmp . err ( ) ,
Some ( e ) if e . to_string ( ) = = " Incorrect arguments for function array::difference(). Argument 1 was the wrong type. Expected a array but failed to convert 3 into a array "
) ) ;
2022-11-27 19:42:24 +00:00
let tmp = res . remove ( 0 ) . result ? ;
let val = Value ::parse ( " [1,2,5,6] " ) ;
assert_eq! ( tmp , val ) ;
//
Ok ( ( ) )
}
2022-10-27 12:23:24 +00:00
#[ tokio::test ]
2022-11-27 11:05:33 +00:00
async fn function_array_distinct ( ) -> Result < ( ) , Error > {
2022-10-27 12:23:24 +00:00
let sql = r #"
2022-11-27 11:05:33 +00:00
RETURN array ::distinct ( [ ] ) ;
2022-11-27 19:42:24 +00:00
RETURN array ::distinct ( " some text " ) ;
RETURN array ::distinct ( [ 1 , 2 , 1 , 3 , 3 , 4 ] ) ;
2022-10-27 12:23:24 +00:00
" #;
let dbs = Datastore ::new ( " memory " ) . await ? ;
let ses = Session ::for_kv ( ) . with_ns ( " test " ) . with_db ( " test " ) ;
let res = & mut dbs . execute ( & sql , & ses , None , false ) . await ? ;
2022-11-27 19:42:24 +00:00
assert_eq! ( res . len ( ) , 3 ) ;
2022-10-27 12:23:24 +00:00
//
let tmp = res . remove ( 0 ) . result ? ;
2022-11-27 19:42:24 +00:00
let val = Value ::parse ( " [] " ) ;
2022-10-27 12:23:24 +00:00
assert_eq! ( tmp , val ) ;
//
2023-04-25 10:13:04 +00:00
let tmp = res . remove ( 0 ) . result ;
assert! ( matches! (
tmp . err ( ) ,
Some ( e ) if e . to_string ( ) = = " Incorrect arguments for function array::distinct(). Argument 1 was the wrong type. Expected a array but failed to convert 'some text' into a array "
) ) ;
2022-11-27 19:42:24 +00:00
//
let tmp = res . remove ( 0 ) . result ? ;
let val = Value ::parse ( " [1,2,3,4] " ) ;
assert_eq! ( tmp , val ) ;
//
Ok ( ( ) )
}
2022-11-28 12:18:30 +00:00
#[ tokio::test ]
async fn function_array_flatten ( ) -> Result < ( ) , Error > {
let sql = r #"
RETURN array ::flatten ( [ ] ) ;
RETURN array ::flatten ( " some text " ) ;
RETURN array ::flatten ( [ [ 1 , 2 ] , [ 3 , 4 ] ] ) ;
RETURN array ::flatten ( [ [ 1 , 2 ] , [ 3 , 4 ] , ' SurrealDB ' , [ 5 , 6 , [ 7 , 8 ] ] ] ) ;
" #;
let dbs = Datastore ::new ( " memory " ) . await ? ;
let ses = Session ::for_kv ( ) . with_ns ( " test " ) . with_db ( " test " ) ;
let res = & mut dbs . execute ( & sql , & ses , None , false ) . await ? ;
assert_eq! ( res . len ( ) , 4 ) ;
//
let tmp = res . remove ( 0 ) . result ? ;
let val = Value ::parse ( " [] " ) ;
assert_eq! ( tmp , val ) ;
//
2023-04-25 10:13:04 +00:00
let tmp = res . remove ( 0 ) . result ;
assert! ( matches! (
tmp . err ( ) ,
Some ( e ) if e . to_string ( ) = = " Incorrect arguments for function array::flatten(). Argument 1 was the wrong type. Expected a array but failed to convert 'some text' into a array "
) ) ;
2022-11-28 12:18:30 +00:00
//
let tmp = res . remove ( 0 ) . result ? ;
let val = Value ::parse ( " [1,2,3,4] " ) ;
assert_eq! ( tmp , val ) ;
//
let tmp = res . remove ( 0 ) . result ? ;
let val = Value ::parse ( " [1, 2, 3, 4, 'SurrealDB', 5, 6, [7, 8]] " ) ;
assert_eq! ( tmp , val ) ;
//
Ok ( ( ) )
}
2023-01-07 20:02:49 +00:00
#[ tokio::test ]
async fn function_array_group ( ) -> Result < ( ) , Error > {
let sql = r #"
RETURN array ::group ( [ ] ) ;
RETURN array ::group ( 3 ) ;
RETURN array ::group ( [ [ 1 , 2 , 3 , 4 ] , [ 3 , 4 , 5 , 6 ] ] ) ;
" #;
let dbs = Datastore ::new ( " memory " ) . await ? ;
let ses = Session ::for_kv ( ) . with_ns ( " test " ) . with_db ( " test " ) ;
let res = & mut dbs . execute ( & sql , & ses , None , false ) . await ? ;
assert_eq! ( res . len ( ) , 3 ) ;
//
let tmp = res . remove ( 0 ) . result ? ;
let val = Value ::parse ( " [] " ) ;
assert_eq! ( tmp , val ) ;
//
2023-04-25 10:13:04 +00:00
let tmp = res . remove ( 0 ) . result ;
assert! ( matches! (
tmp . err ( ) ,
Some ( e ) if e . to_string ( ) = = " Incorrect arguments for function array::group(). Argument 1 was the wrong type. Expected a array but failed to convert 3 into a array "
) ) ;
2023-01-07 20:02:49 +00:00
//
let tmp = res . remove ( 0 ) . result ? ;
let val = Value ::parse ( " [1,2,3,4,5,6] " ) ;
assert_eq! ( tmp , val ) ;
//
Ok ( ( ) )
}
2022-12-17 21:03:13 +00:00
#[ tokio::test ]
async fn function_array_insert ( ) -> Result < ( ) , Error > {
let sql = r #"
RETURN array ::insert ( [ ] , 1 ) ;
2023-04-20 18:21:53 +00:00
RETURN array ::insert ( [ 3 ] , 1 , 5 ) ;
2022-12-17 21:03:13 +00:00
RETURN array ::insert ( [ 3 ] , 1 , 1 ) ;
RETURN array ::insert ( [ 1 , 2 , 3 , 4 ] , 5 , - 1 ) ;
" #;
let dbs = Datastore ::new ( " memory " ) . await ? ;
let ses = Session ::for_kv ( ) . with_ns ( " test " ) . with_db ( " test " ) ;
let res = & mut dbs . execute ( & sql , & ses , None , false ) . await ? ;
2023-04-20 18:21:53 +00:00
assert_eq! ( res . len ( ) , 4 ) ;
2022-12-17 21:03:13 +00:00
//
let tmp = res . remove ( 0 ) . result ? ;
let val = Value ::parse ( " [1] " ) ;
assert_eq! ( tmp , val ) ;
//
let tmp = res . remove ( 0 ) . result ? ;
2023-04-20 18:21:53 +00:00
let val = Value ::parse ( " [3] " ) ;
assert_eq! ( tmp , val ) ;
//
let tmp = res . remove ( 0 ) . result ? ;
2022-12-17 21:03:13 +00:00
let val = Value ::parse ( " [3,1] " ) ;
assert_eq! ( tmp , val ) ;
//
let tmp = res . remove ( 0 ) . result ? ;
let val = Value ::parse ( " [1,2,3,5,4] " ) ;
assert_eq! ( tmp , val ) ;
//
Ok ( ( ) )
}
2022-11-27 19:42:24 +00:00
#[ tokio::test ]
async fn function_array_intersect ( ) -> Result < ( ) , Error > {
let sql = r #"
RETURN array ::intersect ( [ ] , [ ] ) ;
RETURN array ::intersect ( 3 , true ) ;
RETURN array ::intersect ( [ 1 , 2 , 3 , 4 ] , [ 3 , 4 , 5 , 6 ] ) ;
" #;
let dbs = Datastore ::new ( " memory " ) . await ? ;
let ses = Session ::for_kv ( ) . with_ns ( " test " ) . with_db ( " test " ) ;
let res = & mut dbs . execute ( & sql , & ses , None , false ) . await ? ;
assert_eq! ( res . len ( ) , 3 ) ;
//
let tmp = res . remove ( 0 ) . result ? ;
let val = Value ::parse ( " [] " ) ;
assert_eq! ( tmp , val ) ;
//
2023-04-25 10:13:04 +00:00
let tmp = res . remove ( 0 ) . result ;
assert! ( matches! (
tmp . err ( ) ,
Some ( e ) if e . to_string ( ) = = " Incorrect arguments for function array::intersect(). Argument 1 was the wrong type. Expected a array but failed to convert 3 into a array "
) ) ;
2022-11-27 19:42:24 +00:00
//
let tmp = res . remove ( 0 ) . result ? ;
let val = Value ::parse ( " [3,4] " ) ;
assert_eq! ( tmp , val ) ;
//
Ok ( ( ) )
}
2023-01-15 09:48:20 +00:00
#[ tokio::test ]
async fn function_array_max ( ) -> Result < ( ) , Error > {
let sql = r #"
RETURN array ::max ( [ ] ) ;
RETURN array ::max ( " some text " ) ;
RETURN array ::max ( [ 1 , 2 , " text " , 3 , 3 , 4 ] ) ;
" #;
let dbs = Datastore ::new ( " memory " ) . await ? ;
let ses = Session ::for_kv ( ) . with_ns ( " test " ) . with_db ( " test " ) ;
let res = & mut dbs . execute ( & sql , & ses , None , false ) . await ? ;
assert_eq! ( res . len ( ) , 3 ) ;
//
let tmp = res . remove ( 0 ) . result ? ;
let val = Value ::None ;
assert_eq! ( tmp , val ) ;
//
2023-04-25 10:13:04 +00:00
let tmp = res . remove ( 0 ) . result ;
assert! ( matches! (
tmp . err ( ) ,
Some ( e ) if e . to_string ( ) = = " Incorrect arguments for function array::max(). Argument 1 was the wrong type. Expected a array but failed to convert 'some text' into a array "
) ) ;
2023-01-15 09:48:20 +00:00
//
let tmp = res . remove ( 0 ) . result ? ;
2023-01-18 00:11:19 +00:00
let val = Value ::parse ( " 'text' " ) ;
2023-01-15 09:48:20 +00:00
assert_eq! ( tmp , val ) ;
//
Ok ( ( ) )
}
#[ tokio::test ]
async fn function_array_min ( ) -> Result < ( ) , Error > {
let sql = r #"
RETURN array ::min ( [ ] ) ;
RETURN array ::min ( " some text " ) ;
RETURN array ::min ( [ 1 , 2 , " text " , 3 , 3 , 4 ] ) ;
" #;
let dbs = Datastore ::new ( " memory " ) . await ? ;
let ses = Session ::for_kv ( ) . with_ns ( " test " ) . with_db ( " test " ) ;
let res = & mut dbs . execute ( & sql , & ses , None , false ) . await ? ;
assert_eq! ( res . len ( ) , 3 ) ;
//
let tmp = res . remove ( 0 ) . result ? ;
let val = Value ::None ;
assert_eq! ( tmp , val ) ;
//
2023-04-25 10:13:04 +00:00
let tmp = res . remove ( 0 ) . result ;
assert! ( matches! (
tmp . err ( ) ,
Some ( e ) if e . to_string ( ) = = " Incorrect arguments for function array::min(). Argument 1 was the wrong type. Expected a array but failed to convert 'some text' into a array "
) ) ;
2023-01-15 09:48:20 +00:00
//
let tmp = res . remove ( 0 ) . result ? ;
let val = Value ::parse ( " 1 " ) ;
assert_eq! ( tmp , val ) ;
//
Ok ( ( ) )
}
2023-04-20 18:21:53 +00:00
#[ tokio::test ]
async fn function_array_remove ( ) -> Result < ( ) , Error > {
let sql = r #"
RETURN array ::remove ( [ 3 ] , 0 ) ;
RETURN array ::remove ( [ 3 ] , 2 ) ;
RETURN array ::remove ( [ 3 , 4 , 5 ] , 1 ) ;
RETURN array ::remove ( [ 1 , 2 , 3 , 4 ] , - 1 ) ;
" #;
let dbs = Datastore ::new ( " memory " ) . await ? ;
let ses = Session ::for_kv ( ) . with_ns ( " test " ) . with_db ( " test " ) ;
let res = & mut dbs . execute ( & sql , & ses , None , false ) . await ? ;
assert_eq! ( res . len ( ) , 4 ) ;
//
let tmp = res . remove ( 0 ) . result ? ;
let val = Value ::parse ( " [] " ) ;
assert_eq! ( tmp , val ) ;
//
let tmp = res . remove ( 0 ) . result ? ;
let val = Value ::parse ( " [3] " ) ;
assert_eq! ( tmp , val ) ;
//
let tmp = res . remove ( 0 ) . result ? ;
let val = Value ::parse ( " [3,5] " ) ;
assert_eq! ( tmp , val ) ;
//
let tmp = res . remove ( 0 ) . result ? ;
let val = Value ::parse ( " [1,2,3] " ) ;
assert_eq! ( tmp , val ) ;
//
Ok ( ( ) )
}
2022-11-27 19:42:24 +00:00
#[ tokio::test ]
async fn function_array_union ( ) -> Result < ( ) , Error > {
let sql = r #"
RETURN array ::union ( [ ] , [ ] ) ;
RETURN array ::union ( 3 , true ) ;
RETURN array ::union ( [ 1 , 2 , 1 , 6 ] , [ 1 , 3 , 4 , 5 , 6 ] ) ;
" #;
let dbs = Datastore ::new ( " memory " ) . await ? ;
let ses = Session ::for_kv ( ) . with_ns ( " test " ) . with_db ( " test " ) ;
let res = & mut dbs . execute ( & sql , & ses , None , false ) . await ? ;
assert_eq! ( res . len ( ) , 3 ) ;
//
let tmp = res . remove ( 0 ) . result ? ;
2022-10-27 12:23:24 +00:00
let val = Value ::parse ( " [] " ) ;
assert_eq! ( tmp , val ) ;
//
2023-04-25 10:13:04 +00:00
let tmp = res . remove ( 0 ) . result ;
assert! ( matches! (
tmp . err ( ) ,
Some ( e ) if e . to_string ( ) = = " Incorrect arguments for function array::union(). Argument 1 was the wrong type. Expected a array but failed to convert 3 into a array "
) ) ;
2022-10-27 12:23:24 +00:00
//
let tmp = res . remove ( 0 ) . result ? ;
2022-11-27 19:42:24 +00:00
let val = Value ::parse ( " [1,2,6,3,4,5] " ) ;
2022-10-27 12:23:24 +00:00
assert_eq! ( tmp , val ) ;
//
Ok ( ( ) )
}
2022-11-27 11:05:33 +00:00
#[ tokio::test ]
async fn function_string_slice ( ) -> Result < ( ) , Error > {
let sql = r #"
RETURN string ::slice ( " the quick brown fox jumps over the lazy dog. " ) ;
RETURN string ::slice ( " the quick brown fox jumps over the lazy dog. " , 16 ) ;
RETURN string ::slice ( " the quick brown fox jumps over the lazy dog. " , 0 , 60 ) ;
RETURN string ::slice ( " the quick brown fox jumps over the lazy dog. " , 0 , - 1 ) ;
RETURN string ::slice ( " the quick brown fox jumps over the lazy dog. " , 16 , - 1 ) ;
RETURN string ::slice ( " the quick brown fox jumps over the lazy dog. " , - 9 , - 1 ) ;
2022-12-03 23:30:38 +00:00
RETURN string ::slice ( " the quick brown fox jumps over the lazy dog. " , - 100 , - 100 ) ;
2022-11-27 11:05:33 +00:00
" #;
let dbs = Datastore ::new ( " memory " ) . await ? ;
let ses = Session ::for_kv ( ) . with_ns ( " test " ) . with_db ( " test " ) ;
let res = & mut dbs . execute ( & sql , & ses , None , false ) . await ? ;
2022-12-03 23:30:38 +00:00
assert_eq! ( res . len ( ) , 7 ) ;
2022-11-27 11:05:33 +00:00
//
let tmp = res . remove ( 0 ) . result ? ;
let val = Value ::parse ( " 'the quick brown fox jumps over the lazy dog.' " ) ;
assert_eq! ( tmp , val ) ;
//
let tmp = res . remove ( 0 ) . result ? ;
let val = Value ::parse ( " 'fox jumps over the lazy dog.' " ) ;
assert_eq! ( tmp , val ) ;
//
let tmp = res . remove ( 0 ) . result ? ;
let val = Value ::parse ( " 'the quick brown fox jumps over the lazy dog.' " ) ;
assert_eq! ( tmp , val ) ;
//
let tmp = res . remove ( 0 ) . result ? ;
let val = Value ::parse ( " 'the quick brown fox jumps over the lazy dog' " ) ;
assert_eq! ( tmp , val ) ;
//
let tmp = res . remove ( 0 ) . result ? ;
let val = Value ::parse ( " 'fox jumps over the lazy dog' " ) ;
assert_eq! ( tmp , val ) ;
//
let tmp = res . remove ( 0 ) . result ? ;
let val = Value ::parse ( " 'lazy dog' " ) ;
assert_eq! ( tmp , val ) ;
//
2022-12-03 23:30:38 +00:00
let tmp = res . remove ( 0 ) . result ? ;
let val = Value ::parse ( " '' " ) ;
assert_eq! ( tmp , val ) ;
//
2022-11-27 11:05:33 +00:00
Ok ( ( ) )
}
2022-12-30 09:34:46 +00:00
#[ tokio::test ]
async fn function_not ( ) -> Result < ( ) , Error > {
let sql = r #"
RETURN not ( true ) ;
RETURN not ( not ( true ) ) ;
RETURN not ( false ) ;
RETURN not ( not ( false ) ) ;
RETURN not ( 0 ) ;
RETURN not ( 1 ) ;
RETURN not ( " hello " ) ;
" #;
let dbs = Datastore ::new ( " memory " ) . await ? ;
let ses = Session ::for_kv ( ) . with_ns ( " test " ) . with_db ( " test " ) ;
let res = & mut dbs . execute ( & sql , & ses , None , false ) . await ? ;
assert_eq! ( res . len ( ) , 7 ) ;
//
let tmp = res . remove ( 0 ) . result ? ;
2023-04-29 15:58:22 +00:00
let val = Value ::Bool ( false ) ;
2022-12-30 09:34:46 +00:00
assert_eq! ( tmp , val ) ;
//
let tmp = res . remove ( 0 ) . result ? ;
2023-04-29 15:58:22 +00:00
let val = Value ::Bool ( true ) ;
2022-12-30 09:34:46 +00:00
assert_eq! ( tmp , val ) ;
//
let tmp = res . remove ( 0 ) . result ? ;
2023-04-29 15:58:22 +00:00
let val = Value ::Bool ( true ) ;
2022-12-30 09:34:46 +00:00
assert_eq! ( tmp , val ) ;
//
let tmp = res . remove ( 0 ) . result ? ;
2023-04-29 15:58:22 +00:00
let val = Value ::Bool ( false ) ;
2022-12-30 09:34:46 +00:00
assert_eq! ( tmp , val ) ;
//
let tmp = res . remove ( 0 ) . result ? ;
2023-04-29 15:58:22 +00:00
let val = Value ::Bool ( true ) ;
2022-12-30 09:34:46 +00:00
assert_eq! ( tmp , val ) ;
//
let tmp = res . remove ( 0 ) . result ? ;
2023-04-29 15:58:22 +00:00
let val = Value ::Bool ( false ) ;
2022-12-30 09:34:46 +00:00
assert_eq! ( tmp , val ) ;
//
let tmp = res . remove ( 0 ) . result ? ;
2023-04-29 15:58:22 +00:00
let val = Value ::Bool ( false ) ;
2022-12-30 09:34:46 +00:00
assert_eq! ( tmp , val ) ;
//
Ok ( ( ) )
}
2023-02-11 18:17:02 +00:00
#[ tokio::test ]
async fn function_type_thing ( ) -> Result < ( ) , Error > {
let sql = r #"
CREATE type ::thing ( ' person ' , ' test ' ) ;
CREATE type ::thing ( ' person ' , 1434619 ) ;
CREATE type ::thing ( ' city ' , ' 8e60244 d - 95 f6 - 4 f95 - 9e30 - 09 a98977efb0 ' ) ;
CREATE type ::thing ( ' temperature ' , [ ' London ' , ' 2022 - 09 - 30 T20 :25 :01.406828 Z ' ] ) ;
" #;
let dbs = Datastore ::new ( " memory " ) . await ? ;
let ses = Session ::for_kv ( ) . with_ns ( " test " ) . with_db ( " test " ) ;
let res = & mut dbs . execute ( & sql , & ses , None , false ) . await ? ;
assert_eq! ( res . len ( ) , 4 ) ;
//
let tmp = res . remove ( 0 ) . result ? ;
let val = Value ::parse (
" [
{
id : person :test ,
}
] " ,
) ;
assert_eq! ( tmp , val ) ;
//
let tmp = res . remove ( 0 ) . result ? ;
let val = Value ::parse (
" [
{
id : person :1434619 ,
}
] " ,
) ;
assert_eq! ( tmp , val ) ;
//
let tmp = res . remove ( 0 ) . result ? ;
let val = Value ::parse (
" [
{
id : city :⟨ 8e60244 d - 95 f6 - 4 f95 - 9e30 - 09 a98977efb0 ⟩ ,
}
] " ,
) ;
assert_eq! ( tmp , val ) ;
//
let tmp = res . remove ( 0 ) . result ? ;
let val = Value ::parse (
" [
{
id : temperature :[ ' London ' , ' 2022 - 09 - 30 T20 :25 :01.406828 Z ' ] ,
}
] " ,
) ;
assert_eq! ( tmp , val ) ;
//
Ok ( ( ) )
}