You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@annotator.apache.org by ge...@apache.org on 2020/04/03 11:53:21 UTC
[incubator-annotator] 06/09: Test parsing values with parentheses
This is an automated email from the ASF dual-hosted git repository.
gerben pushed a commit to branch fragment-tests
in repository https://gitbox.apache.org/repos/asf/incubator-annotator.git
commit 9f77a08a3d42b1507a68096f661d60842ddac5d8
Author: Gerben <ge...@treora.com>
AuthorDate: Fri Apr 3 12:56:35 2020 +0200
Test parsing values with parentheses
---
packages/fragment-identifier/test/index.js | 51 +++++++++++++++++++++++++++++-
1 file changed, 50 insertions(+), 1 deletion(-)
diff --git a/packages/fragment-identifier/test/index.js b/packages/fragment-identifier/test/index.js
index b06981a..947e03f 100644
--- a/packages/fragment-identifier/test/index.js
+++ b/packages/fragment-identifier/test/index.js
@@ -42,8 +42,57 @@ describe('stringify', () => {
}
});
+const specialCasesToParse = {
+ 'One closing parenthesis inside a value': {
+ fragId: 'selector(type=TextQuoteSelector,exact=(not)%20a%20problem)',
+ selector: {
+ type: 'TextQuoteSelector',
+ exact: '(not) a problem',
+ },
+ },
+
+ 'Two closing parenthesis inside a value': {
+ fragId: 'selector(type=TextQuoteSelector,exact=Hey))%20this%20breaks)',
+ selector: {
+ type: 'TextQuoteSelector',
+ exact: 'Hey)) this breaks',
+ },
+ },
+
+ 'Two closing parentheses: one of value, one of selector': {
+ fragId: 'selector(type=TextQuoteSelector,exact=example%20(that%20fails))',
+ selector: {
+ type: 'TextQuoteSelector',
+ exact: 'example (that fails)',
+ },
+ },
+
+ 'Three closing parentheses: one of the value, two of nested selectors': {
+ // Example from <https://github.com/w3c/web-annotation/issues/443>
+ fragId: `
+ selector(
+ type=RangeSelector,
+ startSelector=selector(type=TextQuoteSelector,exact=(but),
+ endSelector=selector(type=TextQuoteSelector,exact=crazy))
+ )
+ `.replace(/\s/g, ''),
+ selector: {
+ type: 'RangeSelector',
+ startSelector: {
+ type: 'TextQuoteSelector',
+ exact: '(but',
+ },
+ endSelector: {
+ type: 'TextQuoteSelector',
+ exact: 'crazy)',
+ },
+ },
+ },
+};
+
describe('parse', () => {
- for (const [name, example] of Object.entries(specExamples)) {
+ const allCasesToParse = { ...specExamples, ...specialCasesToParse };
+ for (const [name, example] of Object.entries(allCasesToParse)) {
it(`should properly parse: ${name}`, () => {
const expected = (example.selector !== undefined)
? { selector: example.selector }