Search in sources :

Example 16 with OtpBindings

use of org.erlide.util.erlang.OtpBindings in project erlide_eclipse by erlang.

the class TestCaseData method parseReason.

private FailReason parseReason(final OtpErlangObject reason) {
    OtpBindings b;
    try {
        b = OtpErlang.match("{Cause, Stack}", reason);
        if (b == null) {
            return new FailReason("internal error: " + reason.toString(), TestCaseData.NO_STACK);
        }
        final Collection<OtpErlangObject> stack = b.getList("Stack");
        return new FailReason(b.get("Cause").toString(), stack);
    } catch (final OtpParserException e) {
        ErlLogger.warn(e);
    } catch (final OtpErlangException e) {
        ErlLogger.warn(e);
    }
    return null;
}
Also used : OtpParserException(org.erlide.util.erlang.OtpParserException) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OtpErlangException(com.ericsson.otp.erlang.OtpErlangException) OtpBindings(org.erlide.util.erlang.OtpBindings)

Example 17 with OtpBindings

use of org.erlide.util.erlang.OtpBindings in project erlide_eclipse by erlang.

the class LogEventHandler method handleEvent.

@Subscribe
public void handleEvent(final ErlEvent event) {
    if (!event.getTopic().equals(getTopic())) {
        return;
    }
    final OtpErlangObject data = event.getEvent();
    try {
        final OtpBindings b = OtpErlang.match("{K:a,M}", data);
        final String kind = ((OtpErlangAtom) b.get("K")).atomValue();
        final OtpErlangObject amsg = b.get("M");
        ErlLogger.debug("%s: %s", kind, OtpErlang.asString(amsg));
    } catch (final Exception e) {
        ErlLogger.error("erroneous log msg: %s", data);
    }
}
Also used : OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OtpBindings(org.erlide.util.erlang.OtpBindings) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom) Subscribe(com.google.common.eventbus.Subscribe)

Example 18 with OtpBindings

use of org.erlide.util.erlang.OtpBindings in project erlide_eclipse by erlang.

the class PatternMatchTest method testMatch_sig_i.

@Test
public void testMatch_sig_i() throws Exception {
    final OtpBindings r = OtpErlang.match("W:i", "222");
    Assert.assertEquals(r.get("W"), new OtpErlangLong(222));
}
Also used : OtpErlangLong(com.ericsson.otp.erlang.OtpErlangLong) OtpBindings(org.erlide.util.erlang.OtpBindings) Test(org.junit.Test)

Example 19 with OtpBindings

use of org.erlide.util.erlang.OtpBindings in project erlide_eclipse by erlang.

the class PatternMatchTest method testMatch_same_fail.

@Test
public void testMatch_same_fail() throws Exception {
    final OtpBindings r = OtpErlang.match("[W, {W}]", "[a, {b}]");
    Assert.assertNull(r);
}
Also used : OtpBindings(org.erlide.util.erlang.OtpBindings) Test(org.junit.Test)

Example 20 with OtpBindings

use of org.erlide.util.erlang.OtpBindings in project erlide_eclipse by erlang.

the class PatternMatchTest method testMatch_novar.

@Test
public void testMatch_novar() throws Exception {
    final OtpErlangObject p = OtpErlang.parse("[a, {b}]");
    final OtpErlangObject t1 = OtpErlang.parse("[a, {b}]");
    final OtpBindings r = OtpErlang.match(p, t1);
    Assert.assertNotNull(r);
}
Also used : OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OtpBindings(org.erlide.util.erlang.OtpBindings) Test(org.junit.Test)

Aggregations

OtpBindings (org.erlide.util.erlang.OtpBindings)24 Test (org.junit.Test)13 OtpErlangAtom (com.ericsson.otp.erlang.OtpErlangAtom)9 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)9 OtpParserException (org.erlide.util.erlang.OtpParserException)7 OtpErlangException (com.ericsson.otp.erlang.OtpErlangException)6 OtpErlangTuple (com.ericsson.otp.erlang.OtpErlangTuple)3 OtpErlangLong (com.ericsson.otp.erlang.OtpErlangLong)2 OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)2 Collection (java.util.Collection)2 RpcException (org.erlide.runtime.rpc.RpcException)2 OtpErlangList (com.ericsson.otp.erlang.OtpErlangList)1 OtpErlangRangeException (com.ericsson.otp.erlang.OtpErlangRangeException)1 Subscribe (com.google.common.eventbus.Subscribe)1 ArrayList (java.util.ArrayList)1 ErlangFunction (org.erlide.engine.model.erlang.ErlangFunction)1 FunctionRef (org.erlide.engine.model.erlang.FunctionRef)1