/** * Checks if specified query was rewritten for index access, and checks the query result. * * @param query query to be tested * @param result result or {@code null} for no comparison */ private static void check(final String query, final String result) { check( query, result, "exists(/descendant-or-self::*" + "[self::" + Util.className(ValueAccess.class) + "|self::" + Util.className(FTIndexAccess.class) + "])"); }
/** * Returns a string representation of all found arguments. * * @param args array with arguments * @return string representation */ static String foundArgs(final Value[] args) { // compose found arguments final StringBuilder sb = new StringBuilder(); for (final Value v : args) { if (sb.length() != 0) sb.append(", "); sb.append(v instanceof Jav ? Util.className(((Jav) v).toJava()) : v.seqType()); } return sb.toString(); }
/** Test method. */ @Test public void foldLeft1Test() { query("hof:fold-left1(1 to 10, function($x, $y) { $x + $y })", "55"); error("hof:fold-left1((), function($x, $y) { $x + $y })", EMPTYFOUND); // should be unrolled and evaluated at compile time final int limit = FnForEach.UNROLL_LIMIT; check( "hof:fold-left1(1 to " + limit + ", function($a,$b) {$a+$b})", "55", "empty(//" + Util.className(HofFoldLeft1.class) + "[contains(@name, 'fold-left1')])", "exists(*/" + Util.className(Int.class) + ')'); // should be unrolled but not evaluated at compile time check( "hof:fold-left1(1 to " + limit + ", function($a,$b) {0*random:integer($a)+$b})", "10", "empty(//" + Util.className(HofFoldLeft1.class) + "[contains(@name, 'fold-left1')])", "empty(*/" + Util.className(Int.class) + ')', "count(//" + Util.className(Arith.class) + "[@op = '+']) eq 9"); // should not be unrolled check( "hof:fold-left1(1 to " + (limit + 1) + ", function($a,$b) {$a+$b})", "66", "exists(//" + Util.className(HofFoldLeft1.class) + "[contains(@name, 'fold-left1')])"); }
/** * Returns the color for the specified string or {@code null}. * * @param string string string * @return color */ static String color(final byte[] string) { for (final Object[] color : COLORS) { final int cl = color.length; for (int c = 1; c < cl; c++) { final Object o = color[c]; final byte[] col = o instanceof byte[] ? (byte[]) o : Token.token(o instanceof Class ? Util.className((Class<?>) o) : o.toString()); if (Token.eq(col, string)) return color[0].toString(); } } return null; }