File: query.py

package info (click to toggle)
trac-tags 0.9-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 596 kB
  • sloc: python: 3,541; makefile: 2
file content (44 lines) | stat: -rw-r--r-- 1,157 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# -*- coding: utf-8 -*-
#
# Copyright (C) 2011 Odd Simon Simonsen <oddsimons@gmail.com>
#
# This software is licensed as described in the file COPYING, which
# you should have received as part of this distribution.
#

import doctest
import unittest

import tractags.query


class QueryTestCase(unittest.TestCase):
    def test_parse(self):
        """Verify tokenization of quoted strings and strings with unary quotes.

        This as been reported as th:ticket:9057.
        """
        singlequote_phrase = r"""alpha'beta"gamma or 'alpha\'beta"gamma'"""
        q = tractags.query.Query
        self.assertEquals("""\
(or
  ("alpha'beta\"gamma")
  ("alpha'beta\"gamma"))""", repr(q(singlequote_phrase)))

        doublequote_phrase = r'alpha or "beta\'gamma\"delta" or ""'
        self.assertEquals("""\
(or
  ("alpha")
  (or
    ("beta'gamma"delta")
    ("")))""", repr(q(doublequote_phrase)))


def test_suite():
    suite = unittest.TestSuite()
    suite.addTest(doctest.DocTestSuite(module=tractags.query))
    suite.addTest(unittest.makeSuite(QueryTestCase))
    return suite

if __name__ == '__main__':
    unittest.main(defaultTest='test_suite')