jsus 0.1.4 → 0.1.5
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.
- data/CHANGELOG +5 -0
- data/Manifest +6 -2
- data/Rakefile +1 -1
- data/bin/jsus +1 -0
- data/jsus.gemspec +4 -4
- data/lib/jsus.rb +10 -2
- data/lib/jsus/container.rb +56 -19
- data/lib/jsus/package.rb +99 -35
- data/lib/jsus/packager.rb +17 -2
- data/lib/jsus/pool.rb +96 -23
- data/lib/jsus/source_file.rb +170 -36
- data/lib/jsus/tag.rb +142 -0
- data/spec/data/Basic/app/javascripts/Orwik/package.yml +1 -1
- data/spec/data/Extensions/app/javascripts/Core/Source/Class.js +13 -0
- data/spec/data/Extensions/app/javascripts/Core/package.yml +8 -0
- data/spec/data/Extensions/app/javascripts/Orwik/Extensions/Class.js +16 -0
- data/spec/data/Extensions/app/javascripts/Orwik/package.yml +8 -0
- data/spec/data/ExternalDependencies/app/javascripts/Orwik/Source/Test.js +1 -0
- data/spec/data/ExternalDependencies/app/javascripts/Orwik/package.yml +1 -1
- data/spec/data/test_source_one.js +5 -2
- data/spec/lib/jsus/package_spec.rb +26 -9
- data/spec/lib/jsus/pool_spec.rb +38 -1
- data/spec/lib/jsus/source_file_spec.rb +184 -29
- data/spec/lib/jsus/tag_spec.rb +122 -0
- metadata +11 -7
- data/lib/jsus/topsortable.rb +0 -29
- data/spec/lib/jsus/topsortable_spec.rb +0 -51
@@ -0,0 +1,122 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
|
3
|
+
describe Jsus::Tag do
|
4
|
+
subject { Jsus::Tag.new("Wtf") }
|
5
|
+
|
6
|
+
context "initialization" do
|
7
|
+
it "should set given name" do
|
8
|
+
Jsus::Tag.new("Wtf").name.should == "Wtf"
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should truncate leading slash with optional period (.)" do
|
12
|
+
Jsus::Tag.new("/Class").name.should == "Class"
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should parse package name" do
|
16
|
+
Jsus::Tag.new("Class").package_name.should == ""
|
17
|
+
Jsus::Tag.new("Core/Wtf").package_name.should == "Core"
|
18
|
+
Jsus::Tag.new("Core/Subpackage/Wtf").package_name.should == "Core/Subpackage"
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should allow explicit package setting" do
|
22
|
+
Jsus::Tag.new("Wtf", :package => Package.new(:name => "Core")).name.should == "Core/Wtf"
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should set external flag if it looks like an external dependency and not given a package option" do
|
26
|
+
Jsus::Tag.new("Core/WTF").should be_external
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should not set external flag if it doesn't look like an external dependency and not given a package option" do
|
30
|
+
Jsus::Tag.new("WTF").should_not be_external
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should set external flag if package from options is not the same as parsed package" do
|
34
|
+
Jsus::Tag.new("Core/WTF", :package => Package.new(:name => "Class")).should be_external
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should not set external flag if package from options is the same as parsed package" do
|
38
|
+
Jsus::Tag.new("Core/WTF", :package => Package.new(:name => "Core")).should_not be_external
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should use implcit package setting whenever possible" do
|
42
|
+
Jsus::Tag.new("Class/Wtf", :package => Package.new(:name => "Core")).name.should == "Class/Wtf"
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should return a given tag if given a tag" do
|
46
|
+
Jsus::Tag.new(subject).should == subject
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "#name" do
|
51
|
+
it "should return full name unless asked for a short form" do
|
52
|
+
Jsus::Tag.new("Core/Wtf").name.should == "Core/Wtf"
|
53
|
+
Jsus::Tag.new("Core/Subpackage/Wtf").name.should == "Core/Subpackage/Wtf"
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should not add slashes if package name is not set" do
|
57
|
+
Jsus::Tag.new("Wtf").name.should == "Wtf"
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should strip leading slashes" do
|
61
|
+
Jsus::Tag.new("./Wtf").name.should == "Wtf"
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should remove package from short form of non-external tags" do
|
65
|
+
tag = Jsus::Tag.new("Core/WTF")
|
66
|
+
tag.external = false
|
67
|
+
tag.name(:short => true).should == "WTF"
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
describe ".normalize_name_and_options" do
|
73
|
+
it "should parse name as full name if no options given" do
|
74
|
+
normalized = Jsus::Tag.normalize_name_and_options("Core/Wtf")
|
75
|
+
normalized[:name].should == "Wtf"
|
76
|
+
normalized[:package_name].should == "Core"
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should strip leading slash" do
|
80
|
+
Jsus::Tag.normalize_name_and_options("./Core/Wtf")[:package_name].should == "Core"
|
81
|
+
Jsus::Tag.normalize_name_and_options("./Core/Wtf")[:name].should == "Wtf"
|
82
|
+
Jsus::Tag.normalize_name_and_options("./Wtf")[:name].should == "Wtf"
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should use given package name whenever no package name can be restored from name" do
|
86
|
+
Jsus::Tag.normalize_name_and_options("Wtf", :package => Package.new(:name => "Core"))[:package_name].should == "Core"
|
87
|
+
Jsus::Tag.normalize_name_and_options("./Wtf", :package => Package.new(:name => "Core"))[:package_name].should == "Core"
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should parse name as full name whenever possible" do
|
91
|
+
Jsus::Tag.normalize_name_and_options("Class/Wtf", :package => Package.new(:name => "Core"))[:package_name].should == "Class"
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
context "comparison to other types" do
|
96
|
+
it "should consider tags with the same full names equal" do
|
97
|
+
Jsus::Tag.new("Core/Wtf").should == Jsus::Tag.new("Core/Wtf")
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should work with array operations" do
|
101
|
+
([Jsus::Tag.new("Core/Wtf")] - [Jsus::Tag.new("Core/Wtf")]).should == []
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
describe "#empty?" do
|
106
|
+
it "should return true when tag is empty" do
|
107
|
+
Jsus::Tag.new("").should be_empty
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should return false when tag is not empty" do
|
111
|
+
Jsus::Tag.new("Core/Mash").should_not be_empty
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
describe ".[]" do
|
116
|
+
it "should be an alias to .new" do
|
117
|
+
Jsus::Tag["Yo/Rap"].should == Jsus::Tag.new("Yo/Rap")
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
|
122
|
+
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 5
|
9
|
+
version: 0.1.5
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Markiz, idea by Inviz (http://github.com/Inviz)
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-06-
|
17
|
+
date: 2010-06-15 00:00:00 +04:00
|
18
18
|
default_executable: jsus
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -95,7 +95,7 @@ extra_rdoc_files:
|
|
95
95
|
- lib/jsus/packager.rb
|
96
96
|
- lib/jsus/pool.rb
|
97
97
|
- lib/jsus/source_file.rb
|
98
|
-
- lib/jsus/
|
98
|
+
- lib/jsus/tag.rb
|
99
99
|
files:
|
100
100
|
- CHANGELOG
|
101
101
|
- LICENSE
|
@@ -104,13 +104,14 @@ files:
|
|
104
104
|
- Rakefile
|
105
105
|
- TODO
|
106
106
|
- bin/jsus
|
107
|
+
- jsus.gemspec
|
107
108
|
- lib/jsus.rb
|
108
109
|
- lib/jsus/container.rb
|
109
110
|
- lib/jsus/package.rb
|
110
111
|
- lib/jsus/packager.rb
|
111
112
|
- lib/jsus/pool.rb
|
112
113
|
- lib/jsus/source_file.rb
|
113
|
-
- lib/jsus/
|
114
|
+
- lib/jsus/tag.rb
|
114
115
|
- spec/data/Basic/README
|
115
116
|
- spec/data/Basic/app/javascripts/Orwik/Source/Library/Color.js
|
116
117
|
- spec/data/Basic/app/javascripts/Orwik/Source/Widget/Input/Input.Color.js
|
@@ -123,6 +124,10 @@ files:
|
|
123
124
|
- spec/data/ChainDependencies/app/javascripts/Hash/package.yml
|
124
125
|
- spec/data/ChainDependencies/app/javascripts/Mash/Source/Mash.js
|
125
126
|
- spec/data/ChainDependencies/app/javascripts/Mash/package.yml
|
127
|
+
- spec/data/Extensions/app/javascripts/Core/Source/Class.js
|
128
|
+
- spec/data/Extensions/app/javascripts/Core/package.yml
|
129
|
+
- spec/data/Extensions/app/javascripts/Orwik/Extensions/Class.js
|
130
|
+
- spec/data/Extensions/app/javascripts/Orwik/package.yml
|
126
131
|
- spec/data/ExternalDependencies/app/javascripts/Orwik/Source/Test.js
|
127
132
|
- spec/data/ExternalDependencies/app/javascripts/Orwik/package.yml
|
128
133
|
- spec/data/OutsideDependencies/README
|
@@ -143,11 +148,10 @@ files:
|
|
143
148
|
- spec/lib/jsus/packager_spec.rb
|
144
149
|
- spec/lib/jsus/pool_spec.rb
|
145
150
|
- spec/lib/jsus/source_file_spec.rb
|
146
|
-
- spec/lib/jsus/
|
151
|
+
- spec/lib/jsus/tag_spec.rb
|
147
152
|
- spec/shared/class_stubs.rb
|
148
153
|
- spec/spec.opts
|
149
154
|
- spec/spec_helper.rb
|
150
|
-
- jsus.gemspec
|
151
155
|
has_rdoc: true
|
152
156
|
homepage: http://github.com/markiz/jsus
|
153
157
|
licenses: []
|
data/lib/jsus/topsortable.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
module Jsus
|
2
|
-
module Topsortable
|
3
|
-
# Topological sort for packages and source files
|
4
|
-
def topsort(to_sort = :items)
|
5
|
-
graph = RGL::DirectedAdjacencyGraph.new
|
6
|
-
provides_hash = {}
|
7
|
-
# init vertices
|
8
|
-
items = self.send(to_sort)
|
9
|
-
items.each do |item|
|
10
|
-
graph.add_vertex(item)
|
11
|
-
item.provides.each do |provides|
|
12
|
-
provides_hash[provides] = item
|
13
|
-
end
|
14
|
-
end
|
15
|
-
# init edges
|
16
|
-
items.each do |item|
|
17
|
-
item.dependencies.each do |dependency|
|
18
|
-
if required_item = provides_hash[dependency]
|
19
|
-
graph.add_edge(required_item, item)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
result = []
|
24
|
-
graph.topsort_iterator.each { |item| result << item }
|
25
|
-
result
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
29
|
-
end
|
@@ -1,51 +0,0 @@
|
|
1
|
-
require 'spec/spec_helper'
|
2
|
-
|
3
|
-
class SortableItem
|
4
|
-
attr_accessor :value
|
5
|
-
attr_accessor :dependencies
|
6
|
-
attr_accessor :provides
|
7
|
-
def initialize(value)
|
8
|
-
@value = value
|
9
|
-
@provides = [value]
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
class SortableClass
|
14
|
-
include Jsus::Topsortable
|
15
|
-
attr_accessor :items
|
16
|
-
end
|
17
|
-
|
18
|
-
describe Jsus::Topsortable do
|
19
|
-
subject { SortableClass.new }
|
20
|
-
let(:items) { (0..5).map {|i| SortableItem.new(i) } }
|
21
|
-
let(:topsorted_values) { subject.topsort(:items).map {|item| item.value } }
|
22
|
-
before(:each) do
|
23
|
-
subject.items = items
|
24
|
-
end
|
25
|
-
|
26
|
-
it "should topologically sort items correctly" do
|
27
|
-
items[0].dependencies = [1, 2, 3]
|
28
|
-
items[1].dependencies = [3, 4, 5]
|
29
|
-
items[2].dependencies = [1, 3, 4, 5]
|
30
|
-
items[3].dependencies = []
|
31
|
-
items[4].dependencies = [3, 5]
|
32
|
-
items[5].dependencies = [3]
|
33
|
-
topsorted_values.should == [3, 5, 4, 1, 2, 0]
|
34
|
-
end
|
35
|
-
|
36
|
-
it "should play well with multiple provides case" do
|
37
|
-
items[0].dependencies = [2, 3]
|
38
|
-
items[0].provides = [0, 10 ,20, 30]
|
39
|
-
items[1].dependencies = [10, 30]
|
40
|
-
items[1].provides = [1, 21]
|
41
|
-
items[2].dependencies = []
|
42
|
-
items[2].provides = [2, 32, 42]
|
43
|
-
items[3].dependencies = [42]
|
44
|
-
items[3].provides = [3, 43, 53]
|
45
|
-
items[4].dependencies = [21]
|
46
|
-
items[4].provides = [4, 44]
|
47
|
-
items[5].dependencies = [43, 32, 44]
|
48
|
-
items[5].provides = [5, 55]
|
49
|
-
topsorted_values.should == [2, 3, 0, 1, 4, 5]
|
50
|
-
end
|
51
|
-
end
|