You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RegexStringListTest.java 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
  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 java.util.ArrayList;
  24. import java.util.List;
  25. import org.junit.Test;
  26. import static org.junit.Assert.*;
  27. public class RegexStringListTest {
  28. @Test
  29. public void testAdd() {
  30. final RegexStringList list = new RegexStringList();
  31. list.add("a!b@c");
  32. list.add("a!b@c");
  33. list.add("A!B@c");
  34. assertEquals(1, list.count());
  35. assertEquals("a!b@c", list.get(0));
  36. }
  37. @Test
  38. public void testAddAll() {
  39. final List<String> tempList = new ArrayList<String>();
  40. tempList.add("a!b@c");
  41. tempList.add("a!b@c");
  42. tempList.add("A!B@C");
  43. tempList.add("Data.*");
  44. final RegexStringList list = new RegexStringList(tempList);
  45. assertEquals(2, list.count());
  46. assertEquals("a!b@c", list.get(0));
  47. assertEquals("Data.*", list.get(1));
  48. }
  49. @Test
  50. public void testRmove() {
  51. final List<String> tempList = new ArrayList<String>();
  52. tempList.add("a!b@c");
  53. tempList.add("Data.*");
  54. final RegexStringList list = new RegexStringList(tempList);
  55. list.remove(0);
  56. list.remove(17);
  57. assertEquals(1, list.count());
  58. assertEquals("Data.*", list.get(0));
  59. }
  60. @Test
  61. public void testClear() {
  62. final List<String> tempList = new ArrayList<String>();
  63. tempList.add("a!b@c");
  64. tempList.add("Data.*");
  65. final RegexStringList list = new RegexStringList(tempList);
  66. list.clear();
  67. assertEquals(0, list.count());
  68. }
  69. @Test
  70. public void testMatches() {
  71. final List<String> tempList = new ArrayList<String>();
  72. tempList.add("a!b@c");
  73. tempList.add("Data.*");
  74. final RegexStringList list = new RegexStringList(tempList);
  75. assertTrue(list.matches("a!b@c") == 0);
  76. assertTrue(list.matches("foo") == -1);
  77. assertTrue(list.matches("Dataforce") == 1);
  78. assertFalse(list.matches(100, "Dataforce"));
  79. assertTrue(list.matches(1, "Dataforce"));
  80. }
  81. @Test
  82. public void testGet() {
  83. final RegexStringList list = new RegexStringList();
  84. list.add("a!b@c");
  85. assertEquals("a!b@c", list.get(0));
  86. assertEquals("", list.get(7));
  87. }
  88. @Test
  89. public void testSet() {
  90. final RegexStringList list = new RegexStringList();
  91. list.add("a!b@c");
  92. list.set(0, "moo");
  93. list.set(1, "bar");
  94. assertEquals(1, list.count());
  95. assertEquals("moo", list.get(0));
  96. }
  97. }