konstantinvlasenko / PowerSlim

Fitnesse Slim implementation in PowerShell. PowerSlim makes it possible to use PowerShell in the acceptance testing
powerslim.org
GNU General Public License v3.0
48 stars 21 forks source link

function Is-Numeric ($Value) issue in client.ps1 #86

Closed lonestep closed 7 years ago

lonestep commented 8 years ago

function Is-Numeric ($Value) { return $Value -match "^[\d.]+$" }

We have a version string like: 11.2.0.2888 It's been judged as "Int32" and lead to an exception, the cause is this function "Is-Numeric"

PS C:\ITSearch> Is-Numeric "1.2.3" True PS C:\ITSearch> Is-Numeric 5e3 False

my suggestion is:

function Is-Numeric ($Value) { try{ (Invoke-Expression $Value).GetType().Name -match 'byte|short|int32|long|sbyte|ushort|uint32|ulong|float|double|decimal' } catch{ return $false} }

lonestep commented 8 years ago

OR simply : $Value -match "^[\d]+\.*[\d]*$"