@Test public void testParseFileWithEscaptedBrackets() { String file = "[when]ATTRIBUTE \"{attr}\" IS IN \\[{list}\\]=Attribute( {attr} in ({list}) )"; try { final Reader reader = new StringReader(file); this.file = new DSLTokenizedMappingFile(); final boolean parsingResult = this.file.parseAndLoad(reader); reader.close(); assertTrue(this.file.getErrors().toString(), parsingResult); assertTrue(this.file.getErrors().isEmpty()); assertEquals(1, this.file.getMapping().getEntries().size()); DSLMappingEntry entry = (DSLMappingEntry) this.file.getMapping().getEntries().get(0); assertEquals(DSLMappingEntry.CONDITION, entry.getSection()); assertEquals(DSLMappingEntry.EMPTY_METADATA, entry.getMetaData()); assertEquals( lookbehind + "ATTRIBUTE\\s+\"(.*?)\"\\s+IS\\s+IN\\s+\\[(.*?)\\](?=\\W|$)", entry.getKeyPattern().toString()); // Attribute( {attr} in ({list}) ) assertEquals("Attribute( {attr} in ({list}) )", entry.getValuePattern()); } catch (final IOException e) { e.printStackTrace(); fail("Should not raise exception "); } }
@Test public void testParseFileWithEscaptedEquals() { String file = "[when]something:\\={value}=Attribute( something == \"{value}\" )"; try { final Reader reader = new StringReader(file); this.file = new DSLTokenizedMappingFile(); final boolean parsingResult = this.file.parseAndLoad(reader); reader.close(); assertTrue(this.file.getErrors().toString(), parsingResult); assertTrue(this.file.getErrors().isEmpty()); assertEquals(1, this.file.getMapping().getEntries().size()); DSLMappingEntry entry = (DSLMappingEntry) this.file.getMapping().getEntries().get(0); assertEquals(DSLMappingEntry.CONDITION, entry.getSection()); assertEquals(DSLMappingEntry.EMPTY_METADATA, entry.getMetaData()); assertEquals(lookbehind + "something:\\=(.*?)$", entry.getKeyPattern().toString()); assertEquals("Attribute( something == \"{value}\" )", entry.getValuePattern()); } catch (final IOException e) { e.printStackTrace(); fail("Should not raise exception "); } }
/** * Add the new mapping to this expander. * * @param mapping */ public void addDSLMapping(final DSLMapping mapping) { for (DSLMappingEntry entry : mapping.getEntries()) { if (DSLMappingEntry.KEYWORD.equals(entry.getSection())) { this.keywords.add(entry); } else if (DSLMappingEntry.CONDITION.equals(entry.getSection())) { this.condition.add(entry); } else if (DSLMappingEntry.CONSEQUENCE.equals(entry.getSection())) { this.consequence.add(entry); } else { // if any, then add to them both condition and consequence this.condition.add(entry); this.consequence.add(entry); } } if (mapping.getOption("result")) showResult = true; if (mapping.getOption("steps")) showSteps = true; if (mapping.getOption("keyword")) showThen = true; if (mapping.getOption("when")) showWhen = true; if (mapping.getOption("then")) showThen = true; }