Example #1
0
    def test_list_embedded_urls(self) -> None:
        files = {
            'main.cpp': textwrap.dedent("""\
                // URL with quotes
                #define PROBLEM "http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_1_A"
                // url='https://atcoder.jp/'
                // `https://atcoder.jp/contests/abc001`
                //
                // URL without quotes
                // @see https://atcoder.jp/contests/abc002
                //
                // URL with quotes and extra characters
                // {"url": "https://atcoder.jp/contests/abc003"}
                // ('https://atcoder.jp/contests/abc004')
                //
                // URL with opening quote and without closing quote
                // "https://atcoder.jp/contests/abc005
                """).encode(),
        }
        expected = [
            'http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_1_A',
            'https://atcoder.jp/',
            'https://atcoder.jp/contests/abc001',
            'https://atcoder.jp/contests/abc002',
            'https://atcoder.jp/contests/abc003',
            'https://atcoder.jp/contests/abc004',
            'https://atcoder.jp/contests/abc005',
        ]

        with tests.utils.load_files(files) as tempdir:
            with tests.utils.chdir(tempdir):
                file_path = tempdir / 'main.cpp'
                actual = sorted(special_comments.list_embedded_urls(file_path))
                self.assertEqual(actual, expected)
 def list_attributes(self, path: pathlib.Path, *,
                     basedir: pathlib.Path) -> Dict[str, Any]:
     attributes: Dict[str, Any] = special_comments.list_special_comments(
         path.resolve()) or _get_csx_pragmas(path.resolve())
     attributes.setdefault('links', [])
     attributes['links'].extend(special_comments.list_embedded_urls(path))
     return attributes
Example #3
0
    def list_attributes(self, path: pathlib.Path, *, basedir: pathlib.Path) -> Dict[str, Any]:
        """
        :throws Exception:
        """

        attributes: Dict[str, Any] = special_comments.list_special_comments(path)
        attributes.setdefault('links', [])
        attributes['links'].extend(special_comments.list_embedded_urls(path))
        return attributes
    def list_attributes(self, path: pathlib.Path, *,
                        basedir: pathlib.Path) -> Dict[str, Any]:
        attributes: Dict[str, Any] = {}
        attributes.update(
            special_comments.list_doxygen_annotations(path.resolve()))

        comments = special_comments.list_special_comments(path.resolve())
        if comments:
            attributes.update(comments)

        elif super().is_verification_file(path, basedir=basedir):
            # use old-style if special comments not found
            # #define PROBLEM "https://..." の形式は複数 environments との相性がよくない。あと遅い
            attributes[_NOT_SPECIAL_COMMENTS] = ''
            all_ignored = True
            for env in self._list_environments():
                joined_CXXFLAGS = ' '.join(
                    map(shlex.quote, [*env.CXXFLAGS, '-I',
                                      str(basedir)]))
                macros = _cplusplus_list_defined_macros(
                    path.resolve(),
                    CXX=env.CXX,
                    joined_CXXFLAGS=joined_CXXFLAGS)

                # convert macros to attributes
                if _IGNORE not in macros:
                    for key in [_PROBLEM, _ERROR]:
                        if all_ignored:
                            # the first non-ignored environment
                            if key in macros:
                                attributes[key] = macros[key]
                        else:
                            assert attributes.get(key) == macros.get(key)
                    all_ignored = False
                else:
                    if env._is_gcc():
                        attributes[_IGNORE_IF_GCC] = ''
                    elif env._is_clang():
                        attributes[_IGNORE_IF_CLANG] = ''
                    else:
                        attributes[_IGNORE] = ''
            if all_ignored:
                attributes[_IGNORE] = ''

        attributes.setdefault('links', [])
        attributes['links'].extend(special_comments.list_embedded_urls(path))
        return attributes