Skip to content

Commit 667b02c

Browse files
chris-evolvedbinaryadamretter
authored andcommitted
[bugfix] Change fn:collation-key function signatures, and correct comparisons in fn:collation-key tests.
1 parent 845fc74 commit 667b02c

File tree

2 files changed

+33
-33
lines changed

2 files changed

+33
-33
lines changed

exist-core/src/main/java/org/exist/xquery/functions/fn/FunCollationKey.java

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,43 +32,43 @@
3232

3333
import java.nio.charset.StandardCharsets;
3434

35+
import static org.exist.xquery.FunctionDSL.*;
36+
3537
public class FunCollationKey extends BasicFunction {
3638

37-
private static final QName FN_NAME = new QName("collation-key", Function.BUILTIN_FUNCTION_NS, FnModule.PREFIX);
39+
private static final String FN_NAME = "collation-key"; // , Function.BUILTIN_FUNCTION_NS, FnModule.PREFIX);
3840
private static final String FN_DESCRIPTION =
39-
"Given a $value-string value and a $collection-string " +
41+
"Given a $value-string value and a $collation-string " +
4042
"collation, generates an internal value called a collation key, with the " +
4143
"property that the matching and ordering of collation " +
4244
"keys reflects the matching and ordering of strings " +
4345
"under the specified collation.";
44-
private static final FunctionReturnSequenceType FN_RETURN = new FunctionReturnSequenceType(
45-
Type.BASE64_BINARY, Cardinality.ZERO_OR_ONE, "the collation key"
46-
);
47-
48-
public static final FunctionSignature[] FS_COLLATION_KEY_SIGNATURES = {
49-
new FunctionSignature(FunCollationKey.FN_NAME, FunCollationKey.FN_DESCRIPTION,
50-
new SequenceType[] {
51-
new FunctionParameterSequenceType("value-string", Type.STRING,
52-
Cardinality.ZERO_OR_ONE, "The value string")
53-
}, FN_RETURN),
54-
new FunctionSignature(FunCollationKey.FN_NAME, FunCollationKey.FN_DESCRIPTION,
55-
new SequenceType[] {
56-
new FunctionParameterSequenceType("value-string", Type.STRING,
57-
Cardinality.ZERO_OR_ONE, "The value string"),
58-
new FunctionParameterSequenceType("collection-string", Type.STRING,
59-
Cardinality.ZERO_OR_ONE, "The collation string")
60-
}, FN_RETURN)
61-
};
46+
private static final FunctionReturnSequenceType FN_RETURN = returnsOpt(Type.BASE64_BINARY, "the collation key");
47+
private static final FunctionParameterSequenceType PARAM_VALUE_STRING = param("value-string", Type.STRING, "The value string");
48+
private static final FunctionParameterSequenceType PARAM_COLLATION_STRING = param("collation-string", Type.STRING, "The collation string");
49+
public static final FunctionSignature[] FS_COLLATION_KEY_SIGNATURES = functionSignatures(
50+
FN_NAME,
51+
FN_DESCRIPTION,
52+
FN_RETURN,
53+
arities(
54+
arity(PARAM_VALUE_STRING),
55+
arity(PARAM_VALUE_STRING, PARAM_COLLATION_STRING)
56+
)
57+
);
6258

6359
public FunCollationKey(final XQueryContext context, final FunctionSignature signature) {
6460
super(context, signature);
6561
}
6662

67-
public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
63+
public Sequence eval(final Sequence[] args, final Sequence contextSequence) throws XPathException {
6864
final String source = (args.length >= 1) ? args[0].toString() : "";
6965
final Collator collator = (args.length >= 2) ? Collations.getCollationFromURI(args[1].toString()) : null;
7066

7167
return new BinaryValueFromBinaryString(new Base64BinaryValueType(), Base64.encodeBase64String(
7268
(collator == null) ? source.getBytes(StandardCharsets.UTF_8) : new String(collator.getCollationKey(source).toByteArray()).getBytes(StandardCharsets.UTF_8)));
7369
}
70+
71+
private static FunctionSignature[] functionSignatures(final String name, final String description, final FunctionReturnSequenceType returnType, final FunctionParameterSequenceType[][] variableParamTypes) {
72+
return FunctionDSL.functionSignatures(new QName(name, Function.BUILTIN_FUNCTION_NS, FnModule.PREFIX), description, returnType, variableParamTypes);
73+
}
7474
}

exist-core/src/test/xquery/xquery3/fnCollationKey.xqm

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,55 +30,55 @@ declare
3030
function fnck:default-equal-case() {
3131
let $first := fn:collation-key("a")
3232
let $second := fn:collation-key("a")
33-
return $first = $second
33+
return $first eq $second
3434
};
3535

3636
declare
3737
%test:assertTrue
3838
function fnck:default-equal() {
3939
let $first := fn:collation-key("a")
4040
let $second := fn:collation-key("a")
41-
return $first = $second
41+
return $first eq $second
4242
};
4343

4444
declare
4545
%test:assertTrue
4646
function fnck:default-not-equal() {
4747
let $first := fn:collation-key("a")
4848
let $second := fn:collation-key("b")
49-
return $first != $second
49+
return $first ne $second
5050
};
5151

5252
declare
5353
%test:assertTrue
5454
function fnck:default-not-equal-ignore-case() {
5555
let $first := fn:collation-key("a")
5656
let $second := fn:collation-key("A")
57-
return $first != $second
57+
return $first ne $second
5858
};
5959

6060
declare
6161
%test:assertTrue
6262
function fnck:exist-equal() {
6363
let $first := fn:collation-key("a", "http://exist-db.org/collation")
6464
let $second := fn:collation-key("a", "http://exist-db.org/collation")
65-
return $first = $second
65+
return $first eq $second
6666
};
6767

6868
declare
6969
%test:assertTrue
7070
function fnck:exist-equal-ignore-case() {
7171
let $first := fn:collation-key("a", "http://exist-db.org/collation")
7272
let $second := fn:collation-key("A", "http://exist-db.org/collation")
73-
return $first = $second
73+
return $first eq $second
7474
};
7575

7676
declare
7777
%test:assertTrue
7878
function fnck:exist-not-equal() {
7979
let $first := fn:collation-key("a", "http://exist-db.org/collation")
8080
let $second := fn:collation-key("b", "http://exist-db.org/collation")
81-
return $first != $second
81+
return $first ne $second
8282
};
8383

8484
declare
@@ -92,21 +92,21 @@ declare
9292
function fnck:uca-equal() {
9393
let $first := fn:collation-key("a", "http://www.w3.org/2013/collation/UCA")
9494
let $second := fn:collation-key("a", "http://www.w3.org/2013/collation/UCA")
95-
return $first = $second
95+
return $first eq $second
9696
};
9797

9898
declare
9999
%test:assertTrue
100100
function fnck:uca-equal-ignore-case() {
101101
let $first := fn:collation-key("a", "http://www.w3.org/2013/collation/UCA")
102102
let $second := fn:collation-key("A", "http://www.w3.org/2013/collation/UCA")
103-
return $first = $second
103+
return $first eq $second
104104
};
105105

106106
declare
107107
%test:assertTrue
108108
function fnck:uca-not-equal() {
109-
let $first := fn:collation-key("a", "http://www.w3.org/2013/collation/UCA")
110-
let $second := fn:collation-key("b", "http://www.w3.org/2013/collation/UCA")
111-
return $first != $second
109+
let $first := fn:collation-key(fn:codepoints-to-string((37, 65500, 37)))
110+
let $second := fn:collation-key(fn:codepoints-to-string((37, 100000, 37)))
111+
return $first eq $second
112112
};

0 commit comments

Comments
 (0)