| 1 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 140 |
|
| 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 |
|
| 157 |
|
| 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 |
|
| 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 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|