Skip to content
This repository was archived by the owner on Feb 21, 2026. It is now read-only.

Commit c40095c

Browse files
committed
Updated and added tests for Event Lib
1 parent 7f5f6a2 commit c40095c

3 files changed

Lines changed: 33 additions & 2 deletions

File tree

eiger.Tests/EigerTests.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,24 @@ public void ReturnInsideLoopsTest()
381381
}
382382

383383
[TestMethod]
384-
public void MathLibTest() {
384+
public void EventLibTest()
385+
{
386+
// Subscribing to event and invoking event
387+
TestCode(
388+
"include event\nlet ev = Event()\nev.Subscribe(func(msg) emitln(\"First Subscriber: \" + msg) end)\nev.Subscribe(func(msg) emitln(\"Second Subscriber: \" + msg) end)\nev.Invoke(\"Hello!\")",
389+
"First Subscriber: Hello!\nSecond Subscriber: Hello!\n"
390+
);
391+
392+
// Unsubscribing from event
393+
TestCode(
394+
"include event\nfunc functionOne(args) emitln(\"This is function one\") end\nfunc functionTwo(args) emitln(\"This is function two\") end\nlet ev = Event()\nev.Subscribe(functionTwo)\nev.Subscribe(functionOne)\nev.Unsubscribe(functionTwo)\nev.Invoke(nix)",
395+
"This is function one"
396+
);
397+
}
398+
399+
[TestMethod]
400+
public void MathLibTest()
401+
{
385402
TestCode(
386403
"include math\nemitln(math.abs(-128))",
387404
"128"

eiger/Execution/Function.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
using EigerLang.Execution;
88
using EigerLang.Parsing;
99

10+
using Boolean = EigerLang.Execution.BuiltInTypes.Boolean;
11+
1012
namespace EigerLang.Execution;
1113

1214
// a base function from which both custom and built-in functions will extend
@@ -25,6 +27,18 @@ public void CheckArgs(string path, int line, int pos, int argCount)
2527
}
2628

2729
public abstract ReturnResult Execute(List<Value> args, int line, int pos, string path); // abstract execute function
30+
31+
public override Boolean ComparisonEqeq(object other) {
32+
if(other is BaseFunction f)
33+
return new Boolean(filename, line, pos, name == f.name && arg_n.SequenceEqual(f.arg_n) && symbolTable == f.symbolTable);
34+
return new Boolean(filename, line, pos, false);
35+
}
36+
37+
public override Boolean ComparisonNeqeq(object other) {
38+
if(other is BaseFunction f)
39+
return new Boolean(filename, line, pos, !(name == f.name && arg_n.SequenceEqual(f.arg_n) && symbolTable == f.symbolTable));
40+
return new Boolean(filename, line, pos, true);
41+
}
2842
}
2943

3044
// custom functions

eiger/modules/event.ei

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
let newSubscribers = []
1010
for i = 0 to subscribers.length do
1111
if subscribers[i] != subscriber then
12-
newSubscribers += subscibers[i]
12+
newSubscribers += subscribers[i]
1313
end
1414
end
1515
subscribers = newSubscribers

0 commit comments

Comments
 (0)