Skip to content

Commit c43ada9

Browse files
Fix negative value handling in Read-LuaHexFloat and Read-LuaNumber; improve formatting in Lua.Tests
1 parent 9f0a48a commit c43ada9

5 files changed

Lines changed: 16 additions & 15 deletions

File tree

src/functions/private/Read-LuaHexFloat.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
}
4949

5050
$result = ($intPart + $fracValue) * [Math]::Pow(2, $exponent)
51-
if ($isNegative) { $result = -$result }
51+
if ($isNegative) { $result = (-$result) }
5252
return $result
5353
}
5454

src/functions/private/Read-LuaNumber.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@
106106
$numStr.Substring(2)
107107
}
108108
$longVal = [Convert]::ToInt64($hexPart, 16)
109-
if ($isNegative) { $longVal = -$longVal }
109+
if ($isNegative) { $longVal = (-$longVal) }
110110
if ($longVal -ge [int]::MinValue -and
111111
$longVal -le [int]::MaxValue) {
112112
return [int]$longVal

src/functions/private/Read-LuaValue.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@
4848
# Number or negative number
4949
if ($char -match '[0-9]' -or
5050
($char -eq '-' -and
51-
$script:luaPos + 1 -lt $script:luaString.Length -and
52-
$script:luaString[$script:luaPos + 1] -match '[0-9.]')) {
51+
$script:luaPos + 1 -lt $script:luaString.Length -and
52+
$script:luaString[$script:luaPos + 1] -match '[0-9.]')) {
5353
return Read-LuaNumber
5454
}
5555

src/functions/public/Lua/ConvertFrom-Lua.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
https://www.lua.org/manual/5.4/manual.html#3.4.9
5959
#>
6060
[OutputType([object])]
61+
[OutputType([System.Array])]
6162
[CmdletBinding()]
6263
param(
6364
# The Lua table constructor string to convert to a PowerShell object.

tests/Lua.Tests.ps1

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,21 +1006,21 @@ Describe 'Round-trip conversion' {
10061006
It 'Round-trips a full config-like structure (5+ levels)' {
10071007
$original = [ordered]@{
10081008
app = [ordered]@{
1009-
name = 'MyApp'
1009+
name = 'MyApp'
10101010
version = '2.0'
10111011
modules = [ordered]@{
10121012
auth = [ordered]@{
1013-
enabled = $true
1013+
enabled = $true
10141014
provider = [ordered]@{
1015-
type = 'oauth'
1015+
type = 'oauth'
10161016
settings = [ordered]@{
10171017
clientId = 'abc123'
1018-
scopes = @('read', 'write', 'admin')
1018+
scopes = @('read', 'write', 'admin')
10191019
}
10201020
}
10211021
}
10221022
logging = [ordered]@{
1023-
level = 'info'
1023+
level = 'info'
10241024
outputs = @(
10251025
[ordered]@{ type = 'console'; colored = $true },
10261026
[ordered]@{ type = 'file'; path = '/var/log/app.log' }
@@ -1104,8 +1104,8 @@ Describe 'Round-trip conversion' {
11041104

11051105
It 'Round-trips strings with special characters' {
11061106
$original = [ordered]@{
1107-
escaped = "line1`nline2`ttab"
1108-
quoted = 'she said "hi"'
1107+
escaped = "line1`nline2`ttab"
1108+
quoted = 'she said "hi"'
11091109
backslash = 'C:\path\to\file'
11101110
}
11111111
$lua = ConvertTo-Lua -InputObject $original -Depth 5
@@ -1118,8 +1118,8 @@ Describe 'Round-trip conversion' {
11181118
It 'Round-trips unicode strings' {
11191119
$original = [ordered]@{
11201120
greeting = 'Héllo Wörld'
1121-
emoji = 'test'
1122-
cjk = '日本語'
1121+
emoji = 'test'
1122+
cjk = '日本語'
11231123
}
11241124
$lua = ConvertTo-Lua -InputObject $original -Depth 5
11251125
$result = ConvertFrom-Lua -InputObject $lua -AsHashtable
@@ -1130,14 +1130,14 @@ Describe 'Round-trip conversion' {
11301130
It 'Round-trips deeply nested array-of-objects-with-arrays' {
11311131
$original = @(
11321132
[ordered]@{
1133-
name = 'group1'
1133+
name = 'group1'
11341134
items = @(
11351135
[ordered]@{ id = 1; tags = @('a', 'b') },
11361136
[ordered]@{ id = 2; tags = @('c') }
11371137
)
11381138
},
11391139
[ordered]@{
1140-
name = 'group2'
1140+
name = 'group2'
11411141
items = @(
11421142
[ordered]@{ id = 3; tags = @('d', 'e', 'f') }
11431143
)

0 commit comments

Comments
 (0)