mirror of
https://github.com/microsoft/regorus.git
synced 2026-08-05 02:16:11 +00:00
fix bitwise.and and add tests (#19)
Signed-off-by: eric-therond <eric.therond.fr@gmail.com>
This commit is contained in:
@@ -14,7 +14,7 @@ use anyhow::Result;
|
||||
|
||||
pub fn register(m: &mut HashMap<&'static str, builtins::BuiltinFcn>) {
|
||||
m.insert("bits.and", and);
|
||||
m.insert("bits.and", lsh);
|
||||
m.insert("bits.lsh", lsh);
|
||||
m.insert("bits.negate", negate);
|
||||
m.insert("bits.or", or);
|
||||
m.insert("bits.rsh", rsh);
|
||||
|
||||
60
tests/interpreter/cases/builtins/bitwise/and.yaml
Normal file
60
tests/interpreter/cases/builtins/bitwise/and.yaml
Normal file
@@ -0,0 +1,60 @@
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# Licensed under the MIT License.
|
||||
|
||||
cases:
|
||||
- note: bits.and.error.wrongtype1
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
|
||||
x = bits.and(1, "str")
|
||||
query: data.test
|
||||
error: "`bits.and` expects numeric argument. Got `\"str\"` instead"
|
||||
|
||||
- note: bits.and.error.wrongtype2
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
|
||||
x = bits.and("str", 1)
|
||||
query: data.test
|
||||
error: "`bits.and` expects numeric argument. Got `\"str\"` instead"
|
||||
|
||||
- note: bits.and.error.morearg
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
|
||||
x = bits.and(1, 1, 1)
|
||||
query: data.test
|
||||
error: "`bits.and` expects 2 arguments"
|
||||
|
||||
- note: bits.and.error.lessarg
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
|
||||
x = bits.and(1)
|
||||
query: data.test
|
||||
error: "`bits.and` expects 2 arguments"
|
||||
|
||||
- note: bits.and
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
|
||||
x1 = bits.and(1, 0)
|
||||
x2 = bits.and(1, 1)
|
||||
x3 = bits.and(0, 0)
|
||||
x4 = bits.and(0, 1)
|
||||
query: data.test
|
||||
want_result:
|
||||
x1 : 0
|
||||
x2 : 1
|
||||
x3 : 0
|
||||
x4 : 0
|
||||
54
tests/interpreter/cases/builtins/bitwise/lsh.yaml
Normal file
54
tests/interpreter/cases/builtins/bitwise/lsh.yaml
Normal file
@@ -0,0 +1,54 @@
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# Licensed under the MIT License.
|
||||
|
||||
cases:
|
||||
- note: bits.lsh.error.wrongtype1
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
|
||||
x = bits.lsh(1, "str")
|
||||
query: data.test
|
||||
error: "`bits.lsh` expects numeric argument. Got `\"str\"` instead"
|
||||
|
||||
- note: bits.lsh.error.wrongtype2
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
|
||||
x = bits.lsh("str", 1)
|
||||
query: data.test
|
||||
error: "`bits.lsh` expects numeric argument. Got `\"str\"` instead"
|
||||
|
||||
- note: bits.lsh.error.morearg
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
|
||||
x = bits.lsh(1, 1, 1)
|
||||
query: data.test
|
||||
error: "`bits.lsh` expects 2 arguments"
|
||||
|
||||
- note: bits.lsh.error.lessarg
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
|
||||
x = bits.lsh(1)
|
||||
query: data.test
|
||||
error: "`bits.lsh` expects 2 arguments"
|
||||
|
||||
- note: bits.lsh
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
|
||||
x = bits.lsh(9, 2)
|
||||
query: data.test
|
||||
want_result:
|
||||
x : 36
|
||||
40
tests/interpreter/cases/builtins/bitwise/negate.yaml
Normal file
40
tests/interpreter/cases/builtins/bitwise/negate.yaml
Normal file
@@ -0,0 +1,40 @@
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# Licensed under the MIT License.
|
||||
|
||||
cases:
|
||||
- note: bits.negate.error.wrongtype
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
|
||||
x = bits.negate("str")
|
||||
query: data.test
|
||||
error: "`bits.negate` expects numeric argument. Got `\"str\"` instead"
|
||||
|
||||
- note: bits.negate.error.morearg
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
|
||||
x = bits.negate(1, 1)
|
||||
query: data.test
|
||||
error: "`bits.negate` expects 1 argument"
|
||||
|
||||
- note: bits.negate
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
|
||||
x1 = bits.negate(1)
|
||||
x2 = bits.negate(0)
|
||||
x3 = bits.negate(9)
|
||||
x4 = bits.negate(-50)
|
||||
query: data.test
|
||||
want_result:
|
||||
x1 : -2
|
||||
x2 : -1
|
||||
x3 : -10
|
||||
x4 : 49
|
||||
60
tests/interpreter/cases/builtins/bitwise/or.yaml
Normal file
60
tests/interpreter/cases/builtins/bitwise/or.yaml
Normal file
@@ -0,0 +1,60 @@
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# Licensed under the MIT License.
|
||||
|
||||
cases:
|
||||
- note: bits.or.error.wrongtype1
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
|
||||
x = bits.or(1, "str")
|
||||
query: data.test
|
||||
error: "`bits.or` expects numeric argument. Got `\"str\"` instead"
|
||||
|
||||
- note: bits.or.error.wrongtype2
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
|
||||
x = bits.or("str", 1)
|
||||
query: data.test
|
||||
error: "`bits.or` expects numeric argument. Got `\"str\"` instead"
|
||||
|
||||
- note: bits.or.error.morearg
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
|
||||
x = bits.or(1, 1, 1)
|
||||
query: data.test
|
||||
error: "`bits.or` expects 2 arguments"
|
||||
|
||||
- note: bits.or.error.lessarg
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
|
||||
x = bits.or(1)
|
||||
query: data.test
|
||||
error: "`bits.or` expects 2 arguments"
|
||||
|
||||
- note: bits.or
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
|
||||
x1 = bits.or(1, 0)
|
||||
x2 = bits.or(1, 1)
|
||||
x3 = bits.or(0, 0)
|
||||
x4 = bits.or(0, 1)
|
||||
query: data.test
|
||||
want_result:
|
||||
x1 : 1
|
||||
x2 : 1
|
||||
x3 : 0
|
||||
x4 : 1
|
||||
54
tests/interpreter/cases/builtins/bitwise/rsh.yaml
Normal file
54
tests/interpreter/cases/builtins/bitwise/rsh.yaml
Normal file
@@ -0,0 +1,54 @@
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# Licensed under the MIT License.
|
||||
|
||||
cases:
|
||||
- note: bits.rsh.error.wrongtype1
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
|
||||
x = bits.rsh(1, "str")
|
||||
query: data.test
|
||||
error: "`bits.rsh` expects numeric argument. Got `\"str\"` instead"
|
||||
|
||||
- note: bits.rsh.error.wrongtype2
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
|
||||
x = bits.rsh("str", 1)
|
||||
query: data.test
|
||||
error: "`bits.rsh` expects numeric argument. Got `\"str\"` instead"
|
||||
|
||||
- note: bits.rsh.error.morearg
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
|
||||
x = bits.rsh(1, 1, 1)
|
||||
query: data.test
|
||||
error: "`bits.rsh` expects 2 arguments"
|
||||
|
||||
- note: bits.rsh.error.lessarg
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
|
||||
x = bits.rsh(1)
|
||||
query: data.test
|
||||
error: "`bits.rsh` expects 2 arguments"
|
||||
|
||||
- note: bits.rsh
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
|
||||
x = bits.rsh(9, 2)
|
||||
query: data.test
|
||||
want_result:
|
||||
x : 2
|
||||
60
tests/interpreter/cases/builtins/bitwise/xor.yaml
Normal file
60
tests/interpreter/cases/builtins/bitwise/xor.yaml
Normal file
@@ -0,0 +1,60 @@
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# Licensed under the MIT License.
|
||||
|
||||
cases:
|
||||
- note: bits.xor.error.wrongtype1
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
|
||||
x = bits.xor(1, "str")
|
||||
query: data.test
|
||||
error: "`bits.xor` expects numeric argument. Got `\"str\"` instead"
|
||||
|
||||
- note: bits.xor.error.wrongtype2
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
|
||||
x = bits.xor("str", 1)
|
||||
query: data.test
|
||||
error: "`bits.xor` expects numeric argument. Got `\"str\"` instead"
|
||||
|
||||
- note: bits.xor.error.morearg
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
|
||||
x = bits.xor(1, 1, 1)
|
||||
query: data.test
|
||||
error: "`bits.xor` expects 2 arguments"
|
||||
|
||||
- note: bits.xor.error.lessarg
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
|
||||
x = bits.xor(1)
|
||||
query: data.test
|
||||
error: "`bits.xor` expects 2 arguments"
|
||||
|
||||
- note: bits.xor
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
|
||||
x1 = bits.xor(1, 0)
|
||||
x2 = bits.xor(1, 1)
|
||||
x3 = bits.xor(0, 0)
|
||||
x4 = bits.xor(0, 1)
|
||||
query: data.test
|
||||
want_result:
|
||||
x1 : 1
|
||||
x2 : 0
|
||||
x3 : 0
|
||||
x4 : 1
|
||||
Reference in New Issue
Block a user