Esempio n. 1
0
 public void handleBlankCell(Parse cell, TypeAdapter a) {
   try {
     cell.addToBody(gray(a.toString(a.get())));
   } catch (Exception e) {
     cell.addToBody(gray("error"));
   }
 }
Esempio n. 2
0
 private void compare() {
   if (typeAdapter.equals(expected, result)) {
     right(cell);
   } else {
     wrong(cell, typeAdapter.toString(result));
   }
 }
Esempio n. 3
0
 public static TypeAdapter on(Fixture fixture, Method method, boolean isRegex) {
   TypeAdapter a = on(fixture, method.getReturnType());
   a.target = fixture;
   a.method = method;
   a.isRegex = isRegex;
   return a;
 }
Esempio n. 4
0
 private void handleErrorInCell(TypeAdapter a, Parse cell) {
   try {
     Object result = a.invoke();
     wrong(cell, a.toString(result));
   } catch (IllegalAccessException e) {
     exception(cell, e);
   } catch (Exception e) {
     right(cell);
   }
 }
Esempio n. 5
0
 protected Map<Object, Object> cSort(List<?> list, int col) {
   TypeAdapter a = columnBindings[col].adapter;
   Map<Object, Object> result = new ConcurrentHashMap<Object, Object>(list.size());
   for (Object row : list) {
     try {
       a.target = row;
       Object key = a.get();
       bin(result, key, row);
     } catch (Exception e) {
       // surplus anything with bad keys, including null
       surplus.add(row);
     }
   }
   return result;
 }
Esempio n. 6
0
 /* Added by René Majewski */
 @SuppressWarnings("hiding")
 public void run() throws Exception {
   Method method = method(1);
   Class<?> type = method.getParameterTypes()[0];
   String text = cells.more.more.text();
   Object args[] = {TypeAdapter.on(actor, type).parse(text)};
   method.invoke(actor, args);
 }
Esempio n. 7
0
 public boolean equals(Object a, Object b) {
   int length = Array.getLength(a);
   if (length != Array.getLength(b)) return false;
   for (int i = 0; i < length; i++) {
     if (!componentAdapter.equals(Array.get(a, i), Array.get(b, i))) return false;
   }
   return true;
 }
Esempio n. 8
0
 public Object parse(String s) throws Exception {
   StringTokenizer t = new StringTokenizer(s, ",");
   Object array = Array.newInstance(componentType, t.countTokens());
   for (int i = 0; t.hasMoreTokens(); i++) {
     Array.set(array, i, componentAdapter.parse(t.nextToken().trim()));
   }
   return array;
 }
Esempio n. 9
0
 protected Map<Object, Object> eSort(List<?> list, int col) {
   TypeAdapter a = columnBindings[col].adapter;
   Map<Object, Object> result = new ConcurrentHashMap<Object, Object>(list.size());
   for (Object o : list) {
     Parse row = (Parse) o;
     Parse cell = row.parts.at(col);
     try {
       Object key = a.parse(cell.text());
       bin(result, key, row);
     } catch (Exception e) {
       exception(cell, e);
       for (Parse rest = cell.more; rest != null; rest = rest.more) {
         ignore(rest);
       }
     }
   }
   return result;
 }
Esempio n. 10
0
 public String toString(Object o) {
   if (o == null) return "";
   int length = Array.getLength(o);
   StringBuffer b = new StringBuffer(5 * length);
   for (int i = 0; i < length; i++) {
     b.append(componentAdapter.toString(Array.get(o, i)));
     if (i < (length - 1)) {
       b.append(", ");
     }
   }
   return b.toString();
 }
Esempio n. 11
0
 protected void check(List<?> eList, List<?> cList) {
   if (eList.isEmpty()) {
     surplus.addAll(cList);
     return;
   }
   if (cList.isEmpty()) {
     missing.addAll(eList);
     return;
   }
   Parse row = (Parse) eList.remove(0);
   Parse cell = row.parts;
   Object obj = cList.remove(0);
   for (int i = 0; i < columnBindings.length && cell != null; i++) {
     TypeAdapter a = columnBindings[i].adapter;
     if (a != null) {
       a.target = obj;
     }
     check(cell, a);
     cell = cell.more;
   }
   check(eList, cList);
 }
Esempio n. 12
0
 private Object parseCell() {
   try {
     return typeAdapter.isRegex ? cell.text() : typeAdapter.parse(cell.text());
   }
   // Ignore parse exceptions, print non-parse exceptions,
   // return null so that compareCellToResult tries relational matching.
   catch (NumberFormatException e) {
   } catch (ParseException e) {
   } catch (Exception e) {
     e.printStackTrace();
   }
   return new Unparseable();
 }
Esempio n. 13
0
    private void compareCellToResult(TypeAdapter a, Parse theCell) {
      typeAdapter = a;
      cell = theCell;

      try {
        result = typeAdapter.get();
        expected = parseCell();
        if (expected instanceof Unparseable) tryRelationalMatch();
        else compare();
      } catch (Exception e) {
        exception(cell, e);
      }
    }
Esempio n. 14
0
 protected Parse buildCells(Object row) {
   if (row == null) {
     Parse nil = new Parse("td", "null", null, null);
     nil.addToTag(" colspan=" + columnBindings.length);
     return nil;
   }
   Parse root = new Parse(null, null, null, null);
   Parse next = root;
   for (Binding columnBinding : columnBindings) {
     next = next.more = new Parse("td", "&nbsp;", null, null);
     TypeAdapter a = columnBinding.adapter;
     if (a == null) {
       ignore(next);
     } else {
       try {
         a.target = row;
         next.body = gray(escape(a.toString(a.get())));
       } catch (Exception e) {
         exception(next, e);
       }
     }
   }
   return root.more;
 }
Esempio n. 15
0
 public void init(Fixture target, Class<?> type) {
   super.init(target, type);
   componentType = type.getComponentType();
   componentAdapter = on(target, componentType);
 }
Esempio n. 16
0
 public static TypeAdapter on(Fixture fixture, Field field) {
   TypeAdapter a = on(fixture, field.getType());
   a.target = fixture;
   a.field = field;
   return a;
 }
Esempio n. 17
0
 public void check() throws Exception {
   TypeAdapter adapter = TypeAdapter.on(actor, method(0));
   check(cells.more.more, adapter);
 }
Esempio n. 18
0
 public static TypeAdapter on(Fixture target, Class<?> type) {
   TypeAdapter a = adapterFor(type);
   a.init(target, type);
   return a;
 }