Add support for % operator

This commit is contained in:
Stanisław Barzowski 2017-09-19 13:50:08 -04:00 committed by Dave Cunningham
parent cab0cc887e
commit 2cf7443b91
39 changed files with 39 additions and 1 deletions

View File

@ -592,7 +592,7 @@ func todoFunc(e *evaluator, x, y potentialValue) (value, error) {
var todo = &BinaryBuiltin{function: todoFunc, parameters: ast.Identifiers{"x", "y"}} var todo = &BinaryBuiltin{function: todoFunc, parameters: ast.Identifiers{"x", "y"}}
var desugaredBop = map[ast.BinaryOp]ast.Identifier{ var desugaredBop = map[ast.BinaryOp]ast.Identifier{
//bopPercent, ast.BopPercent: "mod",
ast.BopManifestEqual: "equals", ast.BopManifestEqual: "equals",
ast.BopManifestUnequal: "notEquals", // Special case ast.BopManifestUnequal: "notEquals", // Special case
} }

1
testdata/percent_bad.golden vendored Normal file
View File

@ -0,0 +1 @@
RUNTIME ERROR: Operator % cannot be used on types number and string.

1
testdata/percent_bad.input vendored Normal file
View File

@ -0,0 +1 @@
42 % "x"

1
testdata/percent_bad2.golden vendored Normal file
View File

@ -0,0 +1 @@
RUNTIME ERROR: Too many values to format: 1, expected 0

1
testdata/percent_bad2.input vendored Normal file
View File

@ -0,0 +1 @@
"x" % 42

1
testdata/percent_bad3.golden vendored Normal file
View File

@ -0,0 +1 @@
RUNTIME ERROR: Operator % cannot be used on types function and number.

1
testdata/percent_bad3.input vendored Normal file
View File

@ -0,0 +1 @@
(function(x) x) % 42

1
testdata/percent_format_str.golden vendored Normal file
View File

@ -0,0 +1 @@
"x y"

1
testdata/percent_format_str.input vendored Normal file
View File

@ -0,0 +1 @@
"x %s" % ["y"]

1
testdata/percent_format_str2.golden vendored Normal file
View File

@ -0,0 +1 @@
"x y"

1
testdata/percent_format_str2.input vendored Normal file
View File

@ -0,0 +1 @@
"x %s" % "y"

1
testdata/percent_format_str3.golden vendored Normal file
View File

@ -0,0 +1 @@
"x y z"

1
testdata/percent_format_str3.input vendored Normal file
View File

@ -0,0 +1 @@
"x %s %s" % ["y", "z"]

1
testdata/percent_format_str4.golden vendored Normal file
View File

@ -0,0 +1 @@
RUNTIME ERROR: Too many values to format: 2, expected 1

1
testdata/percent_format_str4.input vendored Normal file
View File

@ -0,0 +1 @@
"x %s" % ["y", "z"]

1
testdata/percent_format_str5.golden vendored Normal file
View File

@ -0,0 +1 @@
RUNTIME ERROR: Not enough values to format, got 1

1
testdata/percent_format_str5.input vendored Normal file
View File

@ -0,0 +1 @@
"x %s %s" % ["y"]

1
testdata/percent_format_str6.golden vendored Normal file
View File

@ -0,0 +1 @@
RUNTIME ERROR: Not enough values to format, got 1

1
testdata/percent_format_str6.input vendored Normal file
View File

@ -0,0 +1 @@
"x %s %s" % "y"

1
testdata/percent_format_str7.golden vendored Normal file
View File

@ -0,0 +1 @@
RUNTIME ERROR: Format required number at 0, got string

1
testdata/percent_format_str7.input vendored Normal file
View File

@ -0,0 +1 @@
"x %d" % ["y"]

1
testdata/percent_format_str8.golden vendored Normal file
View File

@ -0,0 +1 @@
"x y z"

1
testdata/percent_format_str8.input vendored Normal file
View File

@ -0,0 +1 @@
"x %(a)s %(b)s" % {a: "y", b: "z"}

1
testdata/percent_mod_int.golden vendored Normal file
View File

@ -0,0 +1 @@
2

1
testdata/percent_mod_int.input vendored Normal file
View File

@ -0,0 +1 @@
42 % 5

1
testdata/percent_mod_int2.golden vendored Normal file
View File

@ -0,0 +1 @@
2

1
testdata/percent_mod_int2.input vendored Normal file
View File

@ -0,0 +1 @@
42 % -5

1
testdata/percent_mod_int3.golden vendored Normal file
View File

@ -0,0 +1 @@
-2

1
testdata/percent_mod_int3.input vendored Normal file
View File

@ -0,0 +1 @@
-42 % 5

1
testdata/percent_mod_int4.golden vendored Normal file
View File

@ -0,0 +1 @@
-2

1
testdata/percent_mod_int4.input vendored Normal file
View File

@ -0,0 +1 @@
-42 % -5

1
testdata/percent_mod_int5.golden vendored Normal file
View File

@ -0,0 +1 @@
RUNTIME ERROR: Division by zero.

1
testdata/percent_mod_int5.input vendored Normal file
View File

@ -0,0 +1 @@
42 % 0

1
testdata/percent_mod_int6.golden vendored Normal file
View File

@ -0,0 +1 @@
0

1
testdata/percent_mod_int6.input vendored Normal file
View File

@ -0,0 +1 @@
0 % 42

1
testdata/std.mod_int.golden vendored Normal file
View File

@ -0,0 +1 @@
2

1
testdata/std.mod_int.input vendored Normal file
View File

@ -0,0 +1 @@
std.mod(42, 5)

1
testdata/std.mod_string.golden vendored Normal file
View File

@ -0,0 +1 @@
"abcd xxx 042"

1
testdata/std.mod_string.input vendored Normal file
View File

@ -0,0 +1 @@
std.mod("abcd %s %03d", ["xxx", 42])