Skip to content
Permalink
Browse files

Add more closure tests

  • Loading branch information...
PseudoKnight committed Sep 7, 2019
1 parent 7e48929 commit 80b0fd55bc392383bd28123cf0e9c30e37ff6783
@@ -103,6 +103,12 @@ public void testProcReturn() throws Exception {
optimize("proc(_proc, return(array(1))) _proc()[0]"));
}

@Test
public void testClosure() throws Exception {
assertEquals("sconcat(assign(@c,closure(@target,msg(concat('Hello ',@target,'!')))),@c('world'))",
optimize("@c = closure(@target) {msg('Hello '.@target.'!')}; @c('world');"));
}

@Test
public void testUnreachableCode() throws Exception {
assertEquals("if(dyn(0),sconcat(die()),sconcat(msg('2'),msg('3')))",
@@ -296,6 +296,26 @@ public void testClosure10() throws Exception {
verify(fakePlayer2).sendMessage("newlabel");
}

@Test(timeout = 10000)
public void testClosure11() throws Exception {
SRun("@c = closure(@msg){msg(@msg)};\n"
+ "@c('Hello World');", fakePlayer);
verify(fakePlayer).sendMessage("Hello World");
}

@Test(timeout = 10000)
public void testClosure12() throws Exception {
SRun("@c = closure(@msg = 'Hello World'){msg(@msg)};\n"
+ "@c();", fakePlayer);
verify(fakePlayer).sendMessage("Hello World");
}

@Test(timeout = 10000, expected = CRECastException.class)
public void testClosure13() throws Exception {
SRun("@s = 'string';\n"
+ "@s();", fakePlayer);
}

@Test
public void testToRadix() throws Exception {
assertEquals("f", SRun("to_radix(15, 16)", null));

0 comments on commit 80b0fd5

Please sign in to comment.
You can’t perform that action at this time.