Fix PatternCompiler and add PatternCompilerTest