示例#1
0
文件: test.py 项目: lqez/slmd
    def test_shuffle_2nd_only(self):
        asis = """
* 1
  * 1
  * 2
  * 3
  * 4
* 2
* 3
"""
        not_to_be_2nd = """
  * 1
  * 2
  * 3
  * 4
"""
        original = asis.splitlines()
        result = sort_string(asis, [0, 2]).splitlines()
        only_2nd = "\n".join(result[2:6])

        self.assertNotEqual(not_to_be_2nd, only_2nd)
        
        # Other lines should be equal
        for l in [1, 6, 7]:
            self.assertEqual(original[l], result[l])
示例#2
0
文件: test.py 项目: lqez/slmd
    def test_descending(self):
        asis = """
* 1
* 3
* 2
"""
        tobe = """
* 3
* 2
* 1
"""
        self.assertEqual(sort_string(asis, [-1]), tobe)
示例#3
0
文件: test.py 项目: lqez/slmd
    def test_shuffle(self):
        asis = """
- A
- B
  - 12
  - A
  - Z
- C
  - A
  - B
  - D
"""
        self.assertNotEqual(sort_string(asis, sort_randomly=True), asis)
示例#4
0
def main(args=sys.argv[1:]):
    args = get_parser().parse_args(args)

    source = args.infile.read()
    result = sort_string(source, args.sort_by, args.casesensitive, args.random)

    if args.overwrite:
        args.infile.close()
        with open(args.infile.name, 'w', encoding=args.infile.encoding) as f:
            f.write(result)
    else:
        args.outfile.write(result)

    return 0 if (source == result) else 1
示例#5
0
文件: test.py 项目: lqez/slmd
    def test_2nd_only(self):
        asis = """
* 1
  * 3
  * 2
  * 1
* 3
* 2
"""
        tobe = """
* 1
  * 1
  * 2
  * 3
* 3
* 2
"""
        self.assertEqual(sort_string(asis, [0, 1]), tobe)
示例#6
0
文件: test.py 项目: lqez/slmd
    def test_basic(self):
        asis = """
normal paragraph

- 2
  - C
  - A
    - 6
      indented text
    - 4
  - B
- 1
  - F
  - A

- k
- j

normal text
"""
        tobe = """
normal paragraph

- 1
  - A
  - F
- 2
  - A
    - 4
    - 6
      indented text
  - B
  - C

- j
- k

normal text
"""
        self.assertEqual(sort_string(asis), tobe)
示例#7
0
文件: test.py 项目: lqez/slmd
    def test_case_sensitive(self):
        asis = """
- C
  - A
  - d
  - b
- b
  - Z
  - 12
  - a
- a
"""
        tobe = """
- a
- b
  - 12
  - a
  - Z
- C
  - A
  - b
  - d
"""
        self.assertEqual(sort_string(asis, case_sensitive=False), tobe)
示例#8
0
文件: test.py 项目: lqez/slmd
    def test_3rd_only(self):
        asis = """
* 2
  * 3
  * 2
  * 1
    * B
    * A
    * C
* 3
* 1
"""
        tobe = """
* 2
  * 3
  * 2
  * 1
    * A
    * B
    * C
* 3
* 1
"""
        self.assertEqual(sort_string(asis, [0, 0, 1]), tobe)