Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
awit-frameworks
awit-perl-toolkit
Commits
706fa1e3
Commit
706fa1e3
authored
Sep 19, 2016
by
Nigel Kukard
Browse files
Merge branch 'isboolean-update-master' into 'master'
Improved isbooleanize() See merge request
!12
parents
15c2714c
107106f1
Pipeline
#264
passed with stages
in 1 minute and 46 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
lib/AWITPT/Util.pm
View file @
706fa1e3
...
...
@@ -374,10 +374,10 @@ sub isBoolean
$var
=~
s/\s//g
;
# Allow true, on, set, enabled, 1, false, off, unset, disabled, 0
if
(
$var
=~
/^(?:true|on|set|enabled|1)$/i
)
{
if
(
$var
=~
/^(?:true|on|set|enabled|
yes|
1)$/i
)
{
return
1
;
}
if
(
$var
=~
/^(?:false|off|unset|disabled|0)$/i
)
{
if
(
$var
=~
/^(?:false|off|unset|disabled|
no|
0)$/i
)
{
return
0
;
}
...
...
t/isboolean.t
0 → 100644
View file @
706fa1e3
# Test harness for isboolean
# Copyright (C) 2014-2016, AllWorldIT
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
use
Test::
More
;
use
strict
;
use
warnings
;
use
AWITPT::
Util
;
is
(
isBoolean
(
0
),
0
,"
isBoolean of 0 should return 0
");
is
(
isBoolean
("
0
"),
0
,"
isBoolean of '0' should return 0
");
is
(
isBoolean
("
00
"),
undef
,"
isBoolean of '00' should return undef
");
is
(
isBoolean
(
1
),
1
,"
isBoolean of 1 should return 1
");
is
(
isBoolean
("
1
"),
1
,"
isBoolean of '1' should return 1
");
is
(
isBoolean
("
11
"),
undef
,"
isBoolean of '11' should return undef
");
is
(
isBoolean
("
-1
"),
undef
,"
isBoolean of '-1' should return undef
");
is
(
isBoolean
("
-0
"),
undef
,"
isBoolean of '-0' should return undef
");
is
(
isBoolean
("
a
"),
undef
,"
isBoolean of 'a' should return undef
");
is
(
isBoolean
("
0a
"),
undef
,"
isBoolean of 'a' should return undef
");
is
(
isBoolean
("
a0
"),
undef
,"
isBoolean of 'a' should return undef
");
is
(
isBoolean
("
TruE
"),
1
,"
isBoolean of 'TruE' should return 1
");
is
(
isBoolean
("
falsE
"),
0
,"
isBoolean of 'falsE' should return 0
");
is
(
isBoolean
("
oN
"),
1
,"
isBoolean of 'oN' should return 1
");
is
(
isBoolean
("
oFf
"),
0
,"
isBoolean of 'oFf' should return 0
");
is
(
isBoolean
("
SeT
"),
1
,"
isBoolean of 'SeT' should return 1
");
is
(
isBoolean
("
unSeT
"),
0
,"
isBoolean of 'unSeT' should return 0
");
is
(
isBoolean
("
EnAblED
"),
1
,"
isBoolean of 'EnAblED' should return 1
");
is
(
isBoolean
("
disabled
"),
0
,"
isBoolean of 'disabled' should return 0
");
is
(
isBoolean
("
yes
"),
1
,"
isBoolean of 'yes' should return 1
");
is
(
isBoolean
("
no
"),
0
,"
isBoolean of 'yes' should return 0
");
is
(
isBoolean
(
1
),
1
,"
isBoolean of 1 should return 1
");
is
(
isBoolean
("
1
"),
1
,"
isBoolean of '1' should return 1
");
done_testing
();
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment