|
4 | 4 | import static com.laytonsmith.testing.StaticTest.SRun; |
5 | 5 |
|
6 | 6 | import com.laytonsmith.core.environments.GlobalEnv; |
| 7 | +import com.laytonsmith.core.events.BindableEvent; |
| 8 | +import com.laytonsmith.core.events.Driver; |
| 9 | +import com.laytonsmith.core.events.EventUtils; |
7 | 10 | import com.laytonsmith.core.exceptions.CRE.CRECastException; |
8 | 11 | import com.laytonsmith.core.exceptions.CRE.CREStackOverflowError; |
9 | 12 | import com.laytonsmith.core.exceptions.StackTraceManager; |
|
13 | 16 | import org.junit.Test; |
14 | 17 |
|
15 | 18 | import static org.junit.Assert.fail; |
| 19 | +import static org.mockito.Mockito.atLeastOnce; |
16 | 20 | import static org.mockito.Mockito.mock; |
17 | 21 | import static org.mockito.Mockito.times; |
18 | 22 | import static org.mockito.Mockito.verify; |
@@ -161,4 +165,37 @@ public void testCustomCallDepthLimit() throws Exception { |
161 | 165 | } |
162 | 166 | } |
163 | 167 |
|
| 168 | + @Test |
| 169 | + public void testProcVisibleInsideClosure() throws Exception { |
| 170 | + SRun("proc _test() { msg('hello') } closure() { _test() }()", fakePlayer); |
| 171 | + verify(fakePlayer).sendMessage("hello"); |
| 172 | + } |
| 173 | + |
| 174 | + @Test |
| 175 | + public void testProcVisibleInClosureExecutedFromBind() throws Exception { |
| 176 | + try { |
| 177 | + SRun("@callbacks = array()" |
| 178 | + + "\nbind('cmdline_test_event', null, null, @event, @callbacks) {" |
| 179 | + + "\n foreach(@cb in @callbacks) {" |
| 180 | + + "\n execute(@cb)" |
| 181 | + + "\n }" |
| 182 | + + "\n}" |
| 183 | + + "\nproc _test() { msg('hello') }" |
| 184 | + + "\n@callbacks[] = closure() {" |
| 185 | + + "\n _test()" |
| 186 | + + "\n}", fakePlayer); |
| 187 | + |
| 188 | + EventUtils.TriggerListener(Driver.EXTENSION, "cmdline_test_event", new BindableEvent() { |
| 189 | + @Override |
| 190 | + public Object _GetObject() { |
| 191 | + return new Object(); |
| 192 | + } |
| 193 | + }); |
| 194 | + |
| 195 | + verify(fakePlayer, atLeastOnce()).sendMessage("hello"); |
| 196 | + } finally { |
| 197 | + EventUtils.UnregisterAll(); |
| 198 | + } |
| 199 | + } |
| 200 | + |
164 | 201 | } |
0 commit comments