Skip to content

Commit 7607e01

Browse files
authored
Merge branch 'openwebwork:develop' into develop
2 parents 31a9e8a + bab8339 commit 7607e01

File tree

8 files changed

+51
-39
lines changed

8 files changed

+51
-39
lines changed

htdocs/package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

htdocs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"prettier-check": "prettier --ignore-path=../.gitignore --check \"**/*.{js,css,scss,html}\" \"../**/*.dist.yml\""
1414
},
1515
"dependencies": {
16-
"@openwebwork/mathquill": "^0.11.0",
16+
"@openwebwork/mathquill": "^0.11.1",
1717
"jsxgraph": "^1.11.1",
1818
"jszip": "^3.10.1",
1919
"jszip-utils": "^0.1.0",

lib/Parser/Legacy/NumberWithUnits.pm

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ sub splitUnits {
9292
: $aUnit . '(?:\s*[/* ]\s*' . $aUnit . ')*';
9393
$unitPattern = $unitPattern . '(?:\/' . $unitPattern . ')*' if $parseMathQuill;
9494
my $unitSpace = "($aUnit) +($aUnit)";
95-
my ($num, $units) = $string =~ m!^(.*?(?:[)}\]0-9a-z]|\d\.))\s*($unitPattern)\s*$!;
95+
my ($num, $units) = $string =~ m!^(.*?(?:[)}\]0-9a-z]|\d\.))?\s*($unitPattern)\s*$!;
9696
if ($units) {
9797
while ($units =~ s/$unitSpace/$1*$2/) { }
9898
$units =~ s/ //g;
@@ -238,20 +238,26 @@ sub unitsPreFilter {
238238
$ans->{correct_value}{context}
239239
&& $ans->{correct_value}->context->flag('useMathQuill')
240240
&& (!defined $ans->{mathQuillOpts} || $ans->{mathQuillOpts} !~ /^\s*disabled\s*$/i));
241+
if (defined($units) && $units ne '' && $num eq '') {
242+
$self->cmp_Error($ans, "Units must follow a number");
243+
$ans->{unit_error} = $ans->{ans_message};
244+
$ans->{student_ans} = '';
245+
return $ans;
246+
}
241247
unless (defined($num) && defined($units) && $units ne '') {
242248
$self->cmp_Error($ans, "Your answer doesn't look like " . lc($self->cmp_class));
243-
$ans->{error_flag} = 'UNITS_NONE';
249+
$ans->{unit_error} = $ans->{ans_message};
244250
return $ans;
245251
}
246252
if ($units =~ m!/.*/!) {
247253
$self->cmp_Error($ans, "Your units can only contain one division");
248-
$ans->{error_flag} = 'UNITS_DIVISION';
254+
$ans->{unit_error} = $ans->{ans_message};
249255
return $ans;
250256
}
251257
my $ref = { getUnits($units) };
252258
if ($ref->{ERROR}) {
253259
$self->cmp_Error($ans, $ref->{ERROR});
254-
$ans->{error_flag} = 'UNITS_BAD';
260+
$ans->{unit_error} = $ans->{ans_message};
255261
return $ans;
256262
}
257263
$ans->{units} = $units;
@@ -263,6 +269,14 @@ sub cmp_preprocess {
263269
my $self = shift;
264270
my $ans = shift;
265271

272+
if ($ans->{unit_error}) {
273+
$ans->{ans_message} = $ans->{error_message} = $ans->{unit_error};
274+
if ($ans->{student_ans} eq '') {
275+
$ans->{student_ans} = $ans->{original_student_ans};
276+
$ans->{preview_latex_string} = TeXunits($ans->{student_ans});
277+
}
278+
return;
279+
}
266280
my $units = $ans->{units};
267281
return $ans unless $units;
268282
$ans->{student_ans} .= " " . $units;
@@ -272,8 +286,8 @@ sub cmp_preprocess {
272286
if (!defined($ans->{student_value}) || $self->checkStudentValue($ans->{student_value})) {
273287
$ans->{student_value} = undef;
274288
$ans->score(0);
275-
$ans->{error_flag} = 'UNITS_NO_NUMBER';
276289
$self->cmp_Error($ans, "Units must follow a number");
290+
$ans->{unit_error} = $ans->{ans_message};
277291
return;
278292
}
279293

@@ -284,7 +298,7 @@ sub cmp_preprocess {
284298
sub cmp_equal {
285299
my $self = shift;
286300
my $ans = shift;
287-
if (!$ans->{error_flag}) {
301+
if (!$ans->{unit_error}) {
288302
my $meth = @{ ref($self) . '::ISA' }[-1] . '::cmp_equal';
289303
$meth = 'Value::cmp_equal' unless defined &$meth;
290304
&$meth($self, $ans, @_);
@@ -298,7 +312,6 @@ sub cmp_postprocess {
298312
$self->cmp_Error($ans, "The units for your answer are not correct")
299313
unless $ans->{correct_value}->uPowers eq $ans->{student_value}->uPowers;
300314
}
301-
$ans->{error_flag} = undef if $ans->{error_flag} =~ m/^UNITS_/;
302315
return $ans;
303316
}
304317

@@ -350,7 +363,7 @@ sub makeValue {
350363
my $value = shift;
351364
my %options = (context => $self->context, @_);
352365
my $num = Value::makeValue($value, %options);
353-
return bless $num, 'Parser::Legacy::FormulaWithUnits' if $num->classMatch('Formula');
366+
return bless $num, 'Parser::Legacy::FormulaWithUnits' if defined $num && $num->classMatch('Formula');
354367
Value::Error("A number with units must be a constant, not %s", lc(Value::showClass($num)))
355368
unless Value::isReal($num);
356369
bless $num, $options{class};

lib/Value/AnswerChecker.pm

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -555,57 +555,57 @@ sub format_matrix_HTML {
555555
my ($rows, $cols) = (scalar(@{$array}), scalar(@{ $array->[0] }));
556556
my $HTML = "";
557557
my $class = 'class="ans_array_cell"';
558-
my $cell = "display:table-cell;vertical-align:middle;";
558+
my $cell = "display:table-cell;vertical-align:middle;text-align:center;";
559559
my $pad = "padding:4px 0;";
560-
if ($sep) { $sep = '<span class="ans_array_sep" style="' . $cell . 'padding:0 2px">' . $sep . '</span>' }
561-
else { $sep = '<span class="ans_array_sep" style="' . $cell . 'width:8px"></span>' }
562-
$sep = '</span>' . $sep . '<span ' . $class . ' style="' . $cell . $pad . '">';
560+
if ($sep) { $sep = '<div class="ans_array_sep" style="' . $cell . 'padding:0 2px">' . $sep . '</div>' }
561+
else { $sep = '<div class="ans_array_sep" style="' . $cell . 'width:8px"></div>' }
562+
$sep = '</div>' . $sep . '<div ' . $class . ' style="' . $cell . $pad . '">';
563563

564564
if ($options{top_labels}) {
565565
$HTML .=
566-
'<span style="display:table-row"><span '
566+
'<div style="display:table-row"><div '
567567
. $class
568568
. ' style="'
569569
. $cell
570570
. $pad . '">'
571571
. join($sep, @{ $options{top_labels} })
572-
. '</span></span>';
572+
. '</div></div>';
573573
}
574574
foreach my $i (0 .. $rows - 1) {
575575
$HTML .=
576-
'<span style="display:table-row"><span '
576+
'<div style="display:table-row"><div '
577577
. $class
578578
. ' style="'
579579
. $cell
580580
. $pad . '">'
581581
. join($sep, EVALUATE(@{ $array->[$i] }))
582-
. '</span></span>';
582+
. '</div></div>';
583583
}
584-
$HTML = '<span class="ans_array_table" style="display:inline-table; vertical-align:middle">' . $HTML . '</span>';
584+
$HTML = '<div class="ans_array_table" style="display:inline-table; vertical-align:middle">' . $HTML . '</div>';
585585
$open = $self->format_delimiter($open, $rows, $options{tth_delims});
586586
$close = $self->format_delimiter($close, $rows, $options{tth_delims});
587587
if ($open ne '' || $close ne '') {
588588
my $delim = "display:inline-block; vertical-align:middle;";
589589
$HTML =
590-
'<span class="ans_array_open" style="'
590+
'<div class="ans_array_open" style="'
591591
. $delim
592592
. ' margin-right:4px">'
593593
. $open
594-
. '</span>'
594+
. '</div>'
595595
. $HTML
596-
. '<span class="ans_array_close" style="'
596+
. '<div class="ans_array_close" style="'
597597
. $delim
598598
. ' margin-left:4px">'
599599
. $close
600-
. '</span>';
600+
. '</div>';
601601
}
602-
return '<span class="ans_array" style="display:inline-block;vertical-align:.5ex"'
602+
return '<div class="ans_array" style="display:inline-block;vertical-align:.5ex"'
603603
. ($options{ans_last_name}
604604
? qq{ data-feedback-insert-element="$options{ans_last_name}" data-feedback-insert-method="append_content"}
605605
: '')
606606
. '>'
607607
. $HTML
608-
. '</span>';
608+
. '</div>';
609609
}
610610

611611
sub EVALUATE {

macros/parsers/parserCheckboxList.pl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ =head1 DESCRIPTION
158158
the literal correct answer, not an index to it. Default: 0
159159
160160
=item C<S<< showInStatic => 0 or 1 >>>
161+
161162
In static output, such as PDF or PTX, this controls whether or not
162163
the list of answer options is displayed. (The text preceding the list
163164
of answer options might make printing the answer option list

macros/parsers/parserMultiAnswer.pl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,9 @@ sub cmp {
104104
}
105105

106106
if ($self->{allowBlankAnswers}) {
107+
my $blankCheck = AnswerEvaluator->new()->{pre_filters}[0][0];
107108
foreach my $cmp (@{ $self->{cmp} }) {
108-
$cmp->install_pre_filter('erase');
109+
$cmp->{pre_filters} = [ grep { $_->[0] != $blankCheck } @{ $cmp->{pre_filters} } ];
109110
$cmp->install_pre_filter(sub {
110111
my $ans = shift;
111112
$ans->{student_ans} =~ s/^\s+//g;

macros/parsers/parserRadioMultiAnswer.pl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,9 +354,10 @@ sub cmp {
354354
}
355355

356356
if ($self->{allowBlankAnswers}) {
357+
my $blankCheck = AnswerEvaluator->new()->{pre_filters}[0][0];
357358
for (@{ $self->{cmp} }) {
358359
for my $cmp (@$_) {
359-
$cmp->install_pre_filter('erase');
360+
$cmp->{pre_filters} = [ grep { $_->[0] != $blankCheck } @{ $cmp->{pre_filters} } ];
360361
$cmp->install_pre_filter(sub {
361362
my $ans = shift;
362363
$ans->{student_ans} =~ s/^\s+//g;

t/units/basic_parser.t

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,8 @@ subtest 'Test error handling' => sub {
9595
qr/Unrecognizable unit: \|$fake\|/,
9696
"No unit '$fake' defined in Units file"
9797
);
98-
like(dies { NumberWithUnits(1) }, qr/You must provide units for your number/, 'No unit given');
99-
like(
100-
dies { NumberWithUnits('J') },
101-
qr/You must provide units for your number/,
102-
'No value given, wants 2 arguments'
103-
);
98+
like(dies { NumberWithUnits(1) }, qr/You must provide units for your number/, 'No unit given');
99+
like(dies { NumberWithUnits('J') }, qr/A number with units must be a constant, not ''/, 'No value given');
104100
};
105101

106102
subtest 'Check parsing of arguments' => sub {

0 commit comments

Comments
 (0)