Debian Codegraph @

tests/test_incomplete.py

raw symbols SCIP
1 # -*- coding: ascii -*-
2 u"""
3 :Copyright:
4
5 Copyright 2019 - 2025
6 Andr\xe9 Malo or his licensors, as applicable
7
8 :License:
9
10 Licensed under the Apache License, Version 2.0 (the "License");
11 you may not use this file except in compliance with the License.
12 You may obtain a copy of the License at
13
14 http://www.apache.org/licenses/LICENSE-2.0
15
16 Unless required by applicable law or agreed to in writing, software
17 distributed under the License is distributed on an "AS IS" BASIS,
18 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 See the License for the specific language governing permissions and
20 limitations under the License.
21
22 ========
23 Basics
24 ========
25
26 test for basics.
27 """
28 __author__ = u"Andr\xe9 Malo"
29
30 import os as _os
31
32 import rjsmin as _rjsmin
33
34 # pylint: disable = protected-access
35 py_jsmin = _rjsmin._make_jsmin(python_only=True)
36 py_jsmin2 = _rjsmin.jsmin_for_posers
37
38 import _rjsmin
39
40 c_jsmin = _rjsmin.jsmin
41
42
43 def load(name):
44 """Load a file"""
45 with open(_os.path.join(_os.path.dirname(__file__), name), "rb") as fp:
46 return fp.read()
47
48
49 def save(name, value):
50 """Load a file"""
51 with open(_os.path.join(_os.path.dirname(__file__), name), "wb") as fp:
52 fp.write(value)
53
54
55 def test_string():
56 """Test incomplete string"""
57 inp = load("js/incomplete_string.js")
58 exp = load("js/incomplete_string.min.js")
59 # save('js/incomplete_string.min.js', py_jsmin(inp))
60 assert py_jsmin(inp) == exp
61 assert py_jsmin2(inp) == exp
62 assert c_jsmin(inp) == exp
63
64 inp = inp.decode("latin-1")
65 exp = exp.decode("latin-1")
66 assert py_jsmin(inp) == exp
67 assert py_jsmin2(inp) == exp
68 assert c_jsmin(inp) == exp
69
70
71 def test_regex():
72 """Test incomplete regex"""
73 inp = load("js/incomplete_regex.js")
74 exp = load("js/incomplete_regex.min.js")
75 # save('js/incomplete_regex.min.js', py_jsmin(inp))
76 assert py_jsmin(inp) == exp
77 assert py_jsmin2(inp) == exp
78 assert c_jsmin(inp) == exp
79
80 inp = inp.decode("latin-1")
81 exp = exp.decode("latin-1")
82 assert py_jsmin(inp) == exp
83 assert py_jsmin2(inp) == exp
84 assert c_jsmin(inp) == exp
85
86
87 def test_regex2():
88 """Test incomplete regex"""
89 inp = load("js/incomplete_regex2.js")
90 exp = load("js/incomplete_regex2.min.js")
91 # save('js/incomplete_regex2.min.js', py_jsmin(inp))
92 assert py_jsmin(inp) == exp
93 assert py_jsmin2(inp) == exp
94 assert c_jsmin(inp) == exp
95
96 inp = inp.decode("latin-1")
97 exp = exp.decode("latin-1")
98 assert py_jsmin(inp) == exp
99 assert py_jsmin2(inp) == exp
100 assert c_jsmin(inp) == exp
101
102
103 def test_comment():
104 """Test incomplete comment"""
105 inp = load("js/incomplete_comment.js")
106 exp = load("js/incomplete_comment.min.js")
107 # save('js/incomplete_comment.min.js', py_jsmin(inp))
108 assert py_jsmin(inp) == exp
109 assert py_jsmin2(inp) == exp
110 assert c_jsmin(inp) == exp
111
112 inp = inp.decode("latin-1")
113 exp = exp.decode("latin-1")
114 assert py_jsmin(inp) == exp
115 assert py_jsmin2(inp) == exp
116 assert c_jsmin(inp) == exp
117
118
119 def test_comment2():
120 """Test incomplete comment"""
121 inp = load("js/incomplete_comment2.js")
122 exp = load("js/incomplete_comment2.min.js")
123 # save('js/incomplete_comment2.min.js', py_jsmin(inp))
124 assert py_jsmin(inp) == exp
125 assert py_jsmin2(inp) == exp
126 assert c_jsmin(inp) == exp
127
128 inp = inp.decode("latin-1")
129 exp = exp.decode("latin-1")
130 assert py_jsmin(inp) == exp
131 assert py_jsmin2(inp) == exp
132 assert c_jsmin(inp) == exp
133
134
135 def test_comment_bang():
136 """Test incomplete bang comment"""
137 inp = load("js/incomplete_bang_comment.js")
138 exp = load("js/incomplete_bang_comment.min.js")
139 # save('js/incomplete_bang_comment.min.js',
140 # py_jsmin(inp, keep_bang_comments=True))
141 assert py_jsmin(inp, keep_bang_comments=True) == exp
142 assert py_jsmin2(inp, keep_bang_comments=True) == exp
143 assert c_jsmin(inp, keep_bang_comments=True) == exp
144
145 inp = inp.decode("latin-1")
146 exp = exp.decode("latin-1")
147 assert py_jsmin(inp, keep_bang_comments=True) == exp
148 assert py_jsmin2(inp, keep_bang_comments=True) == exp
149 assert c_jsmin(inp, keep_bang_comments=True) == exp
150
151
152 def test_comment_bang2():
153 """Test incomplete bang comment"""
154 inp = load("js/incomplete_bang_comment2.js")
155 exp = load("js/incomplete_bang_comment2.min.js")
156 # save('js/incomplete_bang_comment2.min.js',
157 # py_jsmin(inp, keep_bang_comments=True))
158 assert py_jsmin(inp, keep_bang_comments=True) == exp
159 assert py_jsmin2(inp, keep_bang_comments=True) == exp
160 assert c_jsmin(inp, keep_bang_comments=True) == exp
161
162 inp = inp.decode("latin-1")
163 exp = exp.decode("latin-1")
164 assert py_jsmin(inp, keep_bang_comments=True) == exp
165 assert py_jsmin2(inp, keep_bang_comments=True) == exp
166 assert c_jsmin(inp, keep_bang_comments=True) == exp
167
168
169 def test_slash():
170 """Test lone slash"""
171 inp = load("js/lone_slash.js")
172 exp = load("js/lone_slash.min.js")
173 # save('js/lone_slash.min.js', py_jsmin(inp))
174 assert py_jsmin(inp) == exp
175 assert py_jsmin2(inp) == exp
176 assert c_jsmin(inp) == exp
177
178 inp = inp.decode("latin-1")
179 exp = exp.decode("latin-1")
180 assert py_jsmin(inp) == exp
181 assert py_jsmin2(inp) == exp
182 assert c_jsmin(inp) == exp
183
184
185 # def test_basic_bang():
186 # """ Test basic.js with bang comments """
187 # inp = load('js/basic.js')
188 # exp = load('js/basic.bang.js')
189 # # save('js/basic.bang.js', py_jsmin(inp, keep_bang_comments=True))
190 # assert py_jsmin(inp, keep_bang_comments=True) == exp
191 # assert py_jsmin2(inp, keep_bang_comments=True) == exp
192 # assert c_jsmin(inp, keep_bang_comments=True) == exp
193 #
194 # inp = inp.decode('latin-1')
195 # exp = exp.decode('latin-1')
196 # assert py_jsmin(inp, keep_bang_comments=True) == exp
197 # assert py_jsmin2(inp, keep_bang_comments=True) == exp
198 # assert c_jsmin(inp, keep_bang_comments=True) == exp