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.

CoreActionComparisonTest.java 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * Copyright (c) 2006-2014 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().contains("reg"));
  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().contains("equal"));
  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().contains("equal"));
  47. assertTrue(CoreActionComparison.STRING_NEQUALS.getName().toLowerCase().contains("not")
  48. || CoreActionComparison.STRING_NEQUALS.getName().toLowerCase().contains("n't"));
  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().contains("start"));
  58. assertTrue(CoreActionComparison.STRING_STARTSWITH.test("hello", "hello"));
  59. assertTrue(CoreActionComparison.STRING_STARTSWITH.test("hello", "he"));
  60. assertFalse(CoreActionComparison.STRING_STARTSWITH.test("hello", "h.{8}o"));
  61. assertFalse(CoreActionComparison.STRING_STARTSWITH.test("hello", "?!!?!{}"));
  62. }
  63. @Test
  64. public void testStringContains() {
  65. assertEquals(String.class, CoreActionComparison.STRING_CONTAINS.appliesTo());
  66. assertTrue(CoreActionComparison.STRING_CONTAINS.getName().toLowerCase().contains("contain"));
  67. assertTrue(CoreActionComparison.STRING_CONTAINS.test("hello", "hello"));
  68. assertTrue(CoreActionComparison.STRING_CONTAINS.test("hello", "lo"));
  69. assertFalse(CoreActionComparison.STRING_CONTAINS.test("hello", "h.{8}o"));
  70. assertFalse(CoreActionComparison.STRING_CONTAINS.test("hello", "?!!?!{}"));
  71. }
  72. @Test
  73. public void testStringNContains() {
  74. assertEquals(String.class, CoreActionComparison.STRING_NCONTAINS.appliesTo());
  75. assertTrue(
  76. CoreActionComparison.STRING_NCONTAINS.getName().toLowerCase().contains("contain"));
  77. assertTrue(CoreActionComparison.STRING_NCONTAINS.getName().toLowerCase().contains("not")
  78. || CoreActionComparison.STRING_NCONTAINS.getName().toLowerCase().contains("n't"));
  79. assertFalse(CoreActionComparison.STRING_NCONTAINS.test("hello", "hello"));
  80. assertFalse(CoreActionComparison.STRING_NCONTAINS.test("hello", "lo"));
  81. assertTrue(CoreActionComparison.STRING_NCONTAINS.test("hello", "h.{8}o"));
  82. assertTrue(CoreActionComparison.STRING_NCONTAINS.test("hello", "?!!?!{}"));
  83. }
  84. @Test
  85. public void testBoolIs() {
  86. assertEquals(Boolean.class, CoreActionComparison.BOOL_IS.appliesTo());
  87. assertTrue(CoreActionComparison.BOOL_IS.getName().toLowerCase().contains("is"));
  88. assertTrue(CoreActionComparison.BOOL_IS.test(Boolean.TRUE, "true"));
  89. assertTrue(CoreActionComparison.BOOL_IS.test(Boolean.FALSE, "false"));
  90. assertFalse(CoreActionComparison.BOOL_IS.test(Boolean.FALSE, "true"));
  91. assertFalse(CoreActionComparison.BOOL_IS.test(Boolean.TRUE, "false"));
  92. }
  93. }