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 2021/07/14 21:23:20 UTC

[incubator-annotator] 01/01: Update and merge PR #107 (REUSE compliance)

This is an automated email from the ASF dual-hosted git repository.

gerben pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-annotator.git

commit 2c5acf8cbfdbc1bdb96ddddfe4a43342d01c8c03
Merge: fc5474d c4fedab
Author: Gerben <ge...@treora.com>
AuthorDate: Wed Jul 14 23:12:35 2021 +0200

    Update and merge PR #107 (REUSE compliance)
    
    Reapply the SPDX header to current files, and some others that seem to
    have been overlooked.
    
    Copy LICENSE file instead of moving it (symlinking it breaks Rat, somehow).

 .eslintrc.js                                       |   2 +
 .mocharc.js                                        |   2 +
 .ratignore                                         |   1 +
 LICENSES/Apache-2.0.txt                            | 202 +++++++++++++++++++++
 Makefile                                           |   2 +
 README.md                                          |   3 +-
 babel-register.js                                  |   2 +
 babel.config.js                                    |   2 +
 husky.config.js                                    |   2 +
 nyc.config.js                                      |   2 +
 packages/apache-annotator/src/dom.ts               |   2 +
 packages/apache-annotator/src/selector.ts          |   2 +
 packages/dom/@types/optimal-select/index.d.ts      |   2 +
 packages/dom/src/css.ts                            |   2 +
 packages/dom/src/highlight-text.ts                 |   2 +
 packages/dom/src/index.ts                          |   2 +
 packages/dom/src/normalize-range.ts                |   2 +
 packages/dom/src/owner-document.ts                 |   2 +
 packages/dom/src/range/cartesian.ts                |   2 +
 packages/dom/src/range/index.ts                    |   2 +
 packages/dom/src/range/match.ts                    |   2 +
 packages/dom/src/text-node-chunker.ts              |   2 +
 packages/dom/src/text-position/describe.ts         |   2 +
 packages/dom/src/text-position/index.ts            |   2 +
 packages/dom/src/text-position/match.ts            |   2 +
 packages/dom/src/text-quote/describe.ts            |   2 +
 packages/dom/src/text-quote/index.ts               |   2 +
 packages/dom/src/text-quote/match.ts               |   2 +
 packages/dom/src/to-range.ts                       |   2 +
 packages/dom/test/css/describe.test.ts             |   2 +
 packages/dom/test/css/match-cases.ts               |   2 +
 packages/dom/test/css/match.test.ts                |   2 +
 .../dom/test/highlight-text/highlight-text.test.ts |   2 +
 packages/dom/test/range/cartesian.test.ts          |   2 +
 packages/dom/test/text-position/describe.test.ts   |   2 +
 packages/dom/test/text-position/match-cases.ts     |   2 +
 packages/dom/test/text-position/match.test.ts      |   2 +
 packages/dom/test/text-quote/describe-cases.ts     |   2 +
 packages/dom/test/text-quote/describe.test.ts      |   2 +
 packages/dom/test/text-quote/match-cases.ts        |   2 +
 packages/dom/test/text-quote/match.test.ts         |   2 +
 packages/dom/test/utils.ts                         |   2 +
 packages/selector/src/index.ts                     |   2 +
 packages/selector/src/text/chunker.ts              |   2 +
 packages/selector/src/text/code-point-seeker.ts    |   2 +
 .../selector/src/text/describe-text-position.ts    |   2 +
 packages/selector/src/text/describe-text-quote.ts  |   2 +
 packages/selector/src/text/index.ts                |   2 +
 packages/selector/src/text/match-text-position.ts  |   2 +
 packages/selector/src/text/match-text-quote.ts     |   2 +
 packages/selector/src/text/seeker.ts               |   2 +
 packages/selector/src/types.ts                     |   2 +
 test/data-model.test.ts                            |   2 +
 web/index.html                                     |   2 +
 web/index.js                                       |   2 +
 web/style.css                                      |   2 +
 web/webpack.config.js                              |   2 +
 57 files changed, 313 insertions(+), 1 deletion(-)

diff --cc .ratignore
index 05201d1,2d1dedc..b31f5da
--- a/.ratignore
+++ b/.ratignore
@@@ -15,5 -14,5 +15,6 @@@ typedoc\.jso
  yarn\.lock
  CODE_OF_CONDUCT\.md
  DISCLAIMER-WIP
++LICENSES
  README\.md
  SECURITY\.md
diff --cc Makefile
index c193ecf,c193ecf..e00541e
--- a/Makefile
+++ b/Makefile
@@@ -1,3 -1,3 +1,5 @@@
++# SPDX-FileCopyrightText: 2016-2020 The Apache Software Foundation
++# SPDX-License-Identifier: Apache-2.0
  # Licensed under the Apache License, Version 2.0 (the "License"); you may not
  # use this file except in compliance with the License. You may obtain a copy of
  # the License at
diff --cc packages/dom/test/css/describe.test.ts
index 711c9ce,0000000..ab535bb
mode 100644,000000..100644
--- a/packages/dom/test/css/describe.test.ts
+++ b/packages/dom/test/css/describe.test.ts
@@@ -1,58 -1,0 +1,60 @@@
 +/**
++ * SPDX-FileCopyrightText: 2016-2020 The Apache Software Foundation
++ * SPDX-License-Identifier: Apache-2.0
 + * @license
 + * Licensed to the Apache Software Foundation (ASF) under one
 + * or more contributor license agreements.  See the NOTICE file
 + * distributed with this work for additional information
 + * regarding copyright ownership.  The ASF licenses this file
 + * to you under the Apache License, Version 2.0 (the
 + * "License"); you may not use this file except in compliance
 + * with the License.  You may obtain a copy of the License at
 + *
 + *   http://www.apache.org/licenses/LICENSE-2.0
 + *
 + * Unless required by applicable law or agreed to in writing,
 + * software distributed under the License is distributed on an
 + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 + * KIND, either express or implied.  See the License for the
 + * specific language governing permissions and limitations
 + * under the License.
 + */
 +
 +import { assert } from 'chai';
 +import { describeCss } from '../../src/css';
 +import { evaluateXPath } from '../utils';
 +import { testCases } from './match-cases';
 +
 +const domParser = new DOMParser();
 +
 +describe('describeCss', () => {
 +  describe('inverts test cases of css matcher', () => {
 +    for (const [name, { html, scopeXPath, expected }] of Object.entries(
 +      testCases,
 +    )) {
 +      for (let i = 0; i < expected.length; i++) {
 +        const elementXPath = expected[i];
 +        it(`case: '${name}' (${i + 1}/${expected.length})`, async () => {
 +          const doc = domParser.parseFromString(html, 'text/html');
 +          const element = evaluateXPath(doc, elementXPath) as HTMLElement;
 +          const scopeElement = scopeXPath
 +            ? (evaluateXPath(doc, scopeXPath) as HTMLElement)
 +            : undefined;
 +          const cssSelector = await describeCss(element, scopeElement);
 +
 +          // We do not require a specific value for the selector, just
 +          // that it uniquely matches the same element again.
 +          const matchingElements = (scopeElement ?? doc).querySelectorAll(
 +            cssSelector.value,
 +          );
 +          assert.equal(
 +            matchingElements.length,
 +            1,
 +            'Expected a selector with a single match',
 +          );
 +          assert.equal(matchingElements[0], element);
 +        });
 +      }
 +    }
 +  });
 +});
diff --cc packages/dom/test/css/match.test.ts
index ad39b42,0000000..3e379ba
mode 100644,000000..100644
--- a/packages/dom/test/css/match.test.ts
+++ b/packages/dom/test/css/match.test.ts
@@@ -1,59 -1,0 +1,61 @@@
 +/**
++ * SPDX-FileCopyrightText: 2016-2020 The Apache Software Foundation
++ * SPDX-License-Identifier: Apache-2.0
 + * @license
 + * Licensed to the Apache Software Foundation (ASF) under one
 + * or more contributor license agreements.  See the NOTICE file
 + * distributed with this work for additional information
 + * regarding copyright ownership.  The ASF licenses this file
 + * to you under the Apache License, Version 2.0 (the
 + * "License"); you may not use this file except in compliance
 + * with the License.  You may obtain a copy of the License at
 + *
 + *   http://www.apache.org/licenses/LICENSE-2.0
 + *
 + * Unless required by applicable law or agreed to in writing,
 + * software distributed under the License is distributed on an
 + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 + * KIND, either express or implied.  See the License for the
 + * specific language governing permissions and limitations
 + * under the License.
 + */
 +
 +import { assert } from 'chai';
 +import type { CssSelector } from '@apache-annotator/selector';
 +import { createCssSelectorMatcher } from '../../src/css';
 +import { evaluateXPath } from '../utils';
 +import { testCases } from './match-cases';
 +
 +const domParser = new DOMParser();
 +
 +describe('CreateCssSelectorMatcher', () => {
 +  for (const [name, { html, selector, scopeXPath, expected }] of Object.entries(
 +    testCases,
 +  )) {
 +    it(`works for case: '${name}'`, async () => {
 +      const doc = domParser.parseFromString(html, 'text/html');
 +
 +      const scopeElement = scopeXPath ? evaluateXPath(doc, scopeXPath) : doc;
 +      const scope = doc.createRange();
 +      scope.selectNodeContents(scopeElement);
 +
 +      await testMatcher(doc, scope, selector, expected);
 +    });
 +  }
 +});
 +
 +async function testMatcher(
 +  doc: Document,
 +  scope: Range,
 +  selector: CssSelector,
 +  expected: string[],
 +) {
 +  const matcher = createCssSelectorMatcher(selector);
 +  const matches = [];
 +  for await (const value of matcher(scope)) matches.push(value);
 +  assert.equal(matches.length, expected.length, 'Unexpected number of matches');
 +  matches.forEach((match, i) => {
 +    const expectedElement = evaluateXPath(doc, expected[i]);
 +    assert.equal(match, expectedElement);
 +  });
 +}
diff --cc packages/dom/test/utils.ts
index a391074,66a9700..ae7dd9c
--- a/packages/dom/test/utils.ts
+++ b/packages/dom/test/utils.ts
@@@ -1,4 -1,6 +1,6 @@@
 -/** 
 +/**
+  * SPDX-FileCopyrightText: 2016-2020 The Apache Software Foundation
+  * SPDX-License-Identifier: Apache-2.0
   * @license
   * Licensed to the Apache Software Foundation (ASF) under one
   * or more contributor license agreements.  See the NOTICE file
diff --cc packages/selector/src/text/index.ts
index 0261823,0854a35..0287f48
--- a/packages/selector/src/text/index.ts
+++ b/packages/selector/src/text/index.ts
@@@ -1,21 -1,6 +1,23 @@@
 -/*
 +/**
+  * SPDX-FileCopyrightText: 2016-2020 The Apache Software Foundation
+  * SPDX-License-Identifier: Apache-2.0
 + * @license
 + * Licensed to the Apache Software Foundation (ASF) under one
 + * or more contributor license agreements.  See the NOTICE file
 + * distributed with this work for additional information
 + * regarding copyright ownership.  The ASF licenses this file
 + * to you under the Apache License, Version 2.0 (the
 + * "License"); you may not use this file except in compliance
 + * with the License.  You may obtain a copy of the License at
 + *
 + *   http://www.apache.org/licenses/LICENSE-2.0
 + *
 + * Unless required by applicable law or agreed to in writing,
 + * software distributed under the License is distributed on an
 + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 + * KIND, either express or implied.  See the License for the
 + * specific language governing permissions and limitations
 + * under the License.
   */
  
  export * from './describe-text-quote';
diff --cc web/index.html
index 8108f5b,85dae62..8ac55cf
--- a/web/index.html
+++ b/web/index.html
@@@ -1,4 -1,4 +1,6 @@@
  <!--
++SPDX-FileCopyrightText: 2016-2020 The Apache Software Foundation
++SPDX-License-Identifier: Apache-2.0
  Licensed to the Apache Software Foundation (ASF) under one
  or more contributor license agreements.  See the NOTICE file
  distributed with this work for additional information