forked from microsoft/regorus
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for builtin
string::format_int
method (microsoft#65)
- Loading branch information
Showing
2 changed files
with
120 additions
and
19 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
101 changes: 101 additions & 0 deletions
101
tests/interpreter/cases/builtins/strings/format_int.yaml
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,101 @@ | ||
# Copyright (c) Microsoft Corporation. | ||
# Licensed under the MIT License. | ||
|
||
cases: | ||
- note: bases | ||
data: {} | ||
modules: | ||
- | | ||
package test | ||
binary := format_int(10, 2) | ||
octal := format_int(10, 8) | ||
decimal := format_int(10, 10) | ||
hex := format_int(10, 16) | ||
query: data.test | ||
want_result: | ||
binary: "1010" | ||
octal: "12" | ||
decimal: "10" | ||
hex: "a" | ||
|
||
- note: bases-with-floats | ||
data: {} | ||
modules: | ||
- | | ||
package test | ||
binary := format_int(10.2, 2) | ||
octal := format_int(10.7, 8) | ||
decimal := format_int(10.325436, 10) | ||
hex := format_int(10.0, 16) | ||
query: data.test | ||
want_result: | ||
binary: "1010" | ||
octal: "12" | ||
decimal: "10" | ||
hex: "a" | ||
|
||
- note: bases-with-negative-values | ||
data: {} | ||
modules: | ||
- | | ||
package test | ||
binary := format_int(-10, 2) | ||
octal := format_int(-10, 8) | ||
decimal := format_int(-10, 10) | ||
hex := format_int(-10, 16) | ||
query: data.test | ||
want_result: | ||
binary: "-1010" | ||
octal: "-12" | ||
decimal: "-10" | ||
hex: "-a" | ||
|
||
- note: bases-with-negative-floats | ||
data: {} | ||
modules: | ||
- | | ||
package test | ||
binary := format_int(-10.765, 2) | ||
octal := format_int(-10.0, 8) | ||
decimal := format_int(-10.999999999, 10) | ||
hex := format_int(-10.00, 16) | ||
query: data.test | ||
want_result: | ||
binary: "-1010" | ||
octal: "-12" | ||
decimal: "-10" | ||
hex: "-a" | ||
|
||
- note: invalid-num-type | ||
data: {} | ||
modules: | ||
- | | ||
package test | ||
x := format_int("10", 2) | ||
query: data.test | ||
error: '`format_int` expects numeric argument. Got `"10"` instead' | ||
|
||
- note: invalid-base | ||
data: {} | ||
modules: | ||
- | | ||
package test | ||
x := format_int(10, 4) | ||
query: data.test | ||
error: "`format_int` expects base to be one of 2, 8, 10, 16" | ||
|
||
- note: invalid-base-type | ||
data: {} | ||
modules: | ||
- | | ||
package test | ||
x := format_int(10, "2") | ||
query: data.test | ||
error: '`format_int` expects numeric argument. Got `"2"` instead' |