From 6f5aeb823b411183be134f234435b47867ed4b4c Mon Sep 17 00:00:00 2001 From: brian d foy Date: Mon, 25 Mar 2024 13:37:17 -0400 Subject: [PATCH] Fix tests for #517 - assignment does not print --- t/bc/input.t | 83 ++++++++++++++++++++++++++-------------------------- 1 file changed, 42 insertions(+), 41 deletions(-) diff --git a/t/bc/input.t b/t/bc/input.t index 99553847..e8cdf074 100644 --- a/t/bc/input.t +++ b/t/bc/input.t @@ -42,13 +42,14 @@ sub operator_table { my $table = [ 'operators', [ '-1', '-1', 'negation' ], - [ 'var=12', '12', 'variable assignment' ], - [ 'v=3; ++v', "3\n4", 'prefix increment' ], - [ 'v=3; --v', "3\n2", 'prefix increment' ], - [ 'v=3; v++; v', "3\n3\n4", 'postfix increment' ], - [ 'v=3; v--; v', "3\n3\n2", 'postfix increment' ], - [ 'v=3; v+=5; v', "3\n8\n8", 'postfix increment' ], - [ 'v=5; v-=3; v', "5\n2\n2", 'postfix decrement' ], + [ 'var=12', undef, 'variable assignment' ], + [ 'var=12;var', '12', 'variable assignment and print' ], + [ 'v=3; ++v', undef, 'prefix increment' ], + [ 'v=3; --v', undef, 'prefix increment' ], + [ 'v=3; v++; v', "4", 'postfix increment and print' ], + [ 'v=3; v--; v', "2", 'postfix increment and print' ], + [ 'v=3; v+=5; v', "8", 'postfix increment and print' ], + [ 'v=5; v-=3; v', "2", 'postfix decrement and print' ], [ '1+2', '3', 'addition' ], [ '5-3', '2', 'subtraction' ], [ '3*5', '15', 'multiplication' ], @@ -79,85 +80,85 @@ sub operator_table { [ '7 >= 7', '1', 'greater than or equal' ], [ '7 >= 7', '1', 'greater than or equal' ], [ - "x = 3\nx *= 4", - "3\n12", + "x = 3\nx *= 4\nx", + "12", 'binary assignment (multiplication)' ], [ - "x = 16\nx /= 4", - "16\n4", + "x = 16\nx /= 4\nx", + "4", 'binary assignment (division)' ], [ - "x = 16\nx /= 0.5", - "16\n32", + "x = 16\nx /= 0.5\nx", + "32", 'binary assignment (division by fraction)', ], [ - "x = 16\nx /= 0", + "x = 16\nx /= 0\nx", "16", 'binary assignment (division)', 'Runtime error (func=(main), adr=4): Divide by zero' ], [ - "x = 56\nx %= 17", - "56\n5", + "x = 56\nx %= 17\nx", + "5", 'binary assignment (modulo)' ], [ - "x = 56\nx %= 0.5", + "x = 56\nx %= 0.5\nx", "56", 'binary assignment (modulo fraction 0.5)', 'Runtime error (func=(main), adr=4): Modulo by zero', ], [ - "x = 56\nx %= 1.9", + "x = 56\nx %= 1.9\nx", "56", 'binary assignment (modulo fraction 1.9)', 'Runtime error (func=(main), adr=4): Modulo by zero', 'Need to investigate fractional modulo' ], [ - "x = 56\nx %= 0", + "x = 56\nx %= 0\nx", "56", 'binary assignment (modulo zero)', 'Runtime error (func=(main), adr=4): Modulo by zero', ], [ - "x = 56\nx %= -2", + "x = 56\nx %= -2\nx", "56", 'binary assignment (modulo negative number)', 'Runtime error (func=(main), adr=4): Modulo by zero', 'todo' ], [ - "x = 5\nx ^= 4", - "5\n625", + "x = 5\nx ^= 4\nx", + "625", 'binary assignment (exponentiation)' ], [ - "x = 5\nx ^= 0", - "5\n1", + "x = 5\nx ^= 0\nx", + "1", 'binary assignment (exponentiation - 0 power)' ], [ - "x = 5\nx ^= -1", - "5\n0.2", + "x = 5\nx ^= -1\nx", + "0.2", 'binary assignment (exponentiation - negative power)' ], [ - "x = 5\nx ^= 0.5", - qr/5\n2\.23606/, + "x = 5\nx ^= 0.5\nx", + qr/2\.23606/, 'binary assignment (exponentiation - fractional power)' ], [ - "x = 5\ny = 2\nx ^= y", - "5\n2\n25", + "x = 5\ny = 2\nx ^= y\nx", + "25", 'binary assignment (exponentiation - two variables)' ], [ - "x = -1\ny = 0.5\nx ^= y", - qr/\A-1\n0.5\n-?NaN$/i, # NaN might be -nan + "x = -1\ny = 0.5\nx ^= y\nx", + 'NaN', # NaN might be -nan 'binary assignment (exponentiation - square root of -1)' ], ]; @@ -166,15 +167,15 @@ sub operator_table { sub precedence_table { my $table = [ 'precedence', - [ 'v = (3 < 5)', '1', 'just like gnu bc' ], + [ "v = (3 < 5)\nv", '1', 'just like gnu bc' ], # according to the GNU bc documentation, their implementation # will assign 3 to v and then do the relational test - [ 'v = 3 < 5', '1', ' not like gnu bc' ], + [ "v = 3 < 5\nv", '1', ' not like gnu bc' ], - [ 'v = 4+5*2^3', '44', 'PEDMAS' ], - [ 'v = (4+5)*2', '18', 'PEDMAS' ], - [ 'v = -(4+5)+8', '-1', 'PEDMAS' ], + [ "v = 4+5*2^3\nv", '44', 'PEDMAS' ], + [ "v = (4+5)*2\nv", '18', 'PEDMAS' ], + [ "v = -(4+5)+8\nv", '-1', 'PEDMAS' ], ]; } @@ -220,7 +221,7 @@ sub statement_table { [ 'v=5; while (v--) { print v }; print "\n"', - "5\n43210", + "43210", 'while statement', ], @@ -232,7 +233,7 @@ sub statement_table { [ 'for ( v=0; v<5; v++) { print v; if (v>2) break }; print "\n"', - "01230\n", + "0123\n", 'for with break statement', ], @@ -258,7 +259,7 @@ sub run_table { subtest $label => sub { foreach my $tuple (@$table) { my( $input, $expected, $description, $error, $todo ) = @$tuple; - $expected .= "\n" unless ref $expected; + $expected .= "\n" unless( ! defined $expected or ref $expected ); my ( $fh, $temp_filename ) = tempfile(); print {$fh} $input, "\n"; @@ -268,7 +269,7 @@ sub run_table { TODO: { local $TODO = $todo; if( ! ref $expected ) { - is $output, $expected, $description; + is $output, $expected // '', $description; } elsif( ref $expected eq ref qr// ) { like $output, $expected, $description;