Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix extra space being added after the minus sign of negative values #6

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ There are a couple of extra options to pass with the minifier:
* Fix incorrect spacing for double operators, minor bugfixes
* [0.0.3](https://github.com/klaashoekstra94/heishamon_rules_minify/releases/tag/v0.0.3)
* Add option to only remove comments
* [0.0.4](https://github.com/klaashoekstra94/heishamon_rules_minify/releases/tag/v0.0.4)
* Fix extra space being added after the minus sign of negative values

## Contributing

Expand Down
2 changes: 1 addition & 1 deletion src/heishamon_rules_minify/minifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def _fix_spaces_around_operators(text):
flags=re.MULTILINE,
)
text = re.sub(
r"(?<![=<>(,])(?<![=<>(,] ) *- *(?=-*\d|[(#$@%?].+(;|then|end|$))", " - ", text, flags=re.MULTILINE
r"(?<![=<>(,\-+%*\/^])(?<![=<>(,\-+%*\/^] ) *- *(?=-*\d|[(#$@%?].+(;|then|end|$))", " - ", text, flags=re.MULTILINE
)
text = re.sub(r" *% *(?=-*\d|[(#$@%?].+(;|then|end|$))", " % ", text, flags=re.MULTILINE)

Expand Down
26 changes: 23 additions & 3 deletions tests/test_minifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,19 @@
$someValue = 1;
$SomeValue = 2;
$SoveValue3 = 3;
$SomeValuee = 4;
$SomeValuee = -4;
setTimer(3, 60);
end

on timer=4 then
-- Check not adding an extra space after a minus sign
#RoomTempControl = round(#RoomTempDelta + -3);
#RoomTempControl = round(#RoomTempDelta - -3);
#RoomTempControl = round(#RoomTempDelta / -3);
#RoomTempControl = round(#RoomTempDelta * -3);
#RoomTempControl = round(#RoomTempDelta % -3);
#RoomTempControl = round(#RoomTempDelta ^ -3);
end
"""


Expand All @@ -128,7 +138,8 @@ def test_minifier():
on SQM then if #ASQM == 1 then if isset(@Outside_Temp) && isset(@Heatpump_State) then if #QMH == 1 then if @Outside_Temp < 13 then #QM = 1;else #QM = 2;end if @Outside_Temp < 8 then #QM = 0;end if @Outside_Temp < 2 then if %hour > 22 || %hour < 7 then #QM = 1;else #QM = 0;end end if #QMP != #QM && @Heatpump_State == 1 then setTimer(2,900);#QMH = 0;#QMP = #QM;@SetQuietMode = #QM;end end end end end
on ?roomTemp then $M = 0.25;$S = ?roomTempSet;if ?roomTemp > ($S + $M) then if @Heatpump_State == 1 then @SetHeatpump = 0;end else if ?roomTemp < ($S - $M) then if @Heatpump_State == 0 then @SetHeatpump = 1;end else @SetZ1HeatRequestTemperature = round(#HWSTS);end end end
on timer=2 then #QMH = 1;#QM = 0;end
on timer=3 then $S1 = 0;$SV = 1;$SV1 = 2;$SV3 = 3;$SV2 = 4;setTimer(3,60);end
on timer=3 then $S1 = 0;$SV = 1;$SV1 = 2;$SV3 = 3;$SV2 = -4;setTimer(3,60);end
on timer=4 then #RTC = round(#RTD + -3);#RTC = round(#RTD - -3);#RTC = round(#RTD / -3);#RTC = round(#RTD * -3);#RTC = round(#RTD % -3);#RTC = round(#RTD ^ -3);end
"""
output = Minifier.minify(input_text)
assert output == expected_output
Expand Down Expand Up @@ -222,9 +233,18 @@ def test_minifier_comments_only():
$someValue = 1;
$SomeValue = 2;
$SoveValue3 = 3;
$SomeValuee = 4;
$SomeValuee = -4;
setTimer(3, 60);
end

on timer=4 then
#RoomTempControl = round(#RoomTempDelta + -3);
#RoomTempControl = round(#RoomTempDelta - -3);
#RoomTempControl = round(#RoomTempDelta / -3);
#RoomTempControl = round(#RoomTempDelta * -3);
#RoomTempControl = round(#RoomTempDelta % -3);
#RoomTempControl = round(#RoomTempDelta ^ -3);
end
"""
output = Minifier.minify(input_text, comments_only=True)
assert output == expected_output