@@ -693,126 +693,126 @@ mod tests {
693693
694694 #[ test]
695695 fn test_arith_literals ( ) {
696- let expr = parse_arithmetic ( "42" ) . expect ( "TODO: handle error" ) ;
696+ let expr = parse_arithmetic ( "42" ) . unwrap ( ) ;
697697 assert_eq ! ( expr, ArithExpr :: Literal ( 42 ) ) ;
698698
699- let state = ShellState :: new ( "/tmp" ) . expect ( "TODO: handle error" ) ;
700- assert_eq ! ( eval_arith( & expr, & state) . expect ( "TODO: handle error" ) , 42 ) ;
699+ let state = ShellState :: new ( "/tmp" ) . unwrap ( ) ;
700+ assert_eq ! ( eval_arith( & expr, & state) . unwrap ( ) , 42 ) ;
701701 }
702702
703703 #[ test]
704704 fn test_arith_basic_ops ( ) {
705- let state = ShellState :: new ( "/tmp" ) . expect ( "TODO: handle error" ) ;
705+ let state = ShellState :: new ( "/tmp" ) . unwrap ( ) ;
706706
707- assert_eq ! ( eval_arith( & parse_arithmetic( "5 + 3" ) . expect ( "TODO: handle error" ) , & state) . expect ( "TODO: handle error" ) , 8 ) ;
708- assert_eq ! ( eval_arith( & parse_arithmetic( "10 - 4" ) . expect ( "TODO: handle error" ) , & state) . expect ( "TODO: handle error" ) , 6 ) ;
709- assert_eq ! ( eval_arith( & parse_arithmetic( "6 * 7" ) . expect ( "TODO: handle error" ) , & state) . expect ( "TODO: handle error" ) , 42 ) ;
710- assert_eq ! ( eval_arith( & parse_arithmetic( "20 / 4" ) . expect ( "TODO: handle error" ) , & state) . expect ( "TODO: handle error" ) , 5 ) ;
711- assert_eq ! ( eval_arith( & parse_arithmetic( "17 % 5" ) . expect ( "TODO: handle error" ) , & state) . expect ( "TODO: handle error" ) , 2 ) ;
707+ assert_eq ! ( eval_arith( & parse_arithmetic( "5 + 3" ) . unwrap ( ) , & state) . unwrap ( ) , 8 ) ;
708+ assert_eq ! ( eval_arith( & parse_arithmetic( "10 - 4" ) . unwrap ( ) , & state) . unwrap ( ) , 6 ) ;
709+ assert_eq ! ( eval_arith( & parse_arithmetic( "6 * 7" ) . unwrap ( ) , & state) . unwrap ( ) , 42 ) ;
710+ assert_eq ! ( eval_arith( & parse_arithmetic( "20 / 4" ) . unwrap ( ) , & state) . unwrap ( ) , 5 ) ;
711+ assert_eq ! ( eval_arith( & parse_arithmetic( "17 % 5" ) . unwrap ( ) , & state) . unwrap ( ) , 2 ) ;
712712 }
713713
714714 #[ test]
715715 fn test_arith_precedence ( ) {
716- let state = ShellState :: new ( "/tmp" ) . expect ( "TODO: handle error" ) ;
716+ let state = ShellState :: new ( "/tmp" ) . unwrap ( ) ;
717717
718- assert_eq ! ( eval_arith( & parse_arithmetic( "2 + 3 * 4" ) . expect ( "TODO: handle error" ) , & state) . expect ( "TODO: handle error" ) , 14 ) ;
719- assert_eq ! ( eval_arith( & parse_arithmetic( "(2 + 3) * 4" ) . expect ( "TODO: handle error" ) , & state) . expect ( "TODO: handle error" ) , 20 ) ;
720- assert_eq ! ( eval_arith( & parse_arithmetic( "2 ** 3 + 1" ) . expect ( "TODO: handle error" ) , & state) . expect ( "TODO: handle error" ) , 9 ) ;
721- assert_eq ! ( eval_arith( & parse_arithmetic( "2 ** (3 + 1)" ) . expect ( "TODO: handle error" ) , & state) . expect ( "TODO: handle error" ) , 16 ) ;
718+ assert_eq ! ( eval_arith( & parse_arithmetic( "2 + 3 * 4" ) . unwrap ( ) , & state) . unwrap ( ) , 14 ) ;
719+ assert_eq ! ( eval_arith( & parse_arithmetic( "(2 + 3) * 4" ) . unwrap ( ) , & state) . unwrap ( ) , 20 ) ;
720+ assert_eq ! ( eval_arith( & parse_arithmetic( "2 ** 3 + 1" ) . unwrap ( ) , & state) . unwrap ( ) , 9 ) ;
721+ assert_eq ! ( eval_arith( & parse_arithmetic( "2 ** (3 + 1)" ) . unwrap ( ) , & state) . unwrap ( ) , 16 ) ;
722722 }
723723
724724 #[ test]
725725 fn test_arith_power_right_associative ( ) {
726- let state = ShellState :: new ( "/tmp" ) . expect ( "TODO: handle error" ) ;
726+ let state = ShellState :: new ( "/tmp" ) . unwrap ( ) ;
727727
728728 // 2 ** 3 ** 2 = 2 ** (3 ** 2) = 2 ** 9 = 512
729- assert_eq ! ( eval_arith( & parse_arithmetic( "2 ** 3 ** 2" ) . expect ( "TODO: handle error" ) , & state) . expect ( "TODO: handle error" ) , 512 ) ;
729+ assert_eq ! ( eval_arith( & parse_arithmetic( "2 ** 3 ** 2" ) . unwrap ( ) , & state) . unwrap ( ) , 512 ) ;
730730 }
731731
732732 #[ test]
733733 fn test_arith_comparison ( ) {
734- let state = ShellState :: new ( "/tmp" ) . expect ( "TODO: handle error" ) ;
734+ let state = ShellState :: new ( "/tmp" ) . unwrap ( ) ;
735735
736- assert_eq ! ( eval_arith( & parse_arithmetic( "5 > 3" ) . expect ( "TODO: handle error" ) , & state) . expect ( "TODO: handle error" ) , 1 ) ;
737- assert_eq ! ( eval_arith( & parse_arithmetic( "5 < 3" ) . expect ( "TODO: handle error" ) , & state) . expect ( "TODO: handle error" ) , 0 ) ;
738- assert_eq ! ( eval_arith( & parse_arithmetic( "5 == 5" ) . expect ( "TODO: handle error" ) , & state) . expect ( "TODO: handle error" ) , 1 ) ;
739- assert_eq ! ( eval_arith( & parse_arithmetic( "5 != 3" ) . expect ( "TODO: handle error" ) , & state) . expect ( "TODO: handle error" ) , 1 ) ;
740- assert_eq ! ( eval_arith( & parse_arithmetic( "5 >= 5" ) . expect ( "TODO: handle error" ) , & state) . expect ( "TODO: handle error" ) , 1 ) ;
741- assert_eq ! ( eval_arith( & parse_arithmetic( "5 <= 4" ) . expect ( "TODO: handle error" ) , & state) . expect ( "TODO: handle error" ) , 0 ) ;
736+ assert_eq ! ( eval_arith( & parse_arithmetic( "5 > 3" ) . unwrap ( ) , & state) . unwrap ( ) , 1 ) ;
737+ assert_eq ! ( eval_arith( & parse_arithmetic( "5 < 3" ) . unwrap ( ) , & state) . unwrap ( ) , 0 ) ;
738+ assert_eq ! ( eval_arith( & parse_arithmetic( "5 == 5" ) . unwrap ( ) , & state) . unwrap ( ) , 1 ) ;
739+ assert_eq ! ( eval_arith( & parse_arithmetic( "5 != 3" ) . unwrap ( ) , & state) . unwrap ( ) , 1 ) ;
740+ assert_eq ! ( eval_arith( & parse_arithmetic( "5 >= 5" ) . unwrap ( ) , & state) . unwrap ( ) , 1 ) ;
741+ assert_eq ! ( eval_arith( & parse_arithmetic( "5 <= 4" ) . unwrap ( ) , & state) . unwrap ( ) , 0 ) ;
742742 }
743743
744744 #[ test]
745745 fn test_arith_logical ( ) {
746- let state = ShellState :: new ( "/tmp" ) . expect ( "TODO: handle error" ) ;
746+ let state = ShellState :: new ( "/tmp" ) . unwrap ( ) ;
747747
748- assert_eq ! ( eval_arith( & parse_arithmetic( "1 && 1" ) . expect ( "TODO: handle error" ) , & state) . expect ( "TODO: handle error" ) , 1 ) ;
749- assert_eq ! ( eval_arith( & parse_arithmetic( "1 && 0" ) . expect ( "TODO: handle error" ) , & state) . expect ( "TODO: handle error" ) , 0 ) ;
750- assert_eq ! ( eval_arith( & parse_arithmetic( "1 || 0" ) . expect ( "TODO: handle error" ) , & state) . expect ( "TODO: handle error" ) , 1 ) ;
751- assert_eq ! ( eval_arith( & parse_arithmetic( "0 || 0" ) . expect ( "TODO: handle error" ) , & state) . expect ( "TODO: handle error" ) , 0 ) ;
752- assert_eq ! ( eval_arith( & parse_arithmetic( "!0" ) . expect ( "TODO: handle error" ) , & state) . expect ( "TODO: handle error" ) , 1 ) ;
753- assert_eq ! ( eval_arith( & parse_arithmetic( "!5" ) . expect ( "TODO: handle error" ) , & state) . expect ( "TODO: handle error" ) , 0 ) ;
748+ assert_eq ! ( eval_arith( & parse_arithmetic( "1 && 1" ) . unwrap ( ) , & state) . unwrap ( ) , 1 ) ;
749+ assert_eq ! ( eval_arith( & parse_arithmetic( "1 && 0" ) . unwrap ( ) , & state) . unwrap ( ) , 0 ) ;
750+ assert_eq ! ( eval_arith( & parse_arithmetic( "1 || 0" ) . unwrap ( ) , & state) . unwrap ( ) , 1 ) ;
751+ assert_eq ! ( eval_arith( & parse_arithmetic( "0 || 0" ) . unwrap ( ) , & state) . unwrap ( ) , 0 ) ;
752+ assert_eq ! ( eval_arith( & parse_arithmetic( "!0" ) . unwrap ( ) , & state) . unwrap ( ) , 1 ) ;
753+ assert_eq ! ( eval_arith( & parse_arithmetic( "!5" ) . unwrap ( ) , & state) . unwrap ( ) , 0 ) ;
754754 }
755755
756756 #[ test]
757757 fn test_arith_bitwise ( ) {
758- let state = ShellState :: new ( "/tmp" ) . expect ( "TODO: handle error" ) ;
758+ let state = ShellState :: new ( "/tmp" ) . unwrap ( ) ;
759759
760- assert_eq ! ( eval_arith( & parse_arithmetic( "5 & 3" ) . expect ( "TODO: handle error" ) , & state) . expect ( "TODO: handle error" ) , 1 ) ;
761- assert_eq ! ( eval_arith( & parse_arithmetic( "5 | 3" ) . expect ( "TODO: handle error" ) , & state) . expect ( "TODO: handle error" ) , 7 ) ;
762- assert_eq ! ( eval_arith( & parse_arithmetic( "5 ^ 3" ) . expect ( "TODO: handle error" ) , & state) . expect ( "TODO: handle error" ) , 6 ) ;
763- assert_eq ! ( eval_arith( & parse_arithmetic( "~5" ) . expect ( "TODO: handle error" ) , & state) . expect ( "TODO: handle error" ) , -6 ) ;
764- assert_eq ! ( eval_arith( & parse_arithmetic( "8 << 2" ) . expect ( "TODO: handle error" ) , & state) . expect ( "TODO: handle error" ) , 32 ) ;
765- assert_eq ! ( eval_arith( & parse_arithmetic( "8 >> 2" ) . expect ( "TODO: handle error" ) , & state) . expect ( "TODO: handle error" ) , 2 ) ;
760+ assert_eq ! ( eval_arith( & parse_arithmetic( "5 & 3" ) . unwrap ( ) , & state) . unwrap ( ) , 1 ) ;
761+ assert_eq ! ( eval_arith( & parse_arithmetic( "5 | 3" ) . unwrap ( ) , & state) . unwrap ( ) , 7 ) ;
762+ assert_eq ! ( eval_arith( & parse_arithmetic( "5 ^ 3" ) . unwrap ( ) , & state) . unwrap ( ) , 6 ) ;
763+ assert_eq ! ( eval_arith( & parse_arithmetic( "~5" ) . unwrap ( ) , & state) . unwrap ( ) , -6 ) ;
764+ assert_eq ! ( eval_arith( & parse_arithmetic( "8 << 2" ) . unwrap ( ) , & state) . unwrap ( ) , 32 ) ;
765+ assert_eq ! ( eval_arith( & parse_arithmetic( "8 >> 2" ) . unwrap ( ) , & state) . unwrap ( ) , 2 ) ;
766766 }
767767
768768 #[ test]
769769 fn test_arith_variables ( ) {
770- let mut state = ShellState :: new ( "/tmp" ) . expect ( "TODO: handle error" ) ;
770+ let mut state = ShellState :: new ( "/tmp" ) . unwrap ( ) ;
771771 state. set_variable ( "x" , "5" ) ;
772772 state. set_variable ( "y" , "10" ) ;
773773
774- assert_eq ! ( eval_arith( & parse_arithmetic( "x + y" ) . expect ( "TODO: handle error" ) , & state) . expect ( "TODO: handle error" ) , 15 ) ;
775- assert_eq ! ( eval_arith( & parse_arithmetic( "x * 2 + y" ) . expect ( "TODO: handle error" ) , & state) . expect ( "TODO: handle error" ) , 20 ) ;
774+ assert_eq ! ( eval_arith( & parse_arithmetic( "x + y" ) . unwrap ( ) , & state) . unwrap ( ) , 15 ) ;
775+ assert_eq ! ( eval_arith( & parse_arithmetic( "x * 2 + y" ) . unwrap ( ) , & state) . unwrap ( ) , 20 ) ;
776776 }
777777
778778 #[ test]
779779 fn test_arith_undefined_variable ( ) {
780- let state = ShellState :: new ( "/tmp" ) . expect ( "TODO: handle error" ) ;
780+ let state = ShellState :: new ( "/tmp" ) . unwrap ( ) ;
781781
782782 // Undefined variables should be treated as 0
783- assert_eq ! ( eval_arith( & parse_arithmetic( "undefined_var + 5" ) . expect ( "TODO: handle error" ) , & state) . expect ( "TODO: handle error" ) , 5 ) ;
783+ assert_eq ! ( eval_arith( & parse_arithmetic( "undefined_var + 5" ) . unwrap ( ) , & state) . unwrap ( ) , 5 ) ;
784784 }
785785
786786 #[ test]
787787 fn test_arith_division_by_zero ( ) {
788- let state = ShellState :: new ( "/tmp" ) . expect ( "TODO: handle error" ) ;
788+ let state = ShellState :: new ( "/tmp" ) . unwrap ( ) ;
789789
790- assert ! ( eval_arith( & parse_arithmetic( "5 / 0" ) . expect ( "TODO: handle error" ) , & state) . is_err( ) ) ;
791- assert ! ( eval_arith( & parse_arithmetic( "5 % 0" ) . expect ( "TODO: handle error" ) , & state) . is_err( ) ) ;
790+ assert ! ( eval_arith( & parse_arithmetic( "5 / 0" ) . unwrap ( ) , & state) . is_err( ) ) ;
791+ assert ! ( eval_arith( & parse_arithmetic( "5 % 0" ) . unwrap ( ) , & state) . is_err( ) ) ;
792792 }
793793
794794 #[ test]
795795 fn test_arith_nested ( ) {
796- let state = ShellState :: new ( "/tmp" ) . expect ( "TODO: handle error" ) ;
796+ let state = ShellState :: new ( "/tmp" ) . unwrap ( ) ;
797797
798- assert_eq ! ( eval_arith( & parse_arithmetic( "((5 + 3) * 2) + 1" ) . expect ( "TODO: handle error" ) , & state) . expect ( "TODO: handle error" ) , 17 ) ;
799- assert_eq ! ( eval_arith( & parse_arithmetic( "2 ** (3 ** 2)" ) . expect ( "TODO: handle error" ) , & state) . expect ( "TODO: handle error" ) , 512 ) ;
798+ assert_eq ! ( eval_arith( & parse_arithmetic( "((5 + 3) * 2) + 1" ) . unwrap ( ) , & state) . unwrap ( ) , 17 ) ;
799+ assert_eq ! ( eval_arith( & parse_arithmetic( "2 ** (3 ** 2)" ) . unwrap ( ) , & state) . unwrap ( ) , 512 ) ;
800800 }
801801
802802 #[ test]
803803 fn test_arith_unary_minus ( ) {
804- let state = ShellState :: new ( "/tmp" ) . expect ( "TODO: handle error" ) ;
804+ let state = ShellState :: new ( "/tmp" ) . unwrap ( ) ;
805805
806- assert_eq ! ( eval_arith( & parse_arithmetic( "-5" ) . expect ( "TODO: handle error" ) , & state) . expect ( "TODO: handle error" ) , -5 ) ;
807- assert_eq ! ( eval_arith( & parse_arithmetic( "-(5 + 3)" ) . expect ( "TODO: handle error" ) , & state) . expect ( "TODO: handle error" ) , -8 ) ;
808- assert_eq ! ( eval_arith( & parse_arithmetic( "10 + -5" ) . expect ( "TODO: handle error" ) , & state) . expect ( "TODO: handle error" ) , 5 ) ;
806+ assert_eq ! ( eval_arith( & parse_arithmetic( "-5" ) . unwrap ( ) , & state) . unwrap ( ) , -5 ) ;
807+ assert_eq ! ( eval_arith( & parse_arithmetic( "-(5 + 3)" ) . unwrap ( ) , & state) . unwrap ( ) , -8 ) ;
808+ assert_eq ! ( eval_arith( & parse_arithmetic( "10 + -5" ) . unwrap ( ) , & state) . unwrap ( ) , 5 ) ;
809809 }
810810
811811 #[ test]
812812 fn test_arith_whitespace ( ) {
813- let state = ShellState :: new ( "/tmp" ) . expect ( "TODO: handle error" ) ;
813+ let state = ShellState :: new ( "/tmp" ) . unwrap ( ) ;
814814
815- assert_eq ! ( eval_arith( & parse_arithmetic( " 5 + 3 " ) . expect ( "TODO: handle error" ) , & state) . expect ( "TODO: handle error" ) , 8 ) ;
816- assert_eq ! ( eval_arith( & parse_arithmetic( "( ( 5 + 3 ) * 2 )" ) . expect ( "TODO: handle error" ) , & state) . expect ( "TODO: handle error" ) , 16 ) ;
815+ assert_eq ! ( eval_arith( & parse_arithmetic( " 5 + 3 " ) . unwrap ( ) , & state) . unwrap ( ) , 8 ) ;
816+ assert_eq ! ( eval_arith( & parse_arithmetic( "( ( 5 + 3 ) * 2 )" ) . unwrap ( ) , & state) . unwrap ( ) , 16 ) ;
817817 }
818818}
0 commit comments