### Question:
GOLDParser extends Parser { public void clear() { restart(); getScopes().clear(); clearProgramVariables(); getErrorMessages().clear(); setCurrentScope(new Scope("GLOBAL")); } GOLDParser();  GOLDParser(GOLDParserBuildContext context);  GOLDParser(File cgtFile, String rulesPackage, boolean trimReductions);  GOLDParser(InputStream cgtFile, String rulesPackage, boolean trimReductions); void clear(); void clearProgramVariables(); void clearProgramVariable(String name); Variable getProgramVariable(String name); void setProgramVariable(String name, Variable value); Map<String, Scope> getScopes(); Scope getCurrentScope(); Scope setCurrentScope(Scope newScope); boolean getGenerateTree(); void setGenerateTree(boolean generateTree); void raiseParserException(String msg); void raiseParserException(String msg, Throwable cause); List<String> getErrorMessages(); String getErrorMessage(); void addErrorMessage(String message); boolean isReady(); boolean isIgnoreCaseOfVariables(); void setIgnoreCaseOfVariables(boolean ignoreCaseOfVariableNames); boolean setup(File grammarFile); boolean parseSourceStatements(String sourceStatements); boolean parseSourceStatements(Reader sourceReader); boolean processInternalError(); String getParseTree(); void loadRuleHandlers(String packageName); void loadRuleHandlers(List<Class> ruleClasses); List<String> validateHandlersExist(); void validateHandlerExists(Production rule); static final String VT_INDENT_DECREASE; static final String VT_INDENT_INCREASE; }### Answer:
@Test public void testClear() throws Exception { GOLDParser parser = new GOLDParser(); parser.addErrorMessage("Syntax boo-boo"); parser.setCurrentScope(new Scope("Widget")); parser.setProgramVariable("mode", new Variable("debug")); assertEquals("wrong msg", "Syntax boo-boo", parser.getErrorMessage()); assertEquals("wrong number of scopes", 2, parser.getScopes().size()); assertEquals("wrong number of variables", 0, parser.getScopes().get("GLOBAL").getVariables().size()); assertEquals("wrong number of variables", 1, parser.getCurrentScope().getVariables().size()); assertEquals("scope", "Widget", parser.getCurrentScope().getName()); assertEquals("variable", "debug", parser.getProgramVariable("mode").asString()); parser.clear(); assertEquals("wrong msg", "", parser.getErrorMessage()); assertEquals("wrong number of scopes", 1, parser.getScopes().size()); assertNull("shouldn't exist", parser.getScopes().get("Widget")); assertEquals("scope", "GLOBAL", parser.getCurrentScope().getName()); assertEquals("wrong number of variables", 0, parser.getScopes().get("GLOBAL").getVariables().size()); }