mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Use macros to create methods for all watched operators
This commit is contained in:
parent
d02e5d33b4
commit
73c4334246
1 changed files with 18 additions and 21 deletions
|
@ -1,30 +1,27 @@
|
||||||
# Example system to test that doubles as a spy.
|
# Example system to test that doubles as a spy.
|
||||||
# This class tracks calls made to it.
|
# This class tracks calls made to it.
|
||||||
class SpySUT
|
class SpySUT
|
||||||
# Number of times the `#==` method was called.
|
{% for item in [
|
||||||
getter eq_call_count = 0
|
{"==", "eq"},
|
||||||
|
{"!=", "ne"},
|
||||||
|
{"<", "lt"},
|
||||||
|
{"<=", "le"},
|
||||||
|
{">", "gt"},
|
||||||
|
{">=", "ge"},
|
||||||
|
{"===", "case_eq"},
|
||||||
|
{"=~", "match"}
|
||||||
|
] %}
|
||||||
|
{% operator = item[0].id %}
|
||||||
|
{% name = item[1].id %}
|
||||||
|
|
||||||
# Number of times the `#===` method was called.
|
# Number of times the `#{{operator}}` method was called.
|
||||||
getter case_eq_call_count = 0
|
getter {{name}}_call_count = 0
|
||||||
|
|
||||||
# Number of times the `#=~` method was called.
|
# Returns true and increments `#{{name}}_call_count`.
|
||||||
getter match_call_count = 0
|
def {{operator}}(other : T) forall T
|
||||||
|
@{{name}}_call_count += 1
|
||||||
# Returns true and increments `#eq_call_count`.
|
|
||||||
def ==(other : T) forall T
|
|
||||||
@eq_call_count += 1
|
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns true and increments `#case_eq_call_count`.
|
{% end %}
|
||||||
def ===(other : T) forall T
|
|
||||||
@case_eq_call_count += 1
|
|
||||||
true
|
|
||||||
end
|
|
||||||
|
|
||||||
# Returns true and increments `#match_eq_call_count`.
|
|
||||||
def =~(other : T) forall T
|
|
||||||
@match_call_count += 1
|
|
||||||
true
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue