Debian Codegraph @

tests/test_issue13.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_issue():
56 """Test issue"""
57 inp = load("js/issue13.js")
58 exp = load("js/issue13.min.js")
59 # save('js/issue13.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_issue_bang():
72 """Test issue with bang comments"""
73 inp = load("js/issue13.js")
74 exp = load("js/issue13.bang.js")
75 # save('js/issue13.bang.js', py_jsmin(inp, keep_bang_comments=True))
76 assert py_jsmin(inp, keep_bang_comments=True) == exp
77 assert py_jsmin2(inp, keep_bang_comments=True) == exp
78 assert c_jsmin(inp, keep_bang_comments=True) == exp
79
80 inp = inp.decode("latin-1")
81 exp = exp.decode("latin-1")
82 assert py_jsmin(inp, keep_bang_comments=True) == exp
83 assert py_jsmin2(inp, keep_bang_comments=True) == exp
84 assert c_jsmin(inp, keep_bang_comments=True) == exp