From a67305eb17c7660be569899f5a812df19ae695fe Mon Sep 17 00:00:00 2001 From: StefanStrobel <> Date: Thu, 31 Dec 2020 13:52:24 +0000 Subject: [PATCH] 98_HTTPMOD: updated tests for HTTPMOD and its utils git-svn-id: https://svn.fhem.de/fhem/trunk@23444 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/t/FHEM/98_HTTPMOD/31_Regexes.t | 12 +++++++++++- fhem/t/FHEM/98_HTTPMOD/99_evalExpr.t | 19 ++++++++++++++----- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/fhem/t/FHEM/98_HTTPMOD/31_Regexes.t b/fhem/t/FHEM/98_HTTPMOD/31_Regexes.t index c4fc2b53a..97b22be20 100644 --- a/fhem/t/FHEM/98_HTTPMOD/31_Regexes.t +++ b/fhem/t/FHEM/98_HTTPMOD/31_Regexes.t @@ -21,7 +21,7 @@ $modVersion =~ /^([0-9]+)\./; my $major = $1; if ($major && $major >= 4) { - plan tests => 13; + plan tests => 14; } else { plan skip_all => "This test only works for HTTPMOD version 4 or later, installed is $modVersion"; } @@ -47,6 +47,16 @@ is(FhemTestUtils_gotLog(qr/H2: reading20Regex Regex: Bad regexp/), 2, "validatio fhem('set H3 reread'); is(FhemTestUtils_gotEvent(qr/H3:TestReading:\s466/xms), 1, "preProcessRegex"); +FhemTestUtils_resetEvents(); +FhemTestUtils_resetLogs(); + +fhem('attr H1 reading01DeleteIfUnmatched 1'); +fhem('attr H1 reading01Regex \"SampleColor\",\"([^\"]+)\"'); +fhem('set H1 reread'); + +is(FhemTestUtils_gotLog('delete reading TestReading1'), 1, "DeleteIfUnmatched"); + + fhem('set H4 reread'); InternalTimer(time()+1, sub() { diff --git a/fhem/t/FHEM/98_HTTPMOD/99_evalExpr.t b/fhem/t/FHEM/98_HTTPMOD/99_evalExpr.t index 556b03b98..807c2934f 100644 --- a/fhem/t/FHEM/98_HTTPMOD/99_evalExpr.t +++ b/fhem/t/FHEM/98_HTTPMOD/99_evalExpr.t @@ -1,5 +1,5 @@ ############################################## -# test evalExpr Util function +# test evalExpr and other Util functions ############################################## use strict; use warnings; @@ -14,22 +14,31 @@ my @array = (1,2,3); my %tHash = (a => 10, b => 20); my $exp = '$val * 2'; -my $result = EvalExpr($hash, $exp, {'$val' => $val, '@array' => \@array}); +my $result = EvalExpr($hash, {expr => $exp, '$val' => $val, '@array' => \@array}); #Log3 $name, 3, "$name: result of EvalExpr test 1 = $result"; is $result, 10, "simple expression with one scalar in list"; $exp = '$array[1] * 2'; -$result = EvalExpr($hash, $exp, {'$val' => $val, '@array' => \@array}); +$result = EvalExpr($hash, {expr => $exp, '$val' => $val, '@array' => \@array}); is $result, 4, "simple expression with array ref in hash"; $exp = '$hash{a} * 2'; -$result = EvalExpr($hash, $exp, {'$val' => $val, '%hash' => \%tHash}); +$result = EvalExpr($hash, {expr => $exp, '$val' => $val, '%hash' => \%tHash}); is $result, 20, "simple expression with hash ref in hash"; $exp = '$hash->{a} * 2'; -$result = EvalExpr($hash, $exp, {'$val' => $val, '$hash' => \%tHash}); +$result = EvalExpr($hash, {expr => $exp, '$val' => $val, '$hash' => \%tHash}); is $result, 20, "simple expression with hash ref as ref in hash"; +my $format = ''; +$val = undef; +$result = FormatVal($hash, {val => $val, format => $format}); +is $result, undef, "FormatVal with empty format and undef value"; + +$format = '%.2f'; +$result = FormatVal($hash, {val => $val, format => $format}); +is $result, "0.00", "FormatVal with empty format and undef value"; + done_testing; exit(0);