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

📄 runxqts.java

📁 A framework written in Java for implementing high-level and dynamic languages, compiling them into J
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
      }    else if (tagMatches("query"))      {        testQueryName = attributes.getValue("name");      }    else if (tagMatches("source"))      {        String ID = attributes.getValue("ID");        String filename = attributes.getValue("FileName");        sources.put(ID, filename);      }    else if (testName == null && tagMatches("module"))      {        String ID = attributes.getValue("ID");        String filename = attributes.getValue("FileName");        modules.put(ID, filename);      }    else if (tagMatches("collection"))      {        collectionID = attributes.getValue("ID");        collectionDocuments = new Values();        sources.put(collectionID, collectionDocuments);      }    inStartTag = false;  }  String testName;  String scenario;  String testQueryName;  String testFilePath;  String testQuery;  int maxTests = -1;  void report (String result, String comment)  {    boolean failed = "fail".equals(result);    if (failExpected == null)      {        if (failed)          {            System.out.println("FAIL: "+testName);            failCount++;          }        else if ("cannot tell".equals(result))          cannotTellCount++;        else          passCount++;      }    else      {        if (failed)          xfailCount++;        else          {            System.out.println("XPASS: "+testName);            xpassCount++;          }      }    writeAttribute("result", result);    if (failed && failExpected != null)      {        StringBuffer sbuf = new StringBuffer("(expected-to-fail: ");        sbuf.append(failExpected.toString());        sbuf.append(')');        if (comment != null)          {            sbuf.append("; ");            sbuf.append(comment);          }        comment = sbuf.toString();      }    if (comment != null)      writeAttribute("comment", comment);  }  public void evalTest (String testName)    throws Throwable  {    failExpected = expectedFailures.get(testName);    if (failExpected == null)      {        // Check for a wildcard: replace a final non-negative integer by '*'.        int len = testName.length();        while (--len > 0 && Character.digit(testName.charAt(len), 10) >= 0);        failExpected = expectedFailures.get(testName.substring(0, len+1)+'*');      }    Environment env = Environment.getCurrent();    SourceMessages messages = new SourceMessages();    String filename      = directory + '/' + XQueryQueryOffsetPath + testFilePath      + testQueryName + XQueryFileExtension;    InPort in;    expectedErrors = expectedErrorsBuf.toString();    try      {        in = InPort.openFile(filename);      }    catch (java.io.FileNotFoundException ex)      {        String xfilename = directory + '/' + XQueryXQueryOffsetPath           + testFilePath + testQueryName + XQueryXFileExtension;        if (new java.io.File(xfilename).exists())          {            report("fail", "xqueryx not implemented");            return;          }        throw ex;      }    Compilation comp;    Procedure withContextProc = null;    try      {        if (contextItem != null)          {            withContextProc = xqueryLanguage.evalToFocusProc(in, messages);            comp = null;          }        else          comp = xqueryLanguage.parse(in, messages, Language.PARSE_IMMEDIATE);        if (messages.seenErrors())          throw new SyntaxException(messages);      }    catch (SyntaxException ex)      {        in.close();        SourceError error = messages.getErrors();        String errorString = error == null ? "" : "|" + error.code + "|";        if (expectedErrors.indexOf(errorString) >= 0)          {            report("pass", null);          }        else if (errorString.equals("|XQST0009|"))          {            if (failExpected == null)              failExpected = "'import schema' not implemented";            report("fail", null);          }        else if (error.message != null                 && error.message.indexOf("unknown type xs:NOTATION") >= 0                 && (expectedErrors.equals("|XPST0080|")                     || expectedErrors.equals("|XPST0017|")))          {            report("fail", null);          }        else if (error.message != null                 && error.message.indexOf("unknown type xs:ENTITY") >= 0                 && (expectedErrors.equals("|XPTY0004|")))          {            report("fail", null);          }        else if (error.message != null                 && error.message.indexOf("unknown function") >= 0                 && (expectedErrors.equals("|XPDY0002|")                     || expectedErrors.equals("|XPTY0004|")                     || expectedErrors.equals("|XQDY0025|")                     || expectedErrors.equals("|FODC0001|")                     || (expectedErrors.equals("|XPST0017|")                         && (error.message.endsWith(" fn:id")                             || error.message.endsWith(" fn:idref")))))          {            report("fail", null);          }        else if (expectedErrors.length() > 1)          report("pass", "static error: "+error+" expected:"+expectedErrors);        else          report("fail", "static error: "+error.message);        return;      }    in.close();    CallContext ctx = CallContext.getInstance();    if (contextItem != null)      {	gnu.math.IntNum one = gnu.math.IntNum.one();        withContextProc.check3(contextItem, one, one, ctx);      }    gnu.lists.Consumer save = ctx.consumer;    CharArrayOutPort out = new CharArrayOutPort();    XMLPrinter xout = new XMLPrinter(out, false);    xout.strict = true;    xout.useEmptyElementTag = 1;    xout.escapeNonAscii = false;    xout.canonicalizeCDATA = true;    ctx.consumer = xout;    try      {        if (contextItem != null)          ctx.runUntilDone();        else          ModuleExp.evalModule(env, ctx, comp, null, null);      }    catch (Throwable ex)      {        if (ex instanceof NumberFormatException            && expectedErrors.indexOf("|FORG0001|") >= 0)          report("pass", "caught NumberFormatException expected:"+expectedErrors);        else if (ex instanceof ClassCastException                 && (expectedErrors.indexOf("|XPTY0004|") >= 0                     || expectedErrors.indexOf("|XPTY0020|") >= 0                     || expectedErrors.indexOf("|FORG0001|") >= 0                     || expectedErrors.indexOf("|FOAR0002|") >= 0))          report("pass", "caught ClassCastException expected:"+expectedErrors);        else if (expectedErrors.length() > 1)          report("pass", "caught "+ex+" expected:"+expectedErrors);        else          {            report("fail", "caught "+ex);            if (verbose)              {                CharArrayWriter wr = new CharArrayWriter();                PrintWriter pr = new PrintWriter(wr);                ex.printStackTrace(pr);                pr.flush();                writeVerbose("stack", wr.toString());                wr.close();              }          }        return;      }    if (messages.seenErrors())      {        if (expectedErrors.length() > 1)          report("pass", "error: "+messages.getErrors()+" expected: "+expectedErrors);        else          report("fail", "error: "+messages.getErrors());        return;      }    if ("trivial".equals(scenario))      {        failExpected = "trivial embedding not implemented";        report("fail", null);        return;      }    String actual = new String(out.toCharArray());    byte[] expectedBytes = new byte[1024];    xout.close();    ctx.consumer = save;        int numOutputFileAlts = outputFileAlts.size();    boolean foundMatchingOutput = false;    boolean displayDifference = false;    String expected = null;    String compare = null;    for (int ialt = 0;  ialt < numOutputFileAlts;  ialt++)      {        compare = (String) outputCompareAlts.elementAt(ialt);        if ("Ignore".equals(compare))          {            report("pass", null);            foundMatchingOutput = true;            break;          }        String outname  = directory + '/' + ResultOffsetPath + testFilePath          + outputFileAlts.elementAt(ialt);        FileInputStream expectStream = new FileInputStream(outname);        int expectedLength = 0;        for (;;)          {            int avail = expectedBytes.length-expectedLength;            if (avail < 1024)              {                byte[] tmp = new byte[2*expectedBytes.length];                System.arraycopy(expectedBytes, 0, tmp, 0, expectedLength);                expectedBytes = tmp;              }            int n = expectStream.read(expectedBytes, expectedLength, avail);            if (n < 0)              break;            expectedLength += n;          }        expectStream.close();        expected = new String(expectedBytes, 0, expectedLength, "UTF-8");        expected = expected.replaceAll("\r", "");        actual = actual.replaceAll("\r", "");        boolean matches = matches(actual, expected, compare);        if (matches)          {            report("pass", null);            foundMatchingOutput = true;            break;          }        else if ("Inspect".equals(compare))          {            report("cannot tell", null);            foundMatchingOutput = true;            displayDifference = verbose;            break;          }      }    if (! foundMatchingOutput)      {        if (expectedErrors.length() > 1)          {            report("fail", "expected error: "+expectedErrors);            return;          }        else          {            report("fail", null);            if (verbose && expectedFailures.get(testName) == null)              displayDifference = true;          }      }    if (displayDifference)      { // This only displays a single expected result.        writeVerbose("compare", compare);        writeVerbose("expected", expected);        writeVerbose("actual", actual);      }  }  private static int grabAttribute (String str, int start)  {    char inAttr = 0;    for (int i = start; ; )      {        if (i >= str.length())          return -1;        char ch = str.charAt(i++);        if (inAttr == 0 && (ch == '\"' || ch == '\''))          inAttr = ch;        else if (ch == inAttr)          return i;      }  }  public static boolean matches (String arg1 /* result */,                                 String arg2 /*expected*/,                                 String compare)  {    int len1 = arg1.length();    int len2 = arg2.length();    int i1 = 0, i2 = 0;    boolean intag = false;    int start_attr1 = 0;    int start_attr2 = 0;    boolean isXML = "XML".equals(compare) || "Fragment".equals(compare);    char inAttr = 0;    for (;;)      {        if (i1 == len1 && i2 == len2)          return true;        int c1 = i1 == len1 ? -1 : arg1.charAt(i1);        int c2 = i2 == len2 ? -1 : arg2.charAt(i2);        if ((c1 == '&' && arg1.charAt(i1+1) == '#' && i1 + 3 < len1)            || (c2 == '&' && arg2.charAt(i2+1) == '#' && i2 + 3 < len2))          {            try              {                if (c1 == '&')                  {                    int base1 = 10;                    i1 += 2;                    if (arg1.charAt(i1) == 'x')                      {                        i1++;                        base1 = 16;                      }                    int semi1 = arg1.indexOf(';', i1);                    c1 = Integer.parseInt(arg1.substring(i1, semi1), base1);                    i1 = semi1;                  }                else if (c1 >= 0xD800 && c1 < 0xDC00 && i1 + 1 < len1)                  c1 = (c1 - 0xD800) * 0x400                    + (arg1.charAt(++i1) - 0xDC00) + 0x10000;                if (c2 == '&')                  {                    int base2 = 10;                    i2 += 2;                    if (arg2.charAt(i2) == 'x')                      {                        i2++;                        base2 = 16;                      }                    int semi2 = arg2.indexOf(';', i2);                    c2 = Integer.parseInt(arg2.substring(i2, semi2), base2);                    i2 = semi2;                  }                else if (c2 >= 0xD800 && c2 < 0xDC00 && i2 + 1 < len2)                  c2 = (c2 - 0xD800) * 0x400                    + (arg2.charAt(++i2) - 0xDC00) + 0x10000;              }            catch (Throwable ex)              {                return false;              }            if (c1 != c2)              return false;            i1++;

⌨️ 快捷键说明

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