Skip to content

Commit

Permalink
add some more array sort border test to be sure...
Browse files Browse the repository at this point in the history
  • Loading branch information
rbri committed Aug 10, 2024
1 parent 4bb73af commit 3138460
Showing 1 changed file with 78 additions and 2 deletions.
80 changes: 78 additions & 2 deletions src/test/java/org/htmlunit/javascript/NativeArrayTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,55 @@ public void sortSteps() throws Exception {
}

/**
* Test for sort algorithm used (when sort is called with callback).
* Test for sort callback returning bool instead of int.
* @throws Exception if the test fails
*/
@Test
@Alerts("1,1,2,5,9")
public void sortIntComperator() throws Exception {
final String html
= "<html><head><script>\n"
+ LOG_TITLE_FUNCTION
+ "function compare(x, y) {\n"
+ " return x - y;\n"
+ "}\n"
+ "function doTest() {\n"
+ " var t = [1, 5, 2, 1, 9];\n"
+ " t.sort(compare);\n"
+ " log(t);\n"
+ "}\n"
+ "</script></head><body onload='doTest()'>\n"
+ "</body></html>";

loadPageVerifyTitle2(html);
}

/**
* Test for sort callback returning bool instead of int.
* @throws Exception if the test fails
*/
@Test
@Alerts("1,1,2,5,9")
public void sortSmallDoublesComperator() throws Exception {
final String html
= "<html><head><script>\n"
+ LOG_TITLE_FUNCTION
+ "function compare(x, y) {\n"
+ " return (x - y) / 1001;\n"
+ "}\n"
+ "function doTest() {\n"
+ " var t = [1, 5, 2, 1, 9];\n"
+ " t.sort(compare);\n"
+ " log(t);\n"
+ "}\n"
+ "</script></head><body onload='doTest()'>\n"
+ "</body></html>";

loadPageVerifyTitle2(html);
}

/**
* Test for sort callback returning bool instead of int.
* @throws Exception if the test fails
*/
@Test
Expand All @@ -88,7 +136,7 @@ public void sortBoolComperator() throws Exception {
}

/**
* Test for sort algorithm used (when sort is called with callback).
* Test for sort callback..
* @throws Exception if the test fails
*/
@Test
Expand All @@ -111,6 +159,34 @@ public void sortBool2IntComperator() throws Exception {
loadPageVerifyTitle2(html);
}

/**
* Test for sort callback..
* @throws Exception if the test fails
*/
@Test
@Alerts(DEFAULT = "1,5,2,1,9",
FF = "9,1,2,5,1",
FF_ESR = "9,1,2,5,1")
@HtmlUnitNYI(FF = "1,5,2,1,9",
FF_ESR = "1,5,2,1,9")
public void sortInvalidComperator() throws Exception {
final String html
= "<html><head><script>\n"
+ LOG_TITLE_FUNCTION
+ "function compare(x, y) {\n"
+ " return 1;\n"
+ "}\n"
+ "function doTest() {\n"
+ " var t = ['1', '5', '2', '1', '9'];\n"
+ " t.sort(compare);\n"
+ " log(t);\n"
+ "}\n"
+ "</script></head><body onload='doTest()'>\n"
+ "</body></html>";

loadPageVerifyTitle2(html);
}

/**
* Test for the methods with the same expectations for all browsers.
* @throws Exception if the test fails
Expand Down

0 comments on commit 3138460

Please sign in to comment.