@Test public void forEachWordWithSpecialCharsTest() { Interactor interactor = new TestInteractor(); Engine engine = new Engine(interactor); engine.start(); engine.parseAndRun("create msg : \"one\ttwo\nthree\""); 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.parseAndRun("show x, index"); assertEquals("3", engine.getLastResult()); engine.stop(); }
@Test public void forEachWordWithLiteralTest() { Interactor interactor = new TestInteractor(); Engine engine = new Engine(interactor); engine.start(); engine.parseAndRun("create x [for each word]"); engine.parseAndRun("destroy x, in"); engine.parseAndRun("create x, in : \"one two three four five\""); engine.parseAndRun("put \"show here, object\" into x, do"); engine.parseAndRun("run x"); assertEquals("five", 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(); }