### Question:
MicroSyntaxVisitor extends NodeVisitor.Default { static Map<ForOfVariable, String> parseVariables(String ngFor) { Map<ForOfVariable, String> result = new EnumMap<>(ForOfVariable.class); int semi = ngFor.indexOf(';'); if (semi < 0) { return result; } String right = ngFor.substring(semi) .trim(); String[] parts = right.split(";"); for (String part : parts) { part = part.trim(); if (part.isEmpty()) { continue; } Matcher matcher = VAR_DECL_PATTERN.matcher(part); if (!matcher.find()) { throw new NgoyException("Parse error in ngFor. Variables must be specified like: 'index as i; odd as o'"); } String variable = matcher.group(1) .trim(); ForOfVariable fv; try { fv = ForOfVariable.valueOf(variable); } catch (Exception e) { throw new NgoyException("Unknown ngFor variable: %s", variable); } String alias = matcher.group(2) .trim(); result.put(fv, alias); } return result; } MicroSyntaxVisitor(NodeVisitor target); @Override void start(Jerry el); @Override void end(Jerry node);  }### Answer:
@Test public void testNone() { assertThat(parseVariables("let p of persons;")).isEmpty(); }
@Test public void testIndex() { Map<ForOfVariable, String> map = parseVariables("let p of persons; index as ii "); assertThat(map).size() .isEqualTo(1); assertThat(map).contains(entry(ForOfVariable.index, "ii")); }
@Test public void testIndexOdd() { Map<ForOfVariable, String> map = parseVariables("let p of persons; index as ii ; odd as o"); assertThat(map).size() .isEqualTo(2); assertThat(map).contains(entry(ForOfVariable.index, "ii")); assertThat(map).contains(entry(ForOfVariable.odd, "o")); }
@Test public void testUnknownVariable() { expectedEx.expect(NgoyException.class); expectedEx.expectMessage(containsString("Unknown ngFor variable")); expectedEx.expectMessage(containsString("unk")); parseVariables("let p of persons; unk as ii"); }
@Test public void testParseError() { expectedEx.expect(NgoyException.class); expectedEx.expectMessage(containsString("Parse error in ngFor")); parseVariables("let p of persons; index = ii"); }