⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 longest1test.java

📁 大名鼎鼎的java动态脚本语言。已经通过了sun的认证
💻 JAVA
字号:
package gls.ch03.s02;import junit.framework.*;import org.codehaus.groovy.tck.*;public class Longest1Test extends TestCase {    public void testPass() throws Throwable {        StringBuffer srcBuffer = new StringBuffer();        srcBuffer.append("package gls.ch03.s02").append(lineSep);        srcBuffer.append("").append(lineSep);        srcBuffer.append("/**").append(lineSep);        srcBuffer.append(" * GLS 3.2: The longest possible translation is used at each step, even if the ").append(lineSep);        srcBuffer.append(" * result does not ultimately make a correct program while another lexical ").append(lineSep);        srcBuffer.append(" * translation would.").append(lineSep);        srcBuffer.append(" * ").append(lineSep);        srcBuffer.append(" * This is fundamental to the way the lexer works. If there is a problem with").append(lineSep);        srcBuffer.append(" * it, other tests (e.g. to test functionality of operators or identifier").append(lineSep);        srcBuffer.append(" * names) would expose it quickly. Nevertheless, we test some combinations").append(lineSep);        srcBuffer.append(" * here for consistency.").append(lineSep);        srcBuffer.append(" *").append(lineSep);        srcBuffer.append(" * @author Alan Green").append(lineSep);        srcBuffer.append(" */").append(lineSep);        srcBuffer.append("class Longest1 extends GroovyTestCase {").append(lineSep);        srcBuffer.append("").append(lineSep);        srcBuffer.append("    // Increment and decrement operators").append(lineSep);        srcBuffer.append("    void testPrefixIncDec() {").append(lineSep);        srcBuffer.append("        def a = 20").append(lineSep);        srcBuffer.append("        def b = 10").append(lineSep);        srcBuffer.append("        def c = a - b").append(lineSep);        srcBuffer.append("        //c = a -- b // @fail:parse ").append(lineSep);        srcBuffer.append("        //c = a ++ b // @fail:parse").append(lineSep);        srcBuffer.append("        //c = a +- b // @pass").append(lineSep);        srcBuffer.append("        //c = a -+ b // @pass").append(lineSep);        srcBuffer.append("    }").append(lineSep);        srcBuffer.append("}").append(lineSep);        srcBuffer.append("").append(lineSep);        Object result = helper.evaluate(srcBuffer.toString(),"testPass");        if (result instanceof TestResult) {            TestResult testResult = (TestResult)result;            if (testResult.errorCount() > 0) {                TestFailure firstTestFailure = (TestFailure)testResult.errors().nextElement();                throw firstTestFailure.thrownException();            }            if (testResult.failureCount() > 0) {                AssertionFailedError firstFailure = (AssertionFailedError)(testResult.failures().nextElement());                throw firstFailure;            }        }    }    public void testPass1() throws Throwable {        StringBuffer srcBuffer = new StringBuffer();        srcBuffer.append("package gls.ch03.s02").append(lineSep);        srcBuffer.append("").append(lineSep);        srcBuffer.append("/**").append(lineSep);        srcBuffer.append(" * GLS 3.2: The longest possible translation is used at each step, even if the ").append(lineSep);        srcBuffer.append(" * result does not ultimately make a correct program while another lexical ").append(lineSep);        srcBuffer.append(" * translation would.").append(lineSep);        srcBuffer.append(" * ").append(lineSep);        srcBuffer.append(" * This is fundamental to the way the lexer works. If there is a problem with").append(lineSep);        srcBuffer.append(" * it, other tests (e.g. to test functionality of operators or identifier").append(lineSep);        srcBuffer.append(" * names) would expose it quickly. Nevertheless, we test some combinations").append(lineSep);        srcBuffer.append(" * here for consistency.").append(lineSep);        srcBuffer.append(" *").append(lineSep);        srcBuffer.append(" * @author Alan Green").append(lineSep);        srcBuffer.append(" */").append(lineSep);        srcBuffer.append("class Longest1 extends GroovyTestCase {").append(lineSep);        srcBuffer.append("").append(lineSep);        srcBuffer.append("    // Increment and decrement operators").append(lineSep);        srcBuffer.append("    void testPrefixIncDec() {").append(lineSep);        srcBuffer.append("        def a = 20").append(lineSep);        srcBuffer.append("        def b = 10").append(lineSep);        srcBuffer.append("        def c = a - b").append(lineSep);        srcBuffer.append("        //c = a -- b // @fail:parse ").append(lineSep);        srcBuffer.append("        //c = a ++ b // @fail:parse").append(lineSep);        srcBuffer.append("          c = a +- b // @pass").append(lineSep);        srcBuffer.append("        //c = a -+ b // @pass").append(lineSep);        srcBuffer.append("    }").append(lineSep);        srcBuffer.append("}").append(lineSep);        srcBuffer.append("").append(lineSep);        Object result = helper.evaluate(srcBuffer.toString(),"testPass1");        if (result instanceof TestResult) {            TestResult testResult = (TestResult)result;            if (testResult.errorCount() > 0) {                TestFailure firstTestFailure = (TestFailure)testResult.errors().nextElement();                throw firstTestFailure.thrownException();            }            if (testResult.failureCount() > 0) {                AssertionFailedError firstFailure = (AssertionFailedError)(testResult.failures().nextElement());                throw firstFailure;            }        }    }    public void testPass2() throws Throwable {        StringBuffer srcBuffer = new StringBuffer();        srcBuffer.append("package gls.ch03.s02").append(lineSep);        srcBuffer.append("").append(lineSep);        srcBuffer.append("/**").append(lineSep);        srcBuffer.append(" * GLS 3.2: The longest possible translation is used at each step, even if the ").append(lineSep);        srcBuffer.append(" * result does not ultimately make a correct program while another lexical ").append(lineSep);        srcBuffer.append(" * translation would.").append(lineSep);        srcBuffer.append(" * ").append(lineSep);        srcBuffer.append(" * This is fundamental to the way the lexer works. If there is a problem with").append(lineSep);        srcBuffer.append(" * it, other tests (e.g. to test functionality of operators or identifier").append(lineSep);        srcBuffer.append(" * names) would expose it quickly. Nevertheless, we test some combinations").append(lineSep);        srcBuffer.append(" * here for consistency.").append(lineSep);        srcBuffer.append(" *").append(lineSep);        srcBuffer.append(" * @author Alan Green").append(lineSep);        srcBuffer.append(" */").append(lineSep);        srcBuffer.append("class Longest1 extends GroovyTestCase {").append(lineSep);        srcBuffer.append("").append(lineSep);        srcBuffer.append("    // Increment and decrement operators").append(lineSep);        srcBuffer.append("    void testPrefixIncDec() {").append(lineSep);        srcBuffer.append("        def a = 20").append(lineSep);        srcBuffer.append("        def b = 10").append(lineSep);        srcBuffer.append("        def c = a - b").append(lineSep);        srcBuffer.append("        //c = a -- b // @fail:parse ").append(lineSep);        srcBuffer.append("        //c = a ++ b // @fail:parse").append(lineSep);        srcBuffer.append("        //c = a +- b // @pass").append(lineSep);        srcBuffer.append("          c = a -+ b // @pass").append(lineSep);        srcBuffer.append("    }").append(lineSep);        srcBuffer.append("}").append(lineSep);        srcBuffer.append("").append(lineSep);        Object result = helper.evaluate(srcBuffer.toString(),"testPass2");        if (result instanceof TestResult) {            TestResult testResult = (TestResult)result;            if (testResult.errorCount() > 0) {                TestFailure firstTestFailure = (TestFailure)testResult.errors().nextElement();                throw firstTestFailure.thrownException();            }            if (testResult.failureCount() > 0) {                AssertionFailedError firstFailure = (AssertionFailedError)(testResult.failures().nextElement());                throw firstFailure;            }        }    }    public void testFailParse1() throws Throwable {        StringBuffer srcBuffer = new StringBuffer();        srcBuffer.append("package gls.ch03.s02").append(lineSep);        srcBuffer.append("").append(lineSep);        srcBuffer.append("/**").append(lineSep);        srcBuffer.append(" * GLS 3.2: The longest possible translation is used at each step, even if the ").append(lineSep);        srcBuffer.append(" * result does not ultimately make a correct program while another lexical ").append(lineSep);        srcBuffer.append(" * translation would.").append(lineSep);        srcBuffer.append(" * ").append(lineSep);        srcBuffer.append(" * This is fundamental to the way the lexer works. If there is a problem with").append(lineSep);        srcBuffer.append(" * it, other tests (e.g. to test functionality of operators or identifier").append(lineSep);        srcBuffer.append(" * names) would expose it quickly. Nevertheless, we test some combinations").append(lineSep);        srcBuffer.append(" * here for consistency.").append(lineSep);        srcBuffer.append(" *").append(lineSep);        srcBuffer.append(" * @author Alan Green").append(lineSep);        srcBuffer.append(" */").append(lineSep);        srcBuffer.append("class Longest1 extends GroovyTestCase {").append(lineSep);        srcBuffer.append("").append(lineSep);        srcBuffer.append("    // Increment and decrement operators").append(lineSep);        srcBuffer.append("    void testPrefixIncDec() {").append(lineSep);        srcBuffer.append("        def a = 20").append(lineSep);        srcBuffer.append("        def b = 10").append(lineSep);        srcBuffer.append("        def c = a - b").append(lineSep);        srcBuffer.append("          c = a -- b // @fail:parse ").append(lineSep);        srcBuffer.append("        //c = a ++ b // @fail:parse").append(lineSep);        srcBuffer.append("        //c = a +- b // @pass").append(lineSep);        srcBuffer.append("        //c = a -+ b // @pass").append(lineSep);        srcBuffer.append("    }").append(lineSep);        srcBuffer.append("}").append(lineSep);        srcBuffer.append("").append(lineSep);        try {            helper.parse(srcBuffer.toString(),"testFailParse1");            fail("This line did not fail to parse: c = a -- b // @fail:parse");        } catch (Exception e) {            // ignore an exception as that is what we're hoping for in this case.        }    }    public void testFailParse2() throws Throwable {        StringBuffer srcBuffer = new StringBuffer();        srcBuffer.append("package gls.ch03.s02").append(lineSep);        srcBuffer.append("").append(lineSep);        srcBuffer.append("/**").append(lineSep);        srcBuffer.append(" * GLS 3.2: The longest possible translation is used at each step, even if the ").append(lineSep);        srcBuffer.append(" * result does not ultimately make a correct program while another lexical ").append(lineSep);        srcBuffer.append(" * translation would.").append(lineSep);        srcBuffer.append(" * ").append(lineSep);        srcBuffer.append(" * This is fundamental to the way the lexer works. If there is a problem with").append(lineSep);        srcBuffer.append(" * it, other tests (e.g. to test functionality of operators or identifier").append(lineSep);        srcBuffer.append(" * names) would expose it quickly. Nevertheless, we test some combinations").append(lineSep);        srcBuffer.append(" * here for consistency.").append(lineSep);        srcBuffer.append(" *").append(lineSep);        srcBuffer.append(" * @author Alan Green").append(lineSep);        srcBuffer.append(" */").append(lineSep);        srcBuffer.append("class Longest1 extends GroovyTestCase {").append(lineSep);        srcBuffer.append("").append(lineSep);        srcBuffer.append("    // Increment and decrement operators").append(lineSep);        srcBuffer.append("    void testPrefixIncDec() {").append(lineSep);        srcBuffer.append("        def a = 20").append(lineSep);        srcBuffer.append("        def b = 10").append(lineSep);        srcBuffer.append("        def c = a - b").append(lineSep);        srcBuffer.append("        //c = a -- b // @fail:parse ").append(lineSep);        srcBuffer.append("          c = a ++ b // @fail:parse").append(lineSep);        srcBuffer.append("        //c = a +- b // @pass").append(lineSep);        srcBuffer.append("        //c = a -+ b // @pass").append(lineSep);        srcBuffer.append("    }").append(lineSep);        srcBuffer.append("}").append(lineSep);        srcBuffer.append("").append(lineSep);        try {            helper.parse(srcBuffer.toString(),"testFailParse2");            fail("This line did not fail to parse: c = a ++ b // @fail:parse");        } catch (Exception e) {            // ignore an exception as that is what we're hoping for in this case.        }    }    protected String lineSep = System.getProperty("line.separator");    protected TestGeneratorHelper helper = new ClassicGroovyTestGeneratorHelper();}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -