@Test public void forEachWordTest() { Interactor interactor = new TestInteractor(); Engine engine = new Engine(interactor); engine.start(); engine.parseAndRun("create msg : \"one two three\""); engine.parseAndRun("create x [for each word]"); engine.parseAndRun("put \"msg\" into x, in"); engine.parseAndRun("put \"show here, object\" into x, do"); engine.parseAndRun("run x"); assertEquals("three", engine.getLastResult()); engine.stop(); }
@Test public void createForEachWordTest() { Interactor interactor = new TestInteractor(); Engine engine = new Engine(interactor); engine.start(); engine.parseAndRun("create r [for each word]"); OObject parent = engine.getContext().findObjectByName("r"); assertNotNull(parent); OObject index_obj = parent.getBucket().findChildByName("index"); assertNotNull(index_obj); assertEquals("0", index_obj.getSimpleValue()); assertEquals("integer", index_obj.getTypeSpec().getDisplayName()); OObject obj = parent.getBucket().findChildByName("in"); assertNotNull(obj); assertEquals("alias", obj.getTypeSpec().getDisplayName()); obj = parent.getBucket().findChildByName("object"); assertNotNull(obj); assertEquals("", obj.getTypeSpec().getDisplayName()); obj = parent.getBucket().findChildByName("do"); assertNotNull(obj); assertEquals("script", obj.getTypeSpec().getDisplayName()); engine.parseAndRun("put \"r, do\" into r, in"); engine.parseAndRun("put \"show here, index\" into r, do"); engine.parseAndRun("run r"); assertEquals("3", engine.getLastResult()); engine.stop(); }