From 76fb4f311be9678cabb7f9cb143251c7a74e930f Mon Sep 17 00:00:00 2001 From: Chayim Refael Friedman Date: Thu, 3 Dec 2020 21:47:42 +0200 Subject: [PATCH] Test static operators (#798) In #797 it was stated that static operators are valid in Wren, and proposed to check this behavior --- test/language/method/static_operators.wren | 52 ++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 test/language/method/static_operators.wren diff --git a/test/language/method/static_operators.wren b/test/language/method/static_operators.wren new file mode 100644 index 00000000..a7faeda7 --- /dev/null +++ b/test/language/method/static_operators.wren @@ -0,0 +1,52 @@ +class Foo { + static +(other) { "infix %(this) + %(other)" } + static -(other) { "infix %(this) - %(other)" } + static *(other) { "infix %(this) * %(other)" } + static /(other) { "infix %(this) / %(other)" } + static %(other) { "infix %(this) \% %(other)" } + static <(other) { "infix %(this) < %(other)" } + static >(other) { "infix %(this) > %(other)" } + static <=(other) { "infix %(this) <= %(other)" } + static >=(other) { "infix %(this) >= %(other)" } + static ==(other) { "infix %(this) == %(other)" } + static !=(other) { "infix %(this) != %(other)" } + static &(other) { "infix %(this) & %(other)" } + static |(other) { "infix %(this) | %(other)" } + static is(other) { "infix %(this) is %(other)" } + + static ! { "prefix !%(this)" } + static ~ { "prefix ~%(this)" } + static - { "prefix -%(this)" } + + static [a] { "%(this) 1-subscript %(a)" } + static [a, b] { "%(this) 2-subscript %(a) %(b)" } + static [a, b, c] { "%(this) 3-subscript %(a) %(b) %(c)" } + static [a]=(value) { "%(this) 1-subscript setter %(a) = %(value)" } + static [a, b]=(value) { "%(this) 2-subscript setter %(a) %(b) = %(value)" } + static [a, b, c]=(value) { "%(this) 3-subscript setter %(a) %(b) %(c) = %(value)" } +} + +System.print(Foo + "a") // expect: infix Foo + a +System.print(Foo - "a") // expect: infix Foo - a +System.print(Foo * "a") // expect: infix Foo * a +System.print(Foo / "a") // expect: infix Foo / a +System.print(Foo % "a") // expect: infix Foo % a +System.print(Foo < "a") // expec%(this) t: infix Foo < a +System.print(Foo > "a") // expect:%(this) infix Foo > a +System.print(Foo <= "a") // expec%(this) t: infix Foo <= a +System.print(Foo >= "a") // expect: infix Foo >= a +System.print(Foo == "a") // expect: infix Foo == a +System.print(Foo != "a") // expect: infix Foo != a +System.print(Foo & "a") // expect: infix Foo & a +System.print(Foo | "a") // expect: infix Foo | a +System.print(!Foo) // expect: prefix !Foo +System.print(~Foo) // expect: prefix ~Foo +System.print(-Foo) // expect: prefix -Foo +System.print(Foo is "a") // expect: infix Foo is a + +System.print(Foo["a"]) // expect: Foo 1-subscript a +System.print(Foo["a", "b"]) // expect: Foo 2-subscript a b +System.print(Foo["a", "b", "c"]) // expect: Foo 3-subscript a b c +System.print(Foo["a"] = "value") // expect: Foo 1-subscript setter a = value +System.print(Foo["a", "b"] = "value") // expect: Foo 2-subscript setter a b = value +System.print(Foo["a", "b", "c"] = "value") // expect: Foo 3-subscript setter a b c = value