Search in sources :

Example 1 with Record

use of de.prob.translator.types.Record in project probparsers by bendisposto.

the class TestTranslator method testTranslateRecordWithSetValues.

@Test
public void testTranslateRecordWithSetValues() throws Exception {
    Record o = (Record) Translator.translate("rec(key1:{1,2,3}, key2:{a,b})");
    Set a = (Set) o.get("key1");
    assertTrue(a.contains(Number.build(1)));
}
Also used : Set(de.prob.translator.types.Set) Record(de.prob.translator.types.Record) Test(org.junit.Test)

Example 2 with Record

use of de.prob.translator.types.Record in project probparsers by bendisposto.

the class TestTranslator method testTranslateRecord.

@Test
public void testTranslateRecord() throws Exception {
    Record o = (Record) Translator.translate("rec(key1:1, key2:2)");
    assertTrue(o.containsKey("key1"));
    assertTrue(o.containsKey("key2"));
    assertFalse(o.containsKey("key3"));
}
Also used : Record(de.prob.translator.types.Record) Test(org.junit.Test)

Example 3 with Record

use of de.prob.translator.types.Record in project probparsers by bendisposto.

the class TestTranslator method testTranslateRecordWithSequenceValues.

@Test
public void testTranslateRecordWithSequenceValues() throws Exception {
    Record o = (Record) Translator.translate("rec(key1:[1,2,3])");
    Sequence a = (Sequence) o.get("key1");
    assertTrue(a.contains(Number.build(1)));
}
Also used : Record(de.prob.translator.types.Record) Sequence(de.prob.translator.types.Sequence) Test(org.junit.Test)

Example 4 with Record

use of de.prob.translator.types.Record in project probparsers by bendisposto.

the class TranslatingVisitor method caseARecExpression.

@Override
public void caseARecExpression(ARecExpression node) {
    Map<java.lang.String, BObject> s = Record.newStorage();
    // TODO or make the record immutable after filling it
    for (PRecEntry e : node.getEntries()) {
        e.apply(this);
        RecordEntry entry = (RecordEntry) this.getResult();
        s.put(entry.getKey().getValue(), entry.getValue());
    }
    this.setResult(new Record(s));
}
Also used : BObject(de.prob.translator.types.BObject) PRecEntry(de.be4.classicalb.core.parser.node.PRecEntry) Record(de.prob.translator.types.Record) String(de.prob.translator.types.String)

Aggregations

Record (de.prob.translator.types.Record)4 Test (org.junit.Test)3 PRecEntry (de.be4.classicalb.core.parser.node.PRecEntry)1 BObject (de.prob.translator.types.BObject)1 Sequence (de.prob.translator.types.Sequence)1 Set (de.prob.translator.types.Set)1 String (de.prob.translator.types.String)1