Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

CoreActionComparisonTest.java 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * Copyright (c) 2006-2013 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.actions;
  23. import org.junit.Test;
  24. import static org.junit.Assert.*;
  25. public class CoreActionComparisonTest {
  26. @Test
  27. public void testStringRegex() {
  28. assertEquals(String.class, CoreActionComparison.STRING_REGEX.appliesTo());
  29. assertTrue(CoreActionComparison.STRING_REGEX.getName().toLowerCase().indexOf("reg") > -1);
  30. assertTrue(CoreActionComparison.STRING_REGEX.test("hello", "h.*?o"));
  31. assertFalse(CoreActionComparison.STRING_REGEX.test("hello", "h.{8}o"));
  32. assertFalse(CoreActionComparison.STRING_REGEX.test("hello", "?!!?!{}"));
  33. }
  34. @Test
  35. public void testStringEquals() {
  36. assertEquals(String.class, CoreActionComparison.STRING_EQUALS.appliesTo());
  37. assertTrue(CoreActionComparison.STRING_EQUALS.getName().toLowerCase().indexOf("equal") > -1);
  38. assertTrue(CoreActionComparison.STRING_EQUALS.test("hello", "hello"));
  39. assertTrue(CoreActionComparison.STRING_EQUALS.test("hello", "HELLO"));
  40. assertFalse(CoreActionComparison.STRING_EQUALS.test("hello", "h.{8}o"));
  41. assertFalse(CoreActionComparison.STRING_EQUALS.test("hello", "?!!?!{}"));
  42. }
  43. @Test
  44. public void testStringNEquals() {
  45. assertEquals(String.class, CoreActionComparison.STRING_NEQUALS.appliesTo());
  46. assertTrue(CoreActionComparison.STRING_NEQUALS.getName().toLowerCase().indexOf("equal") > -1);
  47. assertTrue(CoreActionComparison.STRING_NEQUALS.getName().toLowerCase().indexOf("not") > -1
  48. || CoreActionComparison.STRING_NEQUALS.getName().toLowerCase().indexOf("n't") > -1);
  49. assertFalse(CoreActionComparison.STRING_NEQUALS.test("hello", "hello"));
  50. assertFalse(CoreActionComparison.STRING_NEQUALS.test("hello", "HELLO"));
  51. assertTrue(CoreActionComparison.STRING_NEQUALS.test("hello", "h.{8}o"));
  52. assertTrue(CoreActionComparison.STRING_NEQUALS.test("hello", "?!!?!{}"));
  53. }
  54. @Test
  55. public void testStringStartsWith() {
  56. assertEquals(String.class, CoreActionComparison.STRING_STARTSWITH.appliesTo());
  57. assertTrue(CoreActionComparison.STRING_STARTSWITH.getName().toLowerCase()
  58. .indexOf("start") > -1);
  59. assertTrue(CoreActionComparison.STRING_STARTSWITH.test("hello", "hello"));
  60. assertTrue(CoreActionComparison.STRING_STARTSWITH.test("hello", "he"));
  61. assertFalse(CoreActionComparison.STRING_STARTSWITH.test("hello", "h.{8}o"));
  62. assertFalse(CoreActionComparison.STRING_STARTSWITH.test("hello", "?!!?!{}"));
  63. }
  64. @Test
  65. public void testStringContains() {
  66. assertEquals(String.class, CoreActionComparison.STRING_CONTAINS.appliesTo());
  67. assertTrue(CoreActionComparison.STRING_CONTAINS.getName().toLowerCase()
  68. .indexOf("contain") > -1);
  69. assertTrue(CoreActionComparison.STRING_CONTAINS.test("hello", "hello"));
  70. assertTrue(CoreActionComparison.STRING_CONTAINS.test("hello", "lo"));
  71. assertFalse(CoreActionComparison.STRING_CONTAINS.test("hello", "h.{8}o"));
  72. assertFalse(CoreActionComparison.STRING_CONTAINS.test("hello", "?!!?!{}"));
  73. }
  74. @Test
  75. public void testStringNContains() {
  76. assertEquals(String.class, CoreActionComparison.STRING_NCONTAINS.appliesTo());
  77. assertTrue(CoreActionComparison.STRING_NCONTAINS.getName().toLowerCase()
  78. .indexOf("contain") > -1);
  79. assertTrue(CoreActionComparison.STRING_NCONTAINS.getName().toLowerCase().indexOf("not") > -1
  80. || CoreActionComparison.STRING_NCONTAINS.getName().toLowerCase().indexOf("n't") > -1);
  81. assertFalse(CoreActionComparison.STRING_NCONTAINS.test("hello", "hello"));
  82. assertFalse(CoreActionComparison.STRING_NCONTAINS.test("hello", "lo"));
  83. assertTrue(CoreActionComparison.STRING_NCONTAINS.test("hello", "h.{8}o"));
  84. assertTrue(CoreActionComparison.STRING_NCONTAINS.test("hello", "?!!?!{}"));
  85. }
  86. @Test
  87. public void testBoolIs() {
  88. assertEquals(Boolean.class, CoreActionComparison.BOOL_IS.appliesTo());
  89. assertTrue(CoreActionComparison.BOOL_IS.getName().toLowerCase()
  90. .indexOf("is") > -1);
  91. assertTrue(CoreActionComparison.BOOL_IS.test(Boolean.TRUE, "true"));
  92. assertTrue(CoreActionComparison.BOOL_IS.test(Boolean.FALSE, "false"));
  93. assertFalse(CoreActionComparison.BOOL_IS.test(Boolean.FALSE, "true"));
  94. assertFalse(CoreActionComparison.BOOL_IS.test(Boolean.TRUE, "false"));
  95. }
  96. }