|
| 1 | +import textwrap |
| 2 | +import unittest |
| 3 | +from typing import * |
| 4 | + |
| 5 | +import onlinejudge_verify.languages.special_comments as special_comments |
| 6 | +import tests.utils |
| 7 | + |
| 8 | + |
| 9 | +class TestSpecialComments(unittest.TestCase): |
| 10 | + """Unit tests for languages/special_comments.py |
| 11 | + """ |
| 12 | + def test_list_embedded_urls(self) -> None: |
| 13 | + files = { |
| 14 | + 'main.cpp': textwrap.dedent("""\ |
| 15 | + // URL with quotes |
| 16 | + #define PROBLEM "http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_1_A" |
| 17 | + // url='https://atcoder.jp/' |
| 18 | + // `https://atcoder.jp/contests/abc001` |
| 19 | + // |
| 20 | + // URL without quotes |
| 21 | + // @see https://atcoder.jp/contests/abc002 |
| 22 | + // |
| 23 | + // URL with quotes and extra characters |
| 24 | + // {"url": "https://atcoder.jp/contests/abc003"} |
| 25 | + // ('https://atcoder.jp/contests/abc004') |
| 26 | + // |
| 27 | + // URL with opening quote and without closing quote |
| 28 | + // "https://atcoder.jp/contests/abc005 |
| 29 | + """).encode(), |
| 30 | + } |
| 31 | + expected = [ |
| 32 | + 'http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_1_A', |
| 33 | + 'https://atcoder.jp/', |
| 34 | + 'https://atcoder.jp/contests/abc001', |
| 35 | + 'https://atcoder.jp/contests/abc002', |
| 36 | + 'https://atcoder.jp/contests/abc003', |
| 37 | + 'https://atcoder.jp/contests/abc004', |
| 38 | + 'https://atcoder.jp/contests/abc005', |
| 39 | + ] |
| 40 | + |
| 41 | + with tests.utils.load_files(files) as tempdir: |
| 42 | + with tests.utils.chdir(tempdir): |
| 43 | + file_path = tempdir / 'main.cpp' |
| 44 | + actual = sorted(special_comments.list_embedded_urls(file_path)) |
| 45 | + self.assertEqual(actual, expected) |
0 commit comments