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

RegexStringListTest.java 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * Copyright (c) 2006-2015 DMDirc Developers
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to deal
  6. * in the Software without restriction, including without limitation the rights
  7. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. * copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. * SOFTWARE.
  21. */
  22. package com.dmdirc.parser.irc;
  23. import com.dmdirc.parser.common.IgnoreList;
  24. import java.util.ArrayList;
  25. import java.util.List;
  26. import org.junit.Test;
  27. import static org.junit.Assert.*;
  28. public class RegexStringListTest {
  29. @Test
  30. public void testAdd() {
  31. final IgnoreList list = new IgnoreList();
  32. list.add("a!b@c");
  33. list.add("a!b@c");
  34. list.add("A!B@c");
  35. assertEquals(1, list.count());
  36. assertEquals("a!b@c", list.get(0));
  37. }
  38. @Test
  39. public void testAddAll() {
  40. final List<String> tempList = new ArrayList<>();
  41. tempList.add("a!b@c");
  42. tempList.add("a!b@c");
  43. tempList.add("A!B@C");
  44. tempList.add("Data.*");
  45. final IgnoreList list = new IgnoreList(tempList);
  46. assertEquals(2, list.count());
  47. assertEquals("a!b@c", list.get(0));
  48. assertEquals("Data.*", list.get(1));
  49. }
  50. @Test
  51. public void testRmove() {
  52. final List<String> tempList = new ArrayList<>();
  53. tempList.add("a!b@c");
  54. tempList.add("Data.*");
  55. final IgnoreList list = new IgnoreList(tempList);
  56. list.remove(0);
  57. list.remove(17);
  58. assertEquals(1, list.count());
  59. assertEquals("Data.*", list.get(0));
  60. }
  61. @Test
  62. public void testClear() {
  63. final List<String> tempList = new ArrayList<>();
  64. tempList.add("a!b@c");
  65. tempList.add("Data.*");
  66. final IgnoreList list = new IgnoreList(tempList);
  67. list.clear();
  68. assertEquals(0, list.count());
  69. }
  70. @Test
  71. public void testMatches() {
  72. final List<String> tempList = new ArrayList<>();
  73. tempList.add("a!b@c");
  74. tempList.add("Data.*");
  75. final IgnoreList list = new IgnoreList(tempList);
  76. assertEquals(0, list.matches("a!b@c"));
  77. assertEquals(-1, list.matches("foo"));
  78. assertEquals(1, list.matches("Dataforce"));
  79. assertFalse(list.matches(100, "Dataforce"));
  80. assertTrue(list.matches(1, "Dataforce"));
  81. }
  82. @Test
  83. public void testGet() {
  84. final IgnoreList list = new IgnoreList();
  85. list.add("a!b@c");
  86. assertEquals("a!b@c", list.get(0));
  87. assertEquals("", list.get(7));
  88. }
  89. @Test
  90. public void testSet() {
  91. final IgnoreList list = new IgnoreList();
  92. list.add("a!b@c");
  93. list.set(0, "moo");
  94. list.set(1, "bar");
  95. assertEquals(1, list.count());
  96. assertEquals("moo", list.get(0));
  97. }
  98. }