@ -1,6 +1,7 @@
use approx ::AbsDiffEq ;
use num_traits ::FloatConst ;
use regex ::Regex ;
use smartstring ::SmartString ;
use crate ::data ::functions ::* ;
use crate ::data ::value ::{ DataValue , RegexWrapper } ;
@ -116,7 +117,7 @@ fn test_is_in() {
DataValue ::from ( 1 ) ,
DataValue ::List ( vec! [ DataValue ::from ( 1 ) , DataValue ::from ( 2 ) ] )
] )
. unwrap ( ) ,
. unwrap ( ) ,
DataValue ::Bool ( true )
) ;
assert_eq! (
@ -124,7 +125,7 @@ fn test_is_in() {
DataValue ::from ( 3 ) ,
DataValue ::List ( vec! [ DataValue ::from ( 1 ) , DataValue ::from ( 2 ) ] )
] )
. unwrap ( ) ,
. unwrap ( ) ,
DataValue ::Bool ( false )
) ;
assert_eq! (
@ -240,7 +241,7 @@ fn test_comparators() {
#[ test ]
fn test_max_min ( ) {
assert_eq! ( op_max ( & [ DataValue ::from ( 1 ) , ] ) . unwrap ( ) , DataValue ::from ( 1 ) ) ;
assert_eq! ( op_max ( & [ DataValue ::from ( 1 ) , ] ) . unwrap ( ) , DataValue ::from ( 1 ) ) ;
assert_eq! (
op_max ( & [
DataValue ::from ( 1 ) ,
@ -248,7 +249,7 @@ fn test_max_min() {
DataValue ::from ( 3 ) ,
DataValue ::from ( 4 )
] )
. unwrap ( ) ,
. unwrap ( ) ,
DataValue ::from ( 4 )
) ;
assert_eq! (
@ -258,7 +259,7 @@ fn test_max_min() {
DataValue ::from ( 3 ) ,
DataValue ::from ( 4 )
] )
. unwrap ( ) ,
. unwrap ( ) ,
DataValue ::from ( 4 )
) ;
assert_eq! (
@ -268,12 +269,12 @@ fn test_max_min() {
DataValue ::from ( 3 ) ,
DataValue ::from ( 4.0 )
] )
. unwrap ( ) ,
. unwrap ( ) ,
DataValue ::from ( 4.0 )
) ;
assert! ( op_max ( & [ DataValue ::Bool ( true ) ] ) . is_err ( ) ) ;
assert_eq! ( op_min ( & [ DataValue ::from ( 1 ) , ] ) . unwrap ( ) , DataValue ::from ( 1 ) ) ;
assert_eq! ( op_min ( & [ DataValue ::from ( 1 ) , ] ) . unwrap ( ) , DataValue ::from ( 1 ) ) ;
assert_eq! (
op_min ( & [
DataValue ::from ( 1 ) ,
@ -281,7 +282,7 @@ fn test_max_min() {
DataValue ::from ( 3 ) ,
DataValue ::from ( 4 )
] )
. unwrap ( ) ,
. unwrap ( ) ,
DataValue ::from ( 1 )
) ;
assert_eq! (
@ -291,7 +292,7 @@ fn test_max_min() {
DataValue ::from ( 3 ) ,
DataValue ::from ( 4 )
] )
. unwrap ( ) ,
. unwrap ( ) ,
DataValue ::from ( 1.0 )
) ;
assert_eq! (
@ -301,7 +302,7 @@ fn test_max_min() {
DataValue ::from ( 3 ) ,
DataValue ::from ( 4.0 )
] )
. unwrap ( ) ,
. unwrap ( ) ,
DataValue ::from ( 1 )
) ;
assert! ( op_max ( & [ DataValue ::Bool ( true ) ] ) . is_err ( ) ) ;
@ -555,7 +556,7 @@ fn test_bits() {
DataValue ::Bytes ( [ 0b111000 ] . into ( ) ) ,
DataValue ::Bytes ( [ 0b010101 ] . into ( ) )
] )
. unwrap ( ) ,
. unwrap ( ) ,
DataValue ::Bytes ( [ 0b010000 ] . into ( ) )
) ;
assert_eq! (
@ -563,7 +564,7 @@ fn test_bits() {
DataValue ::Bytes ( [ 0b111000 ] . into ( ) ) ,
DataValue ::Bytes ( [ 0b010101 ] . into ( ) )
] )
. unwrap ( ) ,
. unwrap ( ) ,
DataValue ::Bytes ( [ 0b111101 ] . into ( ) )
) ;
assert_eq! (
@ -575,7 +576,7 @@ fn test_bits() {
DataValue ::Bytes ( [ 0b111000 ] . into ( ) ) ,
DataValue ::Bytes ( [ 0b010101 ] . into ( ) )
] )
. unwrap ( ) ,
. unwrap ( ) ,
DataValue ::Bytes ( [ 0b101101 ] . into ( ) )
) ;
}
@ -613,11 +614,11 @@ fn test_concat() {
DataValue ::List ( vec! [ DataValue ::Bool ( true ) , DataValue ::Bool ( false ) ] ) ,
DataValue ::List ( vec! [ DataValue ::Bool ( true ) ] )
] )
. unwrap ( ) ,
. unwrap ( ) ,
DataValue ::List ( vec! [
DataValue ::Bool ( true ) ,
DataValue ::Bool ( false ) ,
DataValue ::Bool ( true )
DataValue ::Bool ( true ) ,
] )
) ;
}
@ -629,7 +630,7 @@ fn test_str_includes() {
DataValue ::Str ( "abcdef" . into ( ) ) ,
DataValue ::Str ( "bcd" . into ( ) )
] )
. unwrap ( ) ,
. unwrap ( ) ,
DataValue ::Bool ( true )
) ;
assert_eq! (
@ -673,7 +674,7 @@ fn test_starts_ends_with() {
DataValue ::Str ( "abcdef" . into ( ) ) ,
DataValue ::Str ( "abc" . into ( ) )
] )
. unwrap ( ) ,
. unwrap ( ) ,
DataValue ::Bool ( true )
) ;
assert_eq! (
@ -685,7 +686,7 @@ fn test_starts_ends_with() {
DataValue ::Str ( "abcdef" . into ( ) ) ,
DataValue ::Str ( "def" . into ( ) )
] )
. unwrap ( ) ,
. unwrap ( ) ,
DataValue ::Bool ( true )
) ;
assert_eq! (
@ -701,7 +702,7 @@ fn test_regex() {
DataValue ::Str ( "abcdef" . into ( ) ) ,
DataValue ::Regex ( RegexWrapper ( Regex ::new ( "c.e" ) . unwrap ( ) ) )
] )
. unwrap ( ) ,
. unwrap ( ) ,
DataValue ::Bool ( true )
) ;
@ -710,7 +711,7 @@ fn test_regex() {
DataValue ::Str ( "abcdef" . into ( ) ) ,
DataValue ::Regex ( RegexWrapper ( Regex ::new ( "c.ef$" ) . unwrap ( ) ) )
] )
. unwrap ( ) ,
. unwrap ( ) ,
DataValue ::Bool ( true )
) ;
@ -719,7 +720,7 @@ fn test_regex() {
DataValue ::Str ( "abcdef" . into ( ) ) ,
DataValue ::Regex ( RegexWrapper ( Regex ::new ( "c.e$" ) . unwrap ( ) ) )
] )
. unwrap ( ) ,
. unwrap ( ) ,
DataValue ::Bool ( false )
) ;
@ -729,7 +730,7 @@ fn test_regex() {
DataValue ::Regex ( RegexWrapper ( Regex ::new ( "[be]" ) . unwrap ( ) ) ) ,
DataValue ::Str ( "x" . into ( ) )
] )
. unwrap ( ) ,
. unwrap ( ) ,
DataValue ::Str ( "axcdef" . into ( ) )
) ;
@ -739,7 +740,7 @@ fn test_regex() {
DataValue ::Regex ( RegexWrapper ( Regex ::new ( "[be]" ) . unwrap ( ) ) ) ,
DataValue ::Str ( "x" . into ( ) )
] )
. unwrap ( ) ,
. unwrap ( ) ,
DataValue ::Str ( "axcdxf" . into ( ) )
) ;
assert_eq! (
@ -747,7 +748,7 @@ fn test_regex() {
DataValue ::Str ( "abCDefGH" . into ( ) ) ,
DataValue ::Regex ( RegexWrapper ( Regex ::new ( "[xayef]|(GH)" ) . unwrap ( ) ) )
] )
. unwrap ( ) ,
. unwrap ( ) ,
DataValue ::List ( vec! [
DataValue ::Str ( "a" . into ( ) ) ,
DataValue ::Str ( "e" . into ( ) ) ,
@ -760,7 +761,7 @@ fn test_regex() {
DataValue ::Str ( "abCDefGH" . into ( ) ) ,
DataValue ::Regex ( RegexWrapper ( Regex ::new ( "[xayef]|(GH)" ) . unwrap ( ) ) )
] )
. unwrap ( ) ,
. unwrap ( ) ,
DataValue ::Str ( "a" . into ( ) ) ,
) ;
assert_eq! (
@ -768,7 +769,7 @@ fn test_regex() {
DataValue ::Str ( "abCDefGH" . into ( ) ) ,
DataValue ::Regex ( RegexWrapper ( Regex ::new ( "xyz" ) . unwrap ( ) ) )
] )
. unwrap ( ) ,
. unwrap ( ) ,
DataValue ::List ( vec! [ ] )
) ;
@ -777,7 +778,7 @@ fn test_regex() {
DataValue ::Str ( "abCDefGH" . into ( ) ) ,
DataValue ::Regex ( RegexWrapper ( Regex ::new ( "xyz" ) . unwrap ( ) ) )
] )
. unwrap ( ) ,
. unwrap ( ) ,
DataValue ::Null
) ;
}
@ -897,11 +898,11 @@ fn test_prepend_append() {
DataValue ::List ( vec! [ DataValue ::from ( 1 ) , DataValue ::from ( 2 ) ] ) ,
DataValue ::Null ,
] )
. unwrap ( ) ,
. unwrap ( ) ,
DataValue ::List ( vec! [
DataValue ::Null ,
DataValue ::from ( 1 ) ,
DataValue ::from ( 2 )
DataValue ::from ( 2 ) ,
] ) ,
) ;
assert_eq! (
@ -909,7 +910,7 @@ fn test_prepend_append() {
DataValue ::List ( vec! [ DataValue ::from ( 1 ) , DataValue ::from ( 2 ) ] ) ,
DataValue ::Null ,
] )
. unwrap ( ) ,
. unwrap ( ) ,
DataValue ::List ( vec! [
DataValue ::from ( 1 ) ,
DataValue ::from ( 2 ) ,
@ -950,9 +951,9 @@ fn test_sort_reverse() {
DataValue ::from ( 2.0 ) ,
DataValue ::from ( 1 ) ,
DataValue ::from ( 2 ) ,
DataValue ::Null
DataValue ::Null ,
] ) ] )
. unwrap ( ) ,
. unwrap ( ) ,
DataValue ::List ( vec! [
DataValue ::Null ,
DataValue ::from ( 1 ) ,
@ -965,9 +966,9 @@ fn test_sort_reverse() {
DataValue ::from ( 2.0 ) ,
DataValue ::from ( 1 ) ,
DataValue ::from ( 2 ) ,
DataValue ::Null
DataValue ::Null ,
] ) ] )
. unwrap ( ) ,
. unwrap ( ) ,
DataValue ::List ( vec! [
DataValue ::Null ,
DataValue ::from ( 2 ) ,
@ -985,9 +986,9 @@ fn test_haversine() {
DataValue ::from ( 0 ) ,
DataValue ::from ( 180 ) ,
] )
. unwrap ( )
. get_float ( )
. unwrap ( ) ;
. unwrap ( )
. get_float ( )
. unwrap ( ) ;
assert! ( d . abs_diff_eq ( & f64 ::PI ( ) , 1e-5 ) ) ;
let d = op_haversine_deg_input ( & [
@ -996,9 +997,9 @@ fn test_haversine() {
DataValue ::from ( 0 ) ,
DataValue ::from ( 123 ) ,
] )
. unwrap ( )
. get_float ( )
. unwrap ( ) ;
. unwrap ( )
. get_float ( )
. unwrap ( ) ;
assert! ( d . abs_diff_eq ( & ( f64 ::PI ( ) / 2. ) , 1e-5 ) ) ;
let d = op_haversine ( & [
@ -1007,9 +1008,9 @@ fn test_haversine() {
DataValue ::from ( 0 ) ,
DataValue ::from ( f64 ::PI ( ) ) ,
] )
. unwrap ( )
. get_float ( )
. unwrap ( ) ;
. unwrap ( )
. get_float ( )
. unwrap ( ) ;
assert! ( d . abs_diff_eq ( & f64 ::PI ( ) , 1e-5 ) ) ;
}
@ -1038,17 +1039,17 @@ fn test_first_last() {
assert_eq! (
op_first ( & [ DataValue ::List ( vec! [
DataValue ::from ( 1 ) ,
DataValue ::from ( 2 )
DataValue ::from ( 2 ) ,
] ) ] )
. unwrap ( ) ,
. unwrap ( ) ,
DataValue ::from ( 1 ) ,
) ;
assert_eq! (
op_last ( & [ DataValue ::List ( vec! [
DataValue ::from ( 1 ) ,
DataValue ::from ( 2 )
DataValue ::from ( 2 ) ,
] ) ] )
. unwrap ( ) ,
. unwrap ( ) ,
DataValue ::from ( 2 ) ,
) ;
}
@ -1066,10 +1067,10 @@ fn test_chunks() {
] ) ,
DataValue ::from ( 2 ) ,
] )
. unwrap ( ) ,
. unwrap ( ) ,
DataValue ::List ( vec! [
DataValue ::List ( vec! [ DataValue ::from ( 1 ) , DataValue ::from ( 2 ) , ]) ,
DataValue ::List ( vec! [ DataValue ::from ( 3 ) , DataValue ::from ( 4 ) , ]) ,
DataValue ::List ( vec! [ DataValue ::from ( 1 ) , DataValue ::from ( 2 ) ]) ,
DataValue ::List ( vec! [ DataValue ::from ( 3 ) , DataValue ::from ( 4 ) ]) ,
DataValue ::List ( vec! [ DataValue ::from ( 5 ) ] ) ,
] )
) ;
@ -1084,10 +1085,10 @@ fn test_chunks() {
] ) ,
DataValue ::from ( 2 ) ,
] )
. unwrap ( ) ,
. unwrap ( ) ,
DataValue ::List ( vec! [
DataValue ::List ( vec! [ DataValue ::from ( 1 ) , DataValue ::from ( 2 ) , ]) ,
DataValue ::List ( vec! [ DataValue ::from ( 3 ) , DataValue ::from ( 4 ) , ]) ,
DataValue ::List ( vec! [ DataValue ::from ( 1 ) , DataValue ::from ( 2 ) ]) ,
DataValue ::List ( vec! [ DataValue ::from ( 3 ) , DataValue ::from ( 4 ) ]) ,
] )
) ;
assert_eq! (
@ -1101,22 +1102,22 @@ fn test_chunks() {
] ) ,
DataValue ::from ( 3 ) ,
] )
. unwrap ( ) ,
. unwrap ( ) ,
DataValue ::List ( vec! [
DataValue ::List ( vec! [
DataValue ::from ( 1 ) ,
DataValue ::from ( 2 ) ,
DataValue ::from ( 3 )
DataValue ::from ( 3 ) ,
] ) ,
DataValue ::List ( vec! [
DataValue ::from ( 2 ) ,
DataValue ::from ( 3 ) ,
DataValue ::from ( 4 )
DataValue ::from ( 4 ) ,
] ) ,
DataValue ::List ( vec! [
DataValue ::from ( 3 ) ,
DataValue ::from ( 4 ) ,
DataValue ::from ( 5 )
DataValue ::from ( 5 ) ,
] ) ,
] )
)
@ -1130,11 +1131,11 @@ fn test_get() {
DataValue ::List ( vec! [
DataValue ::from ( 1 ) ,
DataValue ::from ( 2 ) ,
DataValue ::from ( 3 )
DataValue ::from ( 3 ) ,
] ) ,
DataValue ::from ( 1 )
] )
. unwrap ( ) ,
. unwrap ( ) ,
DataValue ::from ( 2 )
) ;
assert_eq! (
@ -1146,11 +1147,11 @@ fn test_get() {
DataValue ::List ( vec! [
DataValue ::from ( 1 ) ,
DataValue ::from ( 2 ) ,
DataValue ::from ( 3 )
DataValue ::from ( 3 ) ,
] ) ,
DataValue ::from ( 1 )
] )
. unwrap ( ) ,
. unwrap ( ) ,
DataValue ::from ( 2 )
) ;
}
@ -1161,24 +1162,24 @@ fn test_slice() {
DataValue ::List ( vec! [
DataValue ::from ( 1 ) ,
DataValue ::from ( 2 ) ,
DataValue ::from ( 3 )
DataValue ::from ( 3 ) ,
] ) ,
DataValue ::from ( 1 ) ,
DataValue ::from ( 4 )
] )
. is_err ( ) ) ;
. is_err ( ) ) ;
assert_eq! (
op_slice ( & [
DataValue ::List ( vec! [
DataValue ::from ( 1 ) ,
DataValue ::from ( 2 ) ,
DataValue ::from ( 3 )
DataValue ::from ( 3 ) ,
] ) ,
DataValue ::from ( 1 ) ,
DataValue ::from ( - 1 )
] )
. unwrap ( ) ,
. unwrap ( ) ,
DataValue ::List ( vec! [ DataValue ::from ( 2 ) ] )
) ;
}
@ -1276,11 +1277,11 @@ fn test_rand() {
fn test_set_ops ( ) {
assert_eq! (
op_union ( & [
DataValue ::List ( [ 1 , 2 , 3 ] . into_iter ( ) . map ( DataValue ::from ) . collect ( ) , ),
DataValue ::List ( [ 2 , 3 , 4 ] . into_iter ( ) . map ( DataValue ::from ) . collect ( ) , ),
DataValue ::List ( [ 3 , 4 , 5 ] . into_iter ( ) . map ( DataValue ::from ) . collect ( ) , )
DataValue ::List ( [ 1 , 2 , 3 ] . into_iter ( ) . map ( DataValue ::from ) . collect ( ) ),
DataValue ::List ( [ 2 , 3 , 4 ] . into_iter ( ) . map ( DataValue ::from ) . collect ( ) ),
DataValue ::List ( [ 3 , 4 , 5 ] . into_iter ( ) . map ( DataValue ::from ) . collect ( ) )
] )
. unwrap ( ) ,
. unwrap ( ) ,
DataValue ::List ( [ 1 , 2 , 3 , 4 , 5 ] . into_iter ( ) . map ( DataValue ::from ) . collect ( ) )
) ;
assert_eq! (
@ -1291,10 +1292,10 @@ fn test_set_ops() {
. map ( DataValue ::from )
. collect ( ) ,
) ,
DataValue ::List ( [ 2 , 3 , 4 ] . into_iter ( ) . map ( DataValue ::from ) . collect ( ) , ),
DataValue ::List ( [ 3 , 4 , 5 ] . into_iter ( ) . map ( DataValue ::from ) . collect ( ) , )
DataValue ::List ( [ 2 , 3 , 4 ] . into_iter ( ) . map ( DataValue ::from ) . collect ( ) ),
DataValue ::List ( [ 3 , 4 , 5 ] . into_iter ( ) . map ( DataValue ::from ) . collect ( ) )
] )
. unwrap ( ) ,
. unwrap ( ) ,
DataValue ::List ( [ 3 , 4 ] . into_iter ( ) . map ( DataValue ::from ) . collect ( ) )
) ;
assert_eq! (
@ -1305,10 +1306,20 @@ fn test_set_ops() {
. map ( DataValue ::from )
. collect ( ) ,
) ,
DataValue ::List ( [ 2 , 3 , 4 ] . into_iter ( ) . map ( DataValue ::from ) . collect ( ) , ),
DataValue ::List ( [ 3 , 4 , 5 ] . into_iter ( ) . map ( DataValue ::from ) . collect ( ) , )
DataValue ::List ( [ 2 , 3 , 4 ] . into_iter ( ) . map ( DataValue ::from ) . collect ( ) ),
DataValue ::List ( [ 3 , 4 , 5 ] . into_iter ( ) . map ( DataValue ::from ) . collect ( ) )
] )
. unwrap ( ) ,
. unwrap ( ) ,
DataValue ::List ( [ 1 , 6 ] . into_iter ( ) . map ( DataValue ::from ) . collect ( ) )
) ;
}
#[ test ]
fn test_uuid ( ) {
let v1 = op_rand_uuid_v1 ( & [ ] ) . unwrap ( ) ;
let v4 = op_rand_uuid_v4 ( & [ ] ) . unwrap ( ) ;
assert! ( op_is_uuid ( & [ v4 ] ) . unwrap ( ) . get_bool ( ) . unwrap ( ) ) ;
assert! ( op_uuid_timestamp ( & [ v1 ] ) . unwrap ( ) . get_int ( ) . is_some ( ) ) ;
assert! ( op_to_uuid ( & [ DataValue ::Str ( SmartString ::from ( "" ) ) ] ) . is_err ( ) ) ;
assert! ( op_to_uuid ( & [ DataValue ::Str ( SmartString ::from ( "f3b4958c-52a1-11e7-802a-010203040506" ) ) ] ) . is_ok ( ) ) ;
}