packr 1.0.2 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,68 +0,0 @@
1
- require 'test/unit'
2
- require 'packr'
3
-
4
- class PackrTest < Test::Unit::TestCase
5
-
6
- def setup
7
- dir = File.dirname(__FILE__) + '/assets'
8
- @data = {
9
- :default => [{
10
- :source => File.read("#{dir}/src/controls.js"),
11
- :packed => File.read("#{dir}/packed/controls.js")
12
- }],
13
- :shrink_vars => [{
14
- :source => File.read("#{dir}/src/dragdrop.js"),
15
- :packed => File.read("#{dir}/packed/dragdrop.js")
16
- },
17
- { :source => File.read("#{dir}/src/prototype.js"),
18
- :packed => File.read("#{dir}/packed/prototype_shrunk.js")
19
- }],
20
- :base62 => [{
21
- :source => File.read("#{dir}/src/effects.js"),
22
- :packed => File.read("#{dir}/packed/effects.js")
23
- }],
24
- :base62_shrink_vars => [{
25
- :source => File.read("#{dir}/src/prototype.js"),
26
- :packed => File.read("#{dir}/packed/prototype.js")
27
- }]
28
- }
29
- end
30
-
31
- def test_basic_packing
32
- assert_equal @data[:default][0][:packed], Packr.pack(@data[:default][0][:source])
33
- end
34
-
35
- def test_shrink_vars_packing
36
- assert_equal @data[:shrink_vars][0][:packed], Packr.pack(@data[:shrink_vars][0][:source], :shrink_vars => true)
37
- assert_equal @data[:shrink_vars][1][:packed], Packr.pack(@data[:shrink_vars][1][:source], :shrink_vars => true)
38
- end
39
-
40
- def test_base62_packing
41
- expected = @data[:base62][0][:packed]
42
- actual = Packr.pack(@data[:base62][0][:source], :base62 => true)
43
- assert_equal expected.size, actual.size
44
- expected_words = expected.scan(/'[\w\|]+'/)[-2].gsub(/^'(.*?)'$/, '\1').split("|").sort
45
- actual_words = actual.scan(/'[\w\|]+'/)[-2].gsub(/^'(.*?)'$/, '\1').split("|").sort
46
- assert expected_words.eql?(actual_words)
47
- end
48
-
49
- def test_base62_and_shrink_vars_packing
50
- expected = @data[:base62_shrink_vars][0][:packed]
51
- actual = Packr.pack(@data[:base62_shrink_vars][0][:source], :base62 => true, :shrink_vars => true)
52
- assert_equal expected.size, actual.size
53
- expected_words = expected.scan(/'[\w\|]+'/)[-2].gsub(/^'(.*?)'$/, '\1').split("|").sort
54
- actual_words = actual.scan(/'[\w\|]+'/)[-2].gsub(/^'(.*?)'$/, '\1').split("|").sort
55
- assert expected_words.eql?(actual_words)
56
- end
57
-
58
- def test_protected_names
59
- expected = 'var func=function(a,b,$super,c){return $super(a+c)}'
60
- actual = Packr.pack('var func = function(foo, bar, $super, baz) { return $super( foo + baz ); }', :shrink_vars => true)
61
- assert_equal expected, actual
62
- packr = Packr.new
63
- packr.protect_vars *(%w(other) + [:method, :names] + ['some random stuff', 24])
64
- expected = 'var func=function(a,other,$super,b,names){return $super()(other.apply(names,a))}'
65
- actual = packr.pack('var func = function(foo, other, $super, bar, names) { return $super()(other.apply(names, foo)); }', :shrink_vars => true)
66
- assert_equal expected, actual
67
- end
68
- end