/projects/htmlunit-2.8/src/test/java/com/gargoylesoftware/htmlunit/javascript/regexp/mozilla/js1_2/StringSplitTest.java

https://gitlab.com/essere.lab.public/qualitas.class-corpus · Java · 136 lines · 67 code · 13 blank · 56 comment · 0 complexity · 04ce37434a5412b615a115d10157820a MD5 · raw file

  1. /*
  2. * Copyright (c) 2002-2010 Gargoyle Software Inc.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. package com.gargoylesoftware.htmlunit.javascript.regexp.mozilla.js1_2;
  16. import org.junit.Test;
  17. import org.junit.runner.RunWith;
  18. import com.gargoylesoftware.htmlunit.BrowserRunner;
  19. import com.gargoylesoftware.htmlunit.WebDriverTestCase;
  20. import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts;
  21. import com.gargoylesoftware.htmlunit.BrowserRunner.Browser;
  22. import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented;
  23. /**
  24. * Tests originally in '/js/src/tests/js1_2/regexp/string_split.js'.
  25. *
  26. * @version $Revision: 5902 $
  27. * @author Ahmed Ashour
  28. */
  29. @RunWith(BrowserRunner.class)
  30. public class StringSplitTest extends WebDriverTestCase {
  31. /**
  32. * Tests 'a b c de f'.split(/\s/).
  33. * @throws Exception if the test fails
  34. */
  35. @Test
  36. @Alerts("a,b,c,de,f")
  37. public void test1() throws Exception {
  38. test("'a b c de f'.split(/\\s/)");
  39. }
  40. /**
  41. * Tests 'a b c de f'.split(/\s/,3).
  42. * @throws Exception if the test fails
  43. */
  44. @Test
  45. @Alerts("a,b,c")
  46. public void test2() throws Exception {
  47. test("'a b c de f'.split(/\\s/,3)");
  48. }
  49. /**
  50. * Tests 'a b c de f'.split(/X/).
  51. * @throws Exception if the test fails
  52. */
  53. @Test
  54. @Alerts("a b c de f")
  55. public void test3() throws Exception {
  56. test("'a b c de f'.split(/X/)");
  57. }
  58. /**
  59. * Tests 'dfe23iu 34 =+65--'.split(/\d+/).
  60. * @throws Exception if the test fails
  61. */
  62. @Test
  63. @Alerts("dfe,iu , =+,--")
  64. public void test4() throws Exception {
  65. test("'dfe23iu 34 =+65--'.split(/\\d+/)");
  66. }
  67. /**
  68. * Tests 'dfe23iu 34 =+65--'.split(new RegExp('\\d+')).
  69. * @throws Exception if the test fails
  70. */
  71. @Test
  72. @Alerts("dfe,iu , =+,--")
  73. public void test5() throws Exception {
  74. test("'dfe23iu 34 =+65--'.split(new RegExp('\\\\d+'))");
  75. }
  76. /**
  77. * Tests 'abc'.split(/[a-z]/).
  78. * @throws Exception if the test fails
  79. */
  80. @Test
  81. @Alerts(FF = ",,,", IE = "")
  82. @NotYetImplemented(Browser.IE)
  83. public void test6() throws Exception {
  84. test("'abc'.split(/[a-z]/)");
  85. }
  86. /**
  87. * Tests 'abc'.split(/[a-z]/).
  88. * @throws Exception if the test fails
  89. */
  90. @Test
  91. @Alerts(FF = ",,,", IE = "")
  92. @NotYetImplemented(Browser.IE)
  93. public void test7() throws Exception {
  94. test("'abc'.split(/[a-z]/)");
  95. }
  96. /**
  97. * Tests 'abc'.split(new RegExp('[a-z]')).
  98. * @throws Exception if the test fails
  99. */
  100. @Test
  101. @Alerts(FF = ",,,", IE = "")
  102. @NotYetImplemented(Browser.IE)
  103. public void test8() throws Exception {
  104. test("'abc'.split(new RegExp('[a-z]'))");
  105. }
  106. /**
  107. * Tests 'abc'.split(new RegExp('[a-z]')).
  108. * @throws Exception if the test fails
  109. */
  110. @Test
  111. @Alerts(FF = ",,,", IE = "")
  112. @NotYetImplemented(Browser.IE)
  113. public void test9() throws Exception {
  114. test("'abc'.split(new RegExp('[a-z]'))");
  115. }
  116. private void test(final String script) throws Exception {
  117. final String html = "<html><head><title>foo</title><script>\n"
  118. + " alert(" + script + ");\n"
  119. + "</script></head><body>\n"
  120. + "</body></html>";
  121. loadPageWithAlerts2(html);
  122. }
  123. }