blob: c7c102945d070a4ea65cae0e30ea6ec64bb82c95 [file] [log] [blame]
Kent Tamura292d5322019-04-22 09:35:161<!DOCTYPE html>
2<link rel="help" href="https://www.w3.org/TR/1999/REC-xpath-19991116/#function-lang">
3<link rel="help" href="https://www.w3.org/TR/xpath-functions-31/#func-lang">
4<body>
5<script src="/resources/testharness.js"></script>
6<script src="/resources/testharnessreport.js"></script>
7<script>
8// Set the context node to the first child of the root element, and evaluate
9// the specified XPath expression. The test passes if
10// - The first child element name is 'match' and XPath result is true, or
11// - The first child element name is not 'match' and XPath result is false.
12function testFirstChild(expression, xmlString) {
13 let doc = (new DOMParser()).parseFromString(xmlString, 'text/xml');
14 test(() => {
15 let element = doc.documentElement.firstChild;
16 let result = doc.evaluate(expression, element, null, XPathResult.BOOLEAN_TYPE, null);
17 assert_equals(result.resultType, XPathResult.BOOLEAN_TYPE);
18 assert_equals(result.booleanValue, element.localName == 'match', element.outerHTML);
19 }, `${expression}: ${doc.documentElement.outerHTML}`);
20}
21
22testFirstChild('lang("en")', '<root><match xml:lang="en"/></root>');
23testFirstChild('lang("en")', '<root><match xml:lang="EN"/></root>');
24testFirstChild('lang("en")', '<root><match xml:lang="en-us"/></root>');
25testFirstChild('lang("en")', '<root><unmatch/></root>');
26
27// XPath 1.0 says:
28// if the context node has no xml:lang attribute, by the value of the
29// xml:lang attribute on the nearest ancestor of the context node that has
30// an xml:lang attribute.
31testFirstChild('lang("ja")', '<root xml:lang="ja"><match/></root>');
32
33// XPath 1.0 says:
34// if there is some suffix starting with - such that the attribute value is
35// equal to the argument ignoring that suffix of the attribute value
36testFirstChild('lang("ja")', '<root xml:lang="ja-jp"><unmatch xml:lang="ja_JP"/></root>');
37
38// U+212A should match to ASCII 'k'.
39// XPath 1.0 says:
40// ... such that the attribute value is equal to the argument ignoring that suffix
41// of the attribute value and ignoring case.
42// XPath 3.1 says:
43// ... true if and only if, based on a caseless default match as specified in
44// section 3.13 of The Unicode Standard,
45testFirstChild('lang("ko")', '<root><match xml:lang="&#x212A;o"/></root>');
46</script>
47</body>