TreePattern implements Serializable { public TreeNode<V> expand(final Map<Var<V>, Tree<V, ?>> vars) { return expand(_pattern, vars); } TreePattern(final Tree<Decl<V>, ?> pattern); SortedSet<Var<V>> vars(); TreePattern<B> map(final Function<? super V, ? extends B> mapper); TreeMatcher<V> matcher(final Tree<V, ?> tree); Optional<TreeMatchResult<V>> match(final Tree<V, ?> tree); boolean matches(final Tree<V, ?> tree); TreeNode<V> expand(final Map<Var<V>, Tree<V, ?>> vars); @Override int hashCode(); @Override boolean equals(final Object obj); @Override String toString(); static TreePattern<String> compile(final String pattern); static TreePattern<V> compile(
		final String pattern,
		final Function<? super String, ? extends V> mapper
	);  }
@Test(dataProvider = "patterns") public void expand( final String pattern, final String[] trees, final String expanded ) { final TreePattern<String> tp = TreePattern.compile(pattern); final Map<Var<String>, Tree<String, ?>> vars = IntStream.range(0, trees.length) .mapToObj(i -> new Object() { final Var<String> name = Var.of(VARS[i]); final Tree<String, ?> tree = TreeNode.parse(trees[i]); }) .collect(Collectors.toMap(o -> o.name, o -> o.tree)); Assert.assertEquals(tp.expand(vars).toParenthesesString(), expanded); }
@Test public void expand() { final TreePattern<String> pattern = TreePattern.compile("add($x,$y,1)"); final Map<Var<String>, Tree<String, ?>> vars = new HashMap<>(); vars.put(TreePattern.Var.of("x"), TreeNode.parse("sin(x)")); vars.put(TreePattern.Var.of("y"), TreeNode.parse("sin(y)")); final Tree<String, ?> tree = pattern.expand(vars); Assert.assertEquals(tree.toParenthesesString(), "add(sin(x),sin(y),1)"); }