1 /* 2 [The "BSD licence"] 3 Copyright (c) 2007-2008 Leon Jen-Yuan Su 4 All rights reserved. 5 6 Redistribution and use in source and binary forms, with or without 7 modification, are permitted provided that the following conditions 8 are met: 9 1. Redistributions of source code must retain the above copyright 10 notice, this list of conditions and the following disclaimer. 11 2. Redistributions in binary form must reproduce the above copyright 12 notice, this list of conditions and the following disclaimer in the 13 documentation and/or other materials provided with the distribution. 14 3. The name of the author may not be used to endorse or promote products 15 derived from this software without specific prior written permission. 16 17 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 package org.antlr.gunit; 29 30 /** A class which wraps all testsuites for an individual rule */ 31 import java.util.Map; 32 import java.util.LinkedHashMap; 33 34 public class gUnitTestSuite { 35 protected String rule = null; // paeser rule name for unit testing 36 protected String lexicalRule = null; // lexical rule name 37 protected String treeRule = null; // optional, required for testing tree grammar rule 38 protected boolean isLexicalRule = false; 39 40 /** A map which stores input/output pairs (individual testsuites). 41 * In other words, it maps input data for unit test (gUnitTestInput object) 42 * to an expected output (Token object). 43 */ 44 protected Map<gUnitTestInput, AbstractTest> testSuites = new LinkedHashMap<gUnitTestInput, AbstractTest>(); 45 gUnitTestSuite()46 public gUnitTestSuite() { 47 } 48 gUnitTestSuite(String rule)49 public gUnitTestSuite(String rule) { 50 this.rule = rule; 51 } 52 gUnitTestSuite(String treeRule, String rule)53 public gUnitTestSuite(String treeRule, String rule) { 54 this.rule = rule; 55 this.treeRule = treeRule; 56 } 57 setRuleName(String ruleName)58 public void setRuleName(String ruleName) { this.rule = ruleName; } setLexicalRuleName(String lexicalRule)59 public void setLexicalRuleName(String lexicalRule) { this.lexicalRule = lexicalRule; this.isLexicalRule = true; } setTreeRuleName(String treeRuleName)60 public void setTreeRuleName(String treeRuleName) { this.treeRule = treeRuleName; } 61 getRuleName()62 public String getRuleName() { return this.rule; } getLexicalRuleName()63 public String getLexicalRuleName() { return this.lexicalRule; } getTreeRuleName()64 public String getTreeRuleName() { return this.treeRule; } isLexicalRule()65 public boolean isLexicalRule() { return this.isLexicalRule; } 66 addTestCase(gUnitTestInput input, AbstractTest expect)67 public void addTestCase(gUnitTestInput input, AbstractTest expect) { 68 if ( input!=null && expect!=null ) { 69 /* 70 * modified by shaoting 71 * if rule is null, use lexRule name 72 */ 73 //expect.setTestedRuleName(this.rule); 74 expect.setTestedRuleName(this.rule ==null ? this.lexicalRule : this.rule); 75 expect.setTestCaseIndex(this.testSuites.size()); 76 this.testSuites.put(input, expect); 77 } 78 } 79 80 } 81