-
-
Notifications
You must be signed in to change notification settings - Fork 373
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 🚀 Add number format expression * Little changes * Prevent variables usage * Support variables as custom format * Make it return null if format is invalid * Add test script * Update test script * Update test script * Changes * Fix class to use same technique as #4664 * Apply suggestions from code review Co-authored-by: LimeGlass <16087552+TheLimeGlass@users.noreply.github.com> * Add helpful comments and use lambda * Update src/main/java/ch/njol/skript/expressions/ExprFormatNumber.java Co-authored-by: LimeGlass <16087552+TheLimeGlass@users.noreply.github.com> * Change expression to function * Remove unused imports * Refactoring and merge base, updating examples * return null instead of empty string * Update examples * Warn instead of erroring, but probably better to remove * Address reviews * better variable naming * init commit * update file name --------- Co-authored-by: Ayham Al-Ali <alali_ayham@yahoo.com> Co-authored-by: Ayham Al-Ali <20037329+AyhamAl-Ali@users.noreply.github.com> Co-authored-by: LimeGlass <16087552+TheLimeGlass@users.noreply.github.com> Co-authored-by: Moderocky <admin@moderocky.com>
- Loading branch information
1 parent
04afda1
commit 9786eb4
Showing
2 changed files
with
107 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/test/skript/tests/regressions/7166-formatted numbers.sk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
test "formatted numbers function": | ||
assert formatNumber(123456789) is "123,456,789" with "default number format failed ##1" | ||
assert formatNumber(1234567) is "1,234,567" with "default number format failed ##2" | ||
assert formatNumber(123.456) is "123.46" with "default number format failed ##3" | ||
|
||
assert formatNumber(12345678, "##,##.00") is "12,34,56,78.00" with "custom number format failed ##1" | ||
assert formatNumber(12345678, "####,####") is "1234,5678" with "custom number format failed ##2" | ||
assert formatNumber(123456.789, "$###,###.##") is "$123,456.79" with "custom number format failed ##3" | ||
|
||
assert formatNumber(12345678, "##.,##") is not set with "invalid number format returns a value" | ||
assert formatNumber(123.45678, "##.,##") is not set with "invalid number format returns a value" | ||
|
||
set {_n} to "a" parsed as number | ||
assert formatNumber({_n}) is not set with "invalid number returns a value" | ||
assert formatNumber({_n}, "##,##") is not set with "invalid number with format returns a value" | ||
assert formatNumber({_n}, "##.,##") is not set with "invalid number with invalid format returns a value" | ||
|
||
set {_n} to NaN value | ||
assert formatNumber({_n}) is "NaN" with "NaN doesn't return a value" | ||
assert formatNumber({_n}, "##,##") is "NaN" with "NaN with format doesn't return a value" | ||
assert formatNumber({_n}, "##.,##") is not set with "NaN with invalid format returns a value" | ||
|
||
set {_n} to infinity value | ||
assert formatNumber({_n}) is "∞" with "infinity doesn't return a value" | ||
assert formatNumber({_n}, "##,##") is "∞" with "infinity with format doesn't return a value" | ||
assert formatNumber({_n}, "##.,##") is not set with "infinity with invalid format returns a value" |