Skip to content

Commit 2e309d6

Browse files
committed
DEVEXP-213 Formatted assertion functions for easier doc generation
Put method signatures on one line - not my favorite, but that's how most of the functions already were, and it makes it easier to generate a list of method signatures. Also removed commented out "item" signatures.
1 parent af28323 commit 2e309d6

File tree

2 files changed

+48
-38
lines changed

2 files changed

+48
-38
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.marklogic.test.unit;
2+
3+
import java.io.BufferedReader;
4+
import java.io.File;
5+
import java.io.FileReader;
6+
import java.io.IOException;
7+
import java.util.ArrayList;
8+
import java.util.Collections;
9+
import java.util.List;
10+
11+
/**
12+
* Not a test, just a simple tool for printing all the non-deprecated assertion functions found in test-helper.xqy.
13+
* The printed output is intended to be inserted into the ./docs/assertions/index.html file on the gh-pages branch.
14+
*/
15+
public class AssertFunctionPrinter {
16+
17+
public static void main(String[] args) throws IOException {
18+
File file = new File("marklogic-unit-test-modules/src/main/ml-modules/root/test/test-helper.xqy");
19+
List<String> signatures = new ArrayList<>();
20+
21+
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
22+
String line = reader.readLine();
23+
while (line != null) {
24+
if (line.contains("declare function test:assert-") && !line.contains("assert-meets")) {
25+
signatures.add(line.replaceAll("declare function test:", "").replaceAll(" \\{", "").trim());
26+
}
27+
line = reader.readLine();
28+
}
29+
}
30+
31+
Collections.sort(signatures);
32+
signatures.forEach(signature -> System.out.println("<li>" + signature + "</li>"));
33+
}
34+
}

marklogic-unit-test-modules/src/main/ml-modules/root/test/test-helper.xqy

Lines changed: 14 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ declare function test:easy-url($url) as xs:string
189189
fn:concat($local-url, if (fn:starts-with($url, "/")) then "" else "/", $url)
190190
};
191191

192-
declare function test:http-get($url as xs:string, $options as item()?(:as (element(xdmp-http:options)|map:map)?:))
192+
declare function test:http-get($url as xs:string, $options as item()?)
193193
{
194194
let $uri := test:easy-url($url)
195195
return
@@ -200,45 +200,45 @@ declare function test:assert-http-get-status($url as xs:string, $options as item
200200
test:assert-http-get-status( $url, $options, $status-code, ())
201201
};
202202

203-
declare function test:assert-http-get-status($url as xs:string, $options as item()?(:as (element(xdmp-http:options)|map:map)?:), $status-code, $message as xs:string*)
203+
declare function test:assert-http-get-status($url as xs:string, $options as item()?, $status-code, $message as xs:string*)
204204
{
205205
let $response := test:http-get($url, $options)
206206
return
207207
test:assert-equal($status-code, fn:data($response[1]/*:code), $message)
208208
};
209209

210-
declare function test:http-post($url as xs:string, $options as item()?(:as (element(xdmp-http:options)|map:map)?:), $data as node()?)
210+
declare function test:http-post($url as xs:string, $options as item()?, $data as node()?)
211211
{
212212
let $uri := test:easy-url($url)
213213
return
214214
xdmp:http-post($uri, $options, $data)
215215
};
216216

217-
declare function test:assert-http-post-status($url as xs:string, $options as item()?(:as (element(xdmp-http:options)|map:map)?:), $data as node()?, $status-code)
217+
declare function test:assert-http-post-status($url as xs:string, $options as item()?, $data as node()?, $status-code)
218218
{
219219
assert-http-post-status($url, $options, $data, $status-code, ())
220220
};
221221

222-
declare function test:assert-http-post-status($url as xs:string, $options as item()?(:as (element(xdmp-http:options)|map:map)?:), $data as node()?, $status-code, $message as xs:string*)
222+
declare function test:assert-http-post-status($url as xs:string, $options as item()?, $data as node()?, $status-code, $message as xs:string*)
223223
{
224224
let $response := test:http-post($url, $options, $data)
225225
return
226226
test:assert-equal($status-code, fn:data($response[1]/*:code), $message)
227227
};
228228

229-
declare function test:http-put($url as xs:string, $options as item()?(:as (element(xdmp-http:options)|map:map)?:), $data as node()?)
229+
declare function test:http-put($url as xs:string, $options as item()?, $data as node()?)
230230
{
231231
let $uri := test:easy-url($url)
232232
return
233233
xdmp:http-put($uri, $options, $data)
234234
};
235235

236-
declare function test:assert-http-put-status($url as xs:string, $options as item()?(:as (element(xdmp-http:options)|map:map)?:), $data as node()?, $status-code)
236+
declare function test:assert-http-put-status($url as xs:string, $options as item()?, $data as node()?, $status-code)
237237
{
238238
test:assert-http-put-status($url, $options, $data, $status-code, ())
239239
};
240240

241-
declare function test:assert-http-put-status($url as xs:string, $options as item()?(:as (element(xdmp-http:options)|map:map)?:), $data as node()?, $status-code, $message as xs:string*)
241+
declare function test:assert-http-put-status($url as xs:string, $options as item()?, $data as node()?, $status-code, $message as xs:string*)
242242
{
243243
let $response := test:http-put($url, $options, $data)
244244
return
@@ -763,11 +763,7 @@ declare function test:assert-meets-minimum-threshold($minimum as xs:decimal, $ac
763763
};
764764

765765
(: Deprecated. Replaced by test:assert-greater-than-or-equal(). :)
766-
declare function test:assert-meets-minimum-threshold(
767-
$minimum as xs:decimal,
768-
$actual as xs:decimal+,
769-
$message as xs:string*
770-
) {
766+
declare function test:assert-meets-minimum-threshold($minimum as xs:decimal, $actual as xs:decimal+, $message as xs:string*) {
771767
(
772768
if (every $i in 1 to fn:count($actual) satisfies $actual[$i] ge $minimum) then
773769
test:success()
@@ -792,11 +788,7 @@ declare function test:assert-meets-maximum-threshold($maximum as xs:decimal, $ac
792788
};
793789

794790
(: Deprecated. Replaced by test:assert-less-than-or-equal(). :)
795-
declare function test:assert-meets-maximum-threshold(
796-
$maximum as xs:decimal,
797-
$actual as xs:decimal+,
798-
$message as xs:string?
799-
) {
791+
declare function test:assert-meets-maximum-threshold($maximum as xs:decimal, $actual as xs:decimal+, $message as xs:string?) {
800792
(
801793
if (every $i in 1 to fn:count($actual) satisfies $actual[$i] le $maximum) then
802794
test:success()
@@ -817,11 +809,7 @@ declare function test:assert-greater-than($value as xs:decimal, $actual as xs:de
817809
test:assert-greater-than($value, $actual, ())
818810
};
819811

820-
declare function test:assert-greater-than(
821-
$value as xs:decimal,
822-
$actual as xs:decimal+,
823-
$message as xs:string*
824-
) {
812+
declare function test:assert-greater-than($value as xs:decimal, $actual as xs:decimal+, $message as xs:string*) {
825813
if (every $i in 1 to fn:count($actual) satisfies $actual[$i] gt $value) then
826814
test:success()
827815
else
@@ -837,11 +825,7 @@ declare function test:assert-greater-than-or-equal($minimum as xs:decimal, $actu
837825
test:assert-greater-than-or-equal($minimum, $actual, ())
838826
};
839827

840-
declare function test:assert-greater-than-or-equal(
841-
$value as xs:decimal,
842-
$actual as xs:decimal+,
843-
$message as xs:string*
844-
) {
828+
declare function test:assert-greater-than-or-equal($value as xs:decimal, $actual as xs:decimal+, $message as xs:string*) {
845829
if (every $i in 1 to fn:count($actual) satisfies $actual[$i] ge $value) then
846830
test:success()
847831
else
@@ -857,11 +841,7 @@ declare function test:assert-less-than($value as xs:decimal, $actual as xs:decim
857841
test:assert-less-than($value, $actual, ())
858842
};
859843

860-
declare function test:assert-less-than(
861-
$value as xs:decimal,
862-
$actual as xs:decimal+,
863-
$message as xs:string?
864-
) {
844+
declare function test:assert-less-than($value as xs:decimal, $actual as xs:decimal+, $message as xs:string?) {
865845
if (every $i in 1 to fn:count($actual) satisfies $actual[$i] lt $value) then
866846
test:success()
867847
else
@@ -878,11 +858,7 @@ declare function test:assert-less-than-or-equal($maximum as xs:decimal, $actual
878858
test:assert-less-than-or-equal($maximum, $actual, ())
879859
};
880860

881-
declare function test:assert-less-than-or-equal(
882-
$value as xs:decimal,
883-
$actual as xs:decimal+,
884-
$message as xs:string?
885-
) {
861+
declare function test:assert-less-than-or-equal($value as xs:decimal, $actual as xs:decimal+, $message as xs:string?) {
886862
if (every $i in 1 to fn:count($actual) satisfies $actual[$i] le $value) then
887863
test:success()
888864
else

0 commit comments

Comments
 (0)