File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -98,3 +98,31 @@ macro_rules! create_context {
9898 ctx
9999 } } ;
100100}
101+
102+ #[ cfg( test) ]
103+ mod tests {
104+ use super :: * ;
105+ use crate :: value:: Value ;
106+
107+ #[ test]
108+ fn test_context_methods ( ) {
109+ let mut ctx = Context :: new ( ) ;
110+ ctx. set_variable ( "var1" , Value :: from ( 42 ) ) ;
111+ ctx. set_func ( "func1" , Arc :: new ( |_| Ok ( Value :: from ( 100 ) ) ) ) ;
112+
113+ // Test get_variable
114+ assert_eq ! ( ctx. get_variable( "var1" ) . unwrap( ) , Value :: from( 42 ) ) ;
115+ assert ! ( ctx. get_variable( "func1" ) . is_none( ) ) ;
116+ assert ! ( ctx. get_variable( "not_found" ) . is_none( ) ) ;
117+
118+ // Test get_func
119+ assert ! ( ctx. get_func( "func1" ) . is_some( ) ) ;
120+ assert ! ( ctx. get_func( "var1" ) . is_none( ) ) ;
121+ assert ! ( ctx. get_func( "not_found" ) . is_none( ) ) ;
122+
123+ // Test value
124+ assert_eq ! ( ctx. value( "var1" ) . unwrap( ) , Value :: from( 42 ) ) ;
125+ assert_eq ! ( ctx. value( "func1" ) . unwrap( ) , Value :: from( 100 ) ) ;
126+ assert_eq ! ( ctx. value( "not_found" ) . unwrap( ) , Value :: None ) ;
127+ }
128+ }
You can’t perform that action at this time.
0 commit comments