|
1
|
|
|
import sys |
|
2
|
|
|
import unittest |
|
3
|
|
|
from queue import Queue |
|
4
|
|
|
|
|
5
|
|
|
sys.path.insert(0, ".") |
|
6
|
|
|
from bears.tests.LocalBearTestHelper import LocalBearTestHelper |
|
7
|
|
|
from bears.js.JSONFormatBear import JSONFormatBear |
|
8
|
|
|
from coalib.settings.Section import Section, Setting |
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
class JSONFormatBearTest(LocalBearTestHelper): |
|
12
|
|
|
def setUp(self): |
|
13
|
|
|
self.section = Section('name') |
|
14
|
|
|
self.uut = JSONFormatBear(self.section, Queue()) |
|
15
|
|
|
|
|
16
|
|
|
def test_valid(self): |
|
17
|
|
|
self.assertLinesValid(self.uut, ['{', |
|
18
|
|
|
' "a": 5,', |
|
19
|
|
|
' "b": 5', |
|
20
|
|
|
'}']) |
|
21
|
|
|
self.assertLinesValid(self.uut, ['{', |
|
22
|
|
|
' "b": 5,', |
|
23
|
|
|
' "a": 5', |
|
24
|
|
|
'}']) |
|
25
|
|
|
|
|
26
|
|
|
def test_invalid(self): |
|
27
|
|
|
self.assertLinesInvalid(self.uut, [""]) |
|
28
|
|
|
self.assertLinesInvalid(self.uut, ["random stuff"]) |
|
29
|
|
|
self.assertLinesInvalid(self.uut, ['{"a":5,"b":5}']) |
|
30
|
|
|
|
|
31
|
|
|
def test_sorting(self): |
|
32
|
|
|
self.section.append(Setting("json_sort", "true")) |
|
33
|
|
|
self.assertLinesInvalid(self.uut, ['{', |
|
34
|
|
|
' "b": 5,', |
|
35
|
|
|
' "a": 5', |
|
36
|
|
|
'}']) |
|
37
|
|
|
|
|
38
|
|
|
def test_indent(self): |
|
39
|
|
|
test_code = ['{', ' "b": 5,', ' "a": 5', '}'] |
|
40
|
|
|
self.assertLinesInvalid(self.uut, test_code) |
|
41
|
|
|
|
|
42
|
|
|
self.section.append(Setting("tab_width", "3")) |
|
43
|
|
|
self.assertLinesValid(self.uut, test_code) |
|
44
|
|
|
|
|
45
|
|
|
|
|
46
|
|
|
if __name__ == '__main__': |
|
47
|
|
|
unittest.main(verbosity=2) |
|
48
|
|
|
|