@Test
  public void testEqualsWithWhitespace() {
    final RawText a =
        new RawText(Constants.encodeASCII("foo-a\n         \n a b c\na      \n  foo\na  b  c\n"));
    final RawText b =
        new RawText(Constants.encodeASCII("foo-a        b\n\nab  c\na\nfoo\na b     c  \n"));

    // "foo-a" != "foo-a        b"
    assertFalse(cmp.equals(a, 0, b, 0));
    assertFalse(cmp.equals(b, 0, a, 0));

    // "         " == ""
    assertTrue(cmp.equals(a, 1, b, 1));
    assertTrue(cmp.equals(b, 1, a, 1));

    // " a b c" != "ab  c"
    assertFalse(cmp.equals(a, 2, b, 2));
    assertFalse(cmp.equals(b, 2, a, 2));

    // "a      " == "a"
    assertTrue(cmp.equals(a, 3, b, 3));
    assertTrue(cmp.equals(b, 3, a, 3));

    // "  foo" != "foo"
    assertFalse(cmp.equals(a, 4, b, 4));
    assertFalse(cmp.equals(b, 4, a, 4));

    // "a  b  c" == "a b     c  "
    assertTrue(cmp.equals(a, 5, b, 5));
    assertTrue(cmp.equals(b, 5, a, 5));
  }
Ejemplo n.º 2
0
  /**
   * Update the dumb client server info files.
   *
   * @throws Exception
   */
  public void updateServerInfo() throws Exception {
    if (db instanceof FileRepository) {
      final FileRepository fr = (FileRepository) db;
      RefWriter rw =
          new RefWriter(fr.getAllRefs().values()) {
            @Override
            protected void writeFile(final String name, final byte[] bin) throws IOException {
              File path = new File(fr.getDirectory(), name);
              TestRepository.this.writeFile(path, bin);
            }
          };
      rw.writePackedRefs();
      rw.writeInfoRefs();

      final StringBuilder w = new StringBuilder();
      for (PackFile p : fr.getObjectDatabase().getPacks()) {
        w.append("P ");
        w.append(p.getPackFile().getName());
        w.append('\n');
      }
      writeFile(
          new File(new File(fr.getObjectDatabase().getDirectory(), "info"), "packs"),
          Constants.encodeASCII(w.toString()));
    }
  }
Ejemplo n.º 3
0
 private static void assertHash(RevObject id, byte[] bin) {
   MessageDigest md = Constants.newMessageDigest();
   md.update(Constants.encodedTypeString(id.getType()));
   md.update((byte) ' ');
   md.update(Constants.encodeASCII(bin.length));
   md.update((byte) 0);
   md.update(bin);
   assertEquals(id, ObjectId.fromRaw(md.digest()));
 }
  public void testEqualsWithoutWhitespace() {
    final RawText a = new RawText(cmp, Constants.encodeASCII("foo-a\nfoo-b\nfoo\n"));
    final RawText b = new RawText(cmp, Constants.encodeASCII("foo-b\nfoo-c\nf\n"));

    assertEquals(3, a.size());
    assertEquals(3, b.size());

    // foo-a != foo-b
    assertFalse(cmp.equals(a, 0, b, 0));
    assertFalse(cmp.equals(b, 0, a, 0));

    // foo-b == foo-b
    assertTrue(cmp.equals(a, 1, b, 0));
    assertTrue(cmp.equals(b, 0, a, 1));

    // foo != f
    assertFalse(cmp.equals(a, 2, b, 2));
    assertFalse(cmp.equals(b, 2, a, 2));
  }
Ejemplo n.º 5
0
 static {
   String[] list =
       new String[] {
         "AUX", "COM1", "COM2", "COM3",
         "COM4", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
         "COM5", "COM6", "COM7", "COM8", "COM9", "CON", "LPT1",
         "LPT2", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
                 // //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
         "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9",
         "NUL", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
                // //$NON-NLS-7$ //$NON-NLS-8$
         "PRN"
       }; //$NON-NLS-1$
   forbidden = new byte[list.length][];
   for (int i = 0; i < list.length; ++i) forbidden[i] = Constants.encodeASCII(list[i]);
 }