@@ -0,0 +1,1954 @@
+package org.basex.test.query;%0D%0A%0D%0Aimport static org.junit.Assert.*;%0D%0Aimport static org.basex.util.Token.*;%0D%0A%0D%0Aimport java.nio.charset.Charset;%0D%0A%0D%0Aimport org.basex.core.BaseXException;%0D%0Aimport org.basex.core.Context;%0D%0Aimport org.basex.core.cmd.XQuery;%0D%0Aimport org.junit.Test;%0D%0A%0D%0A/**%0D%0A * This class tests String %3C-%3E Token conversions.%0D%0A *%0D%0A * @author Workgroup DBIS, University of Konstanz 2005-10, ISC License%0D%0A * @author Leo Woerteler%0D%0A */%0D%0Apublic class UTF8Test %7B%0D%0A  /** Database context. */%0D%0A  private static Context context = new Context();%0D%0A  %0D%0A  /** Codepoint of the MUSICAL SYMBOL PARENTHESIS NOTEHEAD. */%0D%0A  private static final int CP = 0x1D156;%0D%0A  %0D%0A  /** UTF16 chars of the codepoint. */%0D%0A  private static final char%5B%5D CA = Character.toChars(CP);%0D%0A  %0D%0A  /** String containing the codepoint. */%0D%0A  private static final String STR = new String(CA);%0D%0A  %0D%0A  /** UTF-8 bytes of the codepoint. */%0D%0A  private static final byte%5B%5D BA = STR.getBytes(Charset.availableCharsets().get(%0D%0A      %22UTF-8%22));%0D%0A%0D%0A  /** Tests is characters outside of BMP survive token-creation. */%0D%0A  @Test%0D%0A  public final void surrogates() %7B%0D%0A    assertEquals(STR, string(token(STR)));%0D%0A  %7D%0D%0A%0D%0A  /** Tests entity parsing with big codepoints. */%0D%0A  @Test%0D%0A  public final void surrogates2() %7B%0D%0A    assertEquals(STR, query(String.format(%22'&#x%2506x;'%22, CP)));%0D%0A  %7D%0D%0A%0D%0A  /** Tests string creation from bytes. */%0D%0A  @Test%0D%0A  public final void surrogates3() %7B%0D%0A    assertEquals(STR, string(BA));%0D%0A  %7D%0D%0A%0D%0A  /** Tests reading a big codepoint from a token. */%0D%0A  @Test%0D%0A  public final void surrogates4() %7B%0D%0A    assertEquals(CP, cp(BA, 0));%0D%0A  %7D%0D%0A  %0D%0A  /**%0D%0A   * Executes a query and returns the serialized result.%0D%0A   * @param xq query%0D%0A   * @return result%0D%0A   */%0D%0A  private static String query(final String xq) %7B%0D%0A    try %7B%0D%0A      return new XQuery(xq).execute(context);%0D%0A    %7D catch(BaseXException e) %7B%0D%0A      fail(e.getMessage());%0D%0A      return null; // never reached%0D%0A    %7D%0D%0A  %7D%0D%0A  %0D%0A%7D%0D%0A

test cases for String <-> Token conversions