選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

RawCharUtilTest.java 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * Copyright (C) 2010, Google Inc. and others
  3. *
  4. * This program and the accompanying materials are made available under the
  5. * terms of the Eclipse Distribution License v. 1.0 which is available at
  6. * https://www.eclipse.org/org/documents/edl-v10.php.
  7. *
  8. * SPDX-License-Identifier: BSD-3-Clause
  9. */
  10. package org.eclipse.jgit.util;
  11. import static java.nio.charset.StandardCharsets.US_ASCII;
  12. import static org.eclipse.jgit.util.RawCharUtil.isWhitespace;
  13. import static org.eclipse.jgit.util.RawCharUtil.trimLeadingWhitespace;
  14. import static org.eclipse.jgit.util.RawCharUtil.trimTrailingWhitespace;
  15. import static org.junit.Assert.assertEquals;
  16. import static org.junit.Assert.assertFalse;
  17. import static org.junit.Assert.assertTrue;
  18. import org.junit.Test;
  19. public class RawCharUtilTest {
  20. /**
  21. * Test method for {@link RawCharUtil#isWhitespace(byte)}.
  22. */
  23. @Test
  24. public void testIsWhitespace() {
  25. for (byte c = -128; c < 127; c++) {
  26. switch (c) {
  27. case (byte) '\r':
  28. case (byte) '\n':
  29. case (byte) '\t':
  30. case (byte) ' ':
  31. assertTrue(isWhitespace(c));
  32. break;
  33. default:
  34. assertFalse(isWhitespace(c));
  35. }
  36. }
  37. }
  38. /**
  39. * Test method for
  40. * {@link RawCharUtil#trimTrailingWhitespace(byte[], int, int)}.
  41. */
  42. @Test
  43. public void testTrimTrailingWhitespace() {
  44. assertEquals(0, trimTrailingWhitespace("".getBytes(US_ASCII), 0, 0));
  45. assertEquals(0, trimTrailingWhitespace(" ".getBytes(US_ASCII), 0, 1));
  46. assertEquals(1, trimTrailingWhitespace("a ".getBytes(US_ASCII), 0, 2));
  47. assertEquals(2, trimTrailingWhitespace(" a ".getBytes(US_ASCII), 0, 3));
  48. assertEquals(3, trimTrailingWhitespace(" a".getBytes(US_ASCII), 0, 3));
  49. assertEquals(6,
  50. trimTrailingWhitespace(" test ".getBytes(US_ASCII), 2, 9));
  51. }
  52. /**
  53. * Test method for
  54. * {@link RawCharUtil#trimLeadingWhitespace(byte[], int, int)}.
  55. */
  56. @Test
  57. public void testTrimLeadingWhitespace() {
  58. assertEquals(0, trimLeadingWhitespace("".getBytes(US_ASCII), 0, 0));
  59. assertEquals(1, trimLeadingWhitespace(" ".getBytes(US_ASCII), 0, 1));
  60. assertEquals(0, trimLeadingWhitespace("a ".getBytes(US_ASCII), 0, 2));
  61. assertEquals(1, trimLeadingWhitespace(" a ".getBytes(US_ASCII), 0, 3));
  62. assertEquals(2, trimLeadingWhitespace(" a".getBytes(US_ASCII), 0, 3));
  63. assertEquals(2,
  64. trimLeadingWhitespace(" test ".getBytes(US_ASCII),
  65. 2, 9));
  66. }
  67. }