xiki 0.5.0a
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +11 -0
- data/LICENSE +22 -0
- data/README.markdown +83 -0
- data/Rakefile +8 -0
- data/bin/xiki +46 -0
- data/etc/command/xiki_command.rb +203 -0
- data/etc/command/xiki_process.rb +52 -0
- data/etc/command/xiki_wrapper +2 -0
- data/etc/js/menu1.js +55 -0
- data/etc/js/xiki.js +259 -0
- data/etc/logo.png +0 -0
- data/etc/presentations/bootstrap.deck +5 -0
- data/etc/presentations/databases.deck +41 -0
- data/etc/presentations/diffs.deck +23 -0
- data/etc/presentations/documentation.deck +14 -0
- data/etc/presentations/effects.deck +5 -0
- data/etc/presentations/face.deck +297 -0
- data/etc/presentations/files.deck +79 -0
- data/etc/presentations/icons.deck +22 -0
- data/etc/presentations/images.deck +24 -0
- data/etc/presentations/key_shortcuts.deck +16 -0
- data/etc/presentations/macros.deck +18 -0
- data/etc/presentations/menu_classes.deck +44 -0
- data/etc/presentations/menu_directories.deck +30 -0
- data/etc/presentations/notes.deck +19 -0
- data/etc/presentations/other_languages.deck +55 -0
- data/etc/presentations/other_wiki_syntaxes.deck +4 -0
- data/etc/presentations/piano.deck +5 -0
- data/etc/presentations/potential/diffs.deck +38 -0
- data/etc/presentations/potential/evolution.deck +18 -0
- data/etc/presentations/potential/intro.deck +711 -0
- data/etc/presentations/potential/intro1.deck +711 -0
- data/etc/presentations/potential/intro2.deck +97 -0
- data/etc/presentations/potential/make_mysql_menu.deck +36 -0
- data/etc/presentations/potential/ruby_development.deck +17 -0
- data/etc/presentations/potential/ui_prototyping.deck +50 -0
- data/etc/presentations/potential/web_dev.deck +4 -0
- data/etc/presentations/potential/web_development.deck +10 -0
- data/etc/presentations/potential/wiki.deck +45 -0
- data/etc/presentations/presentations.deck +24 -0
- data/etc/presentations/rails_development.deck +29 -0
- data/etc/presentations/search_key_shortcuts.deck +37 -0
- data/etc/presentations/simplest_possible_ui.deck +37 -0
- data/etc/presentations/svg.deck +5 -0
- data/etc/presentations/testing.deck +28 -0
- data/etc/presentations/the_end.deck +13 -0
- data/etc/presentations/type_something_and_double_click.deck +57 -0
- data/etc/presentations/type_the_acronym.deck +144 -0
- data/etc/presentations/web_browser.deck +56 -0
- data/etc/presentations/xiki_command.deck +20 -0
- data/etc/presentations/xiki_url.deck +14 -0
- data/etc/shark.icns +0 -0
- data/etc/shark_script.icns +0 -0
- data/etc/snippets/html.notes +7 -0
- data/etc/snippets/notes.notes +20 -0
- data/etc/snippets/rb.notes +38 -0
- data/etc/templates/menu_template.menu +2 -0
- data/etc/templates/menu_template.rb +8 -0
- data/etc/templates/template.rb +5 -0
- data/etc/themes/Dark_Metal.notes +28 -0
- data/etc/themes/Orange_Path.notes +15 -0
- data/etc/themes/Shiny_Blue.notes +27 -0
- data/etc/themes/Shiny_Green.notes +27 -0
- data/etc/wrappers/wrapper.js +17 -0
- data/etc/wrappers/wrapper.py +20 -0
- data/etc/wrappers/wrapper.rb +25 -0
- data/lib/block.rb +72 -0
- data/lib/bookmarks.rb +352 -0
- data/lib/buffers.rb +170 -0
- data/lib/clipboard.rb +333 -0
- data/lib/code.rb +860 -0
- data/lib/code_tree.rb +476 -0
- data/lib/color.rb +274 -0
- data/lib/console.rb +557 -0
- data/lib/control_lock.rb +9 -0
- data/lib/control_tab.rb +176 -0
- data/lib/core_ext.rb +31 -0
- data/lib/cursor.rb +111 -0
- data/lib/deletes.rb +65 -0
- data/lib/diff_log.rb +297 -0
- data/lib/effects.rb +145 -0
- data/lib/environment.rb +5 -0
- data/lib/file_tree.rb +1875 -0
- data/lib/files.rb +334 -0
- data/lib/hide.rb +259 -0
- data/lib/history.rb +286 -0
- data/lib/image.rb +51 -0
- data/lib/incrementer.rb +15 -0
- data/lib/insert.rb +7 -0
- data/lib/irc.rb +22 -0
- data/lib/key_bindings.rb +658 -0
- data/lib/keys.rb +754 -0
- data/lib/launcher.rb +1351 -0
- data/lib/line.rb +429 -0
- data/lib/links.rb +6 -0
- data/lib/location.rb +175 -0
- data/lib/macros.rb +48 -0
- data/lib/man.rb +19 -0
- data/lib/menu.rb +708 -0
- data/lib/merb.rb +259 -0
- data/lib/message.rb +5 -0
- data/lib/meths.rb +56 -0
- data/lib/mode.rb +34 -0
- data/lib/move.rb +248 -0
- data/lib/notes.rb +1000 -0
- data/lib/numbers.rb +45 -0
- data/lib/ol.rb +203 -0
- data/lib/ol_helper.rb +44 -0
- data/lib/overlay.rb +167 -0
- data/lib/pause_means_space.rb +68 -0
- data/lib/php.rb +22 -0
- data/lib/projects.rb +21 -0
- data/lib/relinquish_exception.rb +2 -0
- data/lib/remote.rb +206 -0
- data/lib/requirer.rb +46 -0
- data/lib/rest_tree.rb +108 -0
- data/lib/ruby.rb +57 -0
- data/lib/ruby_console.rb +165 -0
- data/lib/search.rb +1572 -0
- data/lib/search_term.rb +40 -0
- data/lib/snippet.rb +68 -0
- data/lib/specs.rb +229 -0
- data/lib/styles.rb +274 -0
- data/lib/svn.rb +682 -0
- data/lib/text_util.rb +110 -0
- data/lib/tree.rb +1871 -0
- data/lib/tree_cursor.rb +87 -0
- data/lib/trouble_shooting.rb +27 -0
- data/lib/url_tree.rb +11 -0
- data/lib/view.rb +1474 -0
- data/lib/window.rb +133 -0
- data/lib/xiki.rb +404 -0
- data/menus/accounts.rb +5 -0
- data/menus/address_book.rb +21 -0
- data/menus/agenda.rb +28 -0
- data/menus/all.rb +5 -0
- data/menus/amazon.rb +16 -0
- data/menus/app.rb +16 -0
- data/menus/applescript.rb +46 -0
- data/menus/as.rb +15 -0
- data/menus/bookmarklet.rb +63 -0
- data/menus/bootstrap.rb +568 -0
- data/menus/browse.rb +13 -0
- data/menus/browser.rb +78 -0
- data/menus/cassandra_db.rb +36 -0
- data/menus/chmod.rb +27 -0
- data/menus/classes.rb +5 -0
- data/menus/coffee_script.rb +35 -0
- data/menus/computer.rb +24 -0
- data/menus/contacts.rb +5 -0
- data/menus/cookies.rb +25 -0
- data/menus/couch.rb +184 -0
- data/menus/crop.rb +45 -0
- data/menus/css.rb +55 -0
- data/menus/current.rb +5 -0
- data/menus/db.rb +12 -0
- data/menus/deck.rb +219 -0
- data/menus/dictionary.rb +9 -0
- data/menus/dir.rb +8 -0
- data/menus/disk.rb +5 -0
- data/menus/do.rb +13 -0
- data/menus/docs.rb +58 -0
- data/menus/dotsies.rb +107 -0
- data/menus/edited.rb +18 -0
- data/menus/emacs.rb +17 -0
- data/menus/enter.rb +13 -0
- data/menus/eval.rb +17 -0
- data/menus/executable.rb +16 -0
- data/menus/filter.rb +46 -0
- data/menus/firefox.rb +607 -0
- data/menus/foo.rb +30 -0
- data/menus/french.rb +7 -0
- data/menus/git.rb +185 -0
- data/menus/gito.rb +785 -0
- data/menus/google.rb +35 -0
- data/menus/google_images.rb +11 -0
- data/menus/google_patents.rb +10 -0
- data/menus/gutenberg.rb +13 -0
- data/menus/head.rb +10 -0
- data/menus/headings.rb +39 -0
- data/menus/html.rb +61 -0
- data/menus/icon.rb +40 -0
- data/menus/images.menu +2 -0
- data/menus/img.rb +15 -0
- data/menus/info.rb +9 -0
- data/menus/ip.rb +10 -0
- data/menus/iterm.rb +36 -0
- data/menus/itunes.rb +78 -0
- data/menus/javascript.rb +74 -0
- data/menus/layout.rb +18 -0
- data/menus/local_storage.rb +67 -0
- data/menus/ls.rb +19 -0
- data/menus/mac.rb +87 -0
- data/menus/maps.rb +18 -0
- data/menus/matches.rb +18 -0
- data/menus/memcache.rb +117 -0
- data/menus/mkdir.rb +23 -0
- data/menus/mongo.rb +83 -0
- data/menus/mysql.rb +294 -0
- data/menus/node.rb +88 -0
- data/menus/open.rb +19 -0
- data/menus/outline.rb +24 -0
- data/menus/piano.rb +746 -0
- data/menus/postgres.rb +34 -0
- data/menus/pre.rb +5 -0
- data/menus/python.rb +39 -0
- data/menus/rails.rb +160 -0
- data/menus/rake.rb +12 -0
- data/menus/redmine.rb +168 -0
- data/menus/riak_tree.rb +204 -0
- data/menus/rss.rb +15 -0
- data/menus/safari.rb +11 -0
- data/menus/sass.rb +15 -0
- data/menus/say.rb +6 -0
- data/menus/scale.rb +49 -0
- data/menus/serve.rb +78 -0
- data/menus/shuffle.rb +24 -0
- data/menus/spanish.rb +7 -0
- data/menus/standalone.rb +57 -0
- data/menus/tail.rb +41 -0
- data/menus/technologies.rb +19 -0
- data/menus/themes.rb +32 -0
- data/menus/thesaurus.rb +13 -0
- data/menus/to.rb +24 -0
- data/menus/twitter.rb +57 -0
- data/menus/wikipedia.rb +34 -0
- data/menus/words.rb +11 -0
- data/spec/code_tree_spec.rb +59 -0
- data/spec/diff_log_spec.rb +40 -0
- data/spec/file_tree_spec.rb +102 -0
- data/spec/keys_spec.rb +24 -0
- data/spec/line_spec.rb +68 -0
- data/spec/menu_spec.rb +50 -0
- data/spec/ol_spec.rb +98 -0
- data/spec/remote_spec.rb +43 -0
- data/spec/search_spec.rb +162 -0
- data/spec/text_util_spec.rb +119 -0
- data/spec/tree_cursor_spec.rb +91 -0
- data/spec/tree_spec.rb +955 -0
- data/tests/console_test.rb +11 -0
- data/tests/couch_db_test.rb +12 -0
- data/tests/diff_log_test.rb +43 -0
- data/tests/el_mixin.rb +16 -0
- data/tests/git_test.rb +95 -0
- data/tests/keys_test.rb +19 -0
- data/tests/line_test.rb +38 -0
- data/tests/merb_test.rb +11 -0
- data/tests/redmine_test.rb +50 -0
- data/tests/remote_test.rb +31 -0
- data/tests/rest_tree_test.rb +70 -0
- data/xiki.gemspec +37 -0
- metadata +332 -0
data/spec/remote_spec.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
$:.unshift "spec/"
|
2
|
+
require 'rubygems'
|
3
|
+
class Keys
|
4
|
+
def self.method_missing(meth, *args, &block); end
|
5
|
+
end
|
6
|
+
require 'remote'
|
7
|
+
require 'core_ext'
|
8
|
+
|
9
|
+
describe Remote, "#calculate_local_path" do
|
10
|
+
it "should put dashes in path" do
|
11
|
+
Remote.calculate_local_path("/tmp/foo.txt", "server.com").should == "/tmp/remote_rb/server.com,tmp,foo.txt"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe Remote, "#calculate_remote_path" do
|
16
|
+
it "should remove dashes from path" do
|
17
|
+
Remote.calculate_remote_path("/tmp/remote_rb/server.com,tmp,foo.txt").should == "/tmp/foo.txt"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# describe Remote, "#save_file" do
|
22
|
+
# it "should save local file if modified" do
|
23
|
+
# View = mock 'View'
|
24
|
+
# View.should_receive(:path).and_return '/tmp/remote_rb/tmp,hey.txt'
|
25
|
+
# Remote.save_file
|
26
|
+
# end
|
27
|
+
# end
|
28
|
+
|
29
|
+
|
30
|
+
describe Remote, "#save_file" do
|
31
|
+
before(:each) do
|
32
|
+
$el = mock 'el'
|
33
|
+
$el.stub!(:buffer_modified_p).and_return false
|
34
|
+
View = mock 'View'
|
35
|
+
View.stub!(:path).and_return '/tmp/remote_rb/tmp,hey.txt'
|
36
|
+
View.stub!(:file)#.and_return '/tmp/remote_rb/tmp,hey.txt'
|
37
|
+
View.stub!(:beep)#.and_return '/tmp/remote_rb/tmp,hey.txt'
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should save remotely" do
|
41
|
+
# Remote.save_file
|
42
|
+
end
|
43
|
+
end
|
data/spec/search_spec.rb
ADDED
@@ -0,0 +1,162 @@
|
|
1
|
+
$:.unshift "spec/"
|
2
|
+
require 'search'
|
3
|
+
require 'core_ext'
|
4
|
+
|
5
|
+
describe Search, "#case_options" do
|
6
|
+
it "should initialize" do
|
7
|
+
options = Search.case_options
|
8
|
+
options.class.should == Array
|
9
|
+
options[0][0].should == 'upper'
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should convert case correctly" do
|
13
|
+
options = Search.case_options
|
14
|
+
options[0][1].call("hey").should == 'HEY'
|
15
|
+
options[1][1].call("HEY").should == 'hey'
|
16
|
+
options[2][1].call("hey_you").should == 'HeyYou'
|
17
|
+
options[3][1].call("HeyYou").should == 'hey_you'
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
describe Search, "#deep_outline" do
|
23
|
+
|
24
|
+
before(:all) do
|
25
|
+
@small_tree = "
|
26
|
+
daf jam
|
27
|
+
stuff
|
28
|
+
include ink
|
29
|
+
closs Clam
|
30
|
+
daf aa
|
31
|
+
daf tt
|
32
|
+
".unindent
|
33
|
+
end
|
34
|
+
|
35
|
+
it "grabs lines above" do
|
36
|
+
Search.deep_outline(@small_tree, 6)[0].should == "
|
37
|
+
daf jam
|
38
|
+
closs Clam
|
39
|
+
daf tt
|
40
|
+
".unindent
|
41
|
+
end
|
42
|
+
|
43
|
+
it "remembers line we're on" do
|
44
|
+
Search.deep_outline(@small_tree, 5)[1].should == 3
|
45
|
+
end
|
46
|
+
|
47
|
+
it "grabs only lines above with children" do
|
48
|
+
before = "
|
49
|
+
daf jam
|
50
|
+
stuff
|
51
|
+
include ink
|
52
|
+
closs Clam
|
53
|
+
daf zz
|
54
|
+
daf aa
|
55
|
+
stuff
|
56
|
+
daf zzz
|
57
|
+
daf tt
|
58
|
+
".unindent
|
59
|
+
|
60
|
+
result = Search.deep_outline(before, 9)
|
61
|
+
|
62
|
+
result[0].should == "
|
63
|
+
daf jam
|
64
|
+
closs Clam
|
65
|
+
daf aa
|
66
|
+
daf tt
|
67
|
+
".unindent
|
68
|
+
result[1].should == 4
|
69
|
+
end
|
70
|
+
|
71
|
+
it "grabs lines below" do
|
72
|
+
Search.deep_outline(@small_tree, 1)[0].should == "
|
73
|
+
daf jam
|
74
|
+
closs Clam
|
75
|
+
".unindent
|
76
|
+
end
|
77
|
+
|
78
|
+
it "includes lines above and below" do
|
79
|
+
before ="
|
80
|
+
include ink
|
81
|
+
daf a
|
82
|
+
ee
|
83
|
+
bb
|
84
|
+
closs Clam
|
85
|
+
daf aa
|
86
|
+
stuff
|
87
|
+
daf zz
|
88
|
+
daf bb
|
89
|
+
aaa
|
90
|
+
stuff
|
91
|
+
zzz
|
92
|
+
ttt
|
93
|
+
ccc
|
94
|
+
stuff
|
95
|
+
daf zz
|
96
|
+
daf cc
|
97
|
+
stuff
|
98
|
+
daf zzz
|
99
|
+
end
|
100
|
+
".unindent
|
101
|
+
|
102
|
+
result = Search.deep_outline(before, 13)
|
103
|
+
result[0].should == "
|
104
|
+
daf a
|
105
|
+
closs Clam
|
106
|
+
daf aa
|
107
|
+
daf bb
|
108
|
+
aaa
|
109
|
+
ttt
|
110
|
+
ccc
|
111
|
+
daf cc
|
112
|
+
".unindent
|
113
|
+
|
114
|
+
result[1].should == 6
|
115
|
+
|
116
|
+
end
|
117
|
+
|
118
|
+
# it "should convert case correctly" do
|
119
|
+
# options = Search.case_options
|
120
|
+
# options[0][1].call("hey").should == 'HEY'
|
121
|
+
# options[1][1].call("HEY").should == 'hey'
|
122
|
+
# options[2][1].call("hey_you").should == 'HeyYou'
|
123
|
+
# options[3][1].call("HeyYou").should == 'hey_you'
|
124
|
+
# end
|
125
|
+
|
126
|
+
it "ignores Ol lines" do
|
127
|
+
tree = "
|
128
|
+
daf jam
|
129
|
+
aa
|
130
|
+
aaa
|
131
|
+
Ol.line
|
132
|
+
bb
|
133
|
+
Ol.line
|
134
|
+
cc
|
135
|
+
ccc
|
136
|
+
".unindent
|
137
|
+
|
138
|
+
Search.deep_outline(tree, 5)[0].should == "
|
139
|
+
daf jam
|
140
|
+
aa
|
141
|
+
bb
|
142
|
+
cc
|
143
|
+
".unindent
|
144
|
+
end
|
145
|
+
|
146
|
+
end
|
147
|
+
|
148
|
+
|
149
|
+
# describe Search, "# function that prompts" do
|
150
|
+
# # TODO: move this into View.input :choices=>case_options
|
151
|
+
# it "should get input from user" do
|
152
|
+
|
153
|
+
# end
|
154
|
+
# end
|
155
|
+
|
156
|
+
# describe Search, "#change_case" do
|
157
|
+
# it "should change case" do
|
158
|
+
# 1.should == 1
|
159
|
+
# # Line.without_label(:line=>"- hey: you").should == "you"
|
160
|
+
# end
|
161
|
+
# end
|
162
|
+
|
@@ -0,0 +1,119 @@
|
|
1
|
+
$:.unshift "spec/"
|
2
|
+
require 'text_util'
|
3
|
+
|
4
|
+
describe TextUtil, "#unindent" do
|
5
|
+
it "indents to the left" do
|
6
|
+
before =
|
7
|
+
" hey
|
8
|
+
you
|
9
|
+
".gsub(/^ /, '')
|
10
|
+
after =
|
11
|
+
"hey
|
12
|
+
you
|
13
|
+
".gsub(/^ /, '')
|
14
|
+
TextUtil.unindent(before).should == after
|
15
|
+
end
|
16
|
+
|
17
|
+
it "doesn't delete blank lines" do
|
18
|
+
before =
|
19
|
+
" hey
|
20
|
+
|
21
|
+
you
|
22
|
+
".gsub(/^ /, '')
|
23
|
+
after =
|
24
|
+
"hey
|
25
|
+
|
26
|
+
you
|
27
|
+
".gsub(/^ /, '')
|
28
|
+
TextUtil.unindent(before).should == after
|
29
|
+
end
|
30
|
+
|
31
|
+
it "works when inital linebreak" do
|
32
|
+
before =
|
33
|
+
"
|
34
|
+
hey
|
35
|
+
you
|
36
|
+
".gsub(/^ /, '')
|
37
|
+
after =
|
38
|
+
"hey
|
39
|
+
you
|
40
|
+
".gsub(/^ /, '')
|
41
|
+
TextUtil.unindent(before).should == after
|
42
|
+
end
|
43
|
+
|
44
|
+
it "works when tabs exist" do
|
45
|
+
before =
|
46
|
+
"\they
|
47
|
+
\tyou
|
48
|
+
".gsub(/^ /, '')
|
49
|
+
after =
|
50
|
+
"hey
|
51
|
+
you
|
52
|
+
".gsub(/^ /, '')
|
53
|
+
TextUtil.unindent(before).should == after
|
54
|
+
end
|
55
|
+
|
56
|
+
it "works when space on 2nd line" do
|
57
|
+
before =
|
58
|
+
"Dev Todo
|
59
|
+
* Ad
|
60
|
+
* 70:
|
61
|
+
".gsub(/^ /, '')
|
62
|
+
after =
|
63
|
+
"Dev Todo
|
64
|
+
* Ad
|
65
|
+
* 70:
|
66
|
+
".gsub(/^ /, '')
|
67
|
+
TextUtil.unindent(before).should == after
|
68
|
+
end
|
69
|
+
|
70
|
+
it "shouldn't change if only 2 spaces over" do
|
71
|
+
before =
|
72
|
+
"Dev Todo
|
73
|
+
* Ad
|
74
|
+
* 70:
|
75
|
+
".gsub(/^ /, '')
|
76
|
+
after =
|
77
|
+
"Dev Todo
|
78
|
+
* Ad
|
79
|
+
* 70:
|
80
|
+
".gsub(/^ /, '')
|
81
|
+
TextUtil.unindent(before).should == after
|
82
|
+
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
describe TextUtil, "#snake_case" do
|
87
|
+
it "converts to snake" do
|
88
|
+
TextUtil.snake_case("core_platform").should == "core_platform"
|
89
|
+
TextUtil.snake_case("CorePlatform").should == "core_platform"
|
90
|
+
TextUtil.snake_case("/CorePlatform").should == "core_platform"
|
91
|
+
TextUtil.snake_case("core platform").should == "core_platform"
|
92
|
+
TextUtil.snake_case("core-platform").should == "core_platform"
|
93
|
+
|
94
|
+
hi = "HiYou"
|
95
|
+
TextUtil.snake_case! hi
|
96
|
+
hi.should == "hi_you"
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe TextUtil, "#camel_case" do
|
101
|
+
it "converts to camel" do
|
102
|
+
TextUtil.camel_case("core_platform").should == "CorePlatform"
|
103
|
+
TextUtil.camel_case("CORE_PLATFORM").should == "CorePlatform"
|
104
|
+
TextUtil.camel_case("CorePlatform").should == "CorePlatform"
|
105
|
+
TextUtil.camel_case("/CorePlatform").should == "CorePlatform"
|
106
|
+
TextUtil.camel_case("core platform").should == "CorePlatform"
|
107
|
+
TextUtil.camel_case("core-platform").should == "CorePlatform"
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
describe TextUtil, "#title_case" do
|
112
|
+
it "converts to title case" do
|
113
|
+
TextUtil.title_case("core_platform").should == "Core Platform"
|
114
|
+
TextUtil.title_case("CorePlatform").should == "Core Platform"
|
115
|
+
TextUtil.title_case("/CorePlatform").should == "/Core Platform"
|
116
|
+
TextUtil.title_case("core platform").should == "Core Platform"
|
117
|
+
TextUtil.title_case("core-platform").should == "Core Platform"
|
118
|
+
end
|
119
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
$:.unshift "spec/"
|
2
|
+
require 'core_ext'
|
3
|
+
require 'tree_cursor'
|
4
|
+
require 'ol'
|
5
|
+
|
6
|
+
def a_aa_tree
|
7
|
+
"
|
8
|
+
- a/
|
9
|
+
- aa/
|
10
|
+
".unindent
|
11
|
+
end
|
12
|
+
|
13
|
+
describe TreeCursor, "#each" do
|
14
|
+
it "loops through each line" do
|
15
|
+
tc = TreeCursor.new "- a/\n - aa/", 1
|
16
|
+
|
17
|
+
result, indexes = "", []
|
18
|
+
tc.each do
|
19
|
+
result << tc.line
|
20
|
+
indexes << tc.i
|
21
|
+
end
|
22
|
+
|
23
|
+
result.should == "- a/ - aa/"
|
24
|
+
indexes.should == [0, 1]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe TreeCursor, "#at_leaf?" do
|
29
|
+
it "recognizes leaf if no children" do
|
30
|
+
TreeCursor.new("
|
31
|
+
- a/
|
32
|
+
- aa/".unindent).at_leaf?.should == true
|
33
|
+
end
|
34
|
+
|
35
|
+
it "returns false if children" do
|
36
|
+
TreeCursor.new(a_aa_tree).at_leaf?.should == false
|
37
|
+
end
|
38
|
+
|
39
|
+
it "recognizes leaf if at end" do
|
40
|
+
TreeCursor.new("
|
41
|
+
- a/
|
42
|
+
- aa/".unindent, 1).at_leaf?.should == true
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe TreeCursor, "#select" do
|
47
|
+
it "finds matching line" do
|
48
|
+
tc = TreeCursor.new(a_aa_tree)
|
49
|
+
|
50
|
+
tc.select " - aa/"
|
51
|
+
tc.i.should == 1
|
52
|
+
end
|
53
|
+
|
54
|
+
it "stays at 0 when no matching line" do
|
55
|
+
tc = TreeCursor.new(a_aa_tree)
|
56
|
+
|
57
|
+
tc.select " - aaa/"
|
58
|
+
tc.i.should == 0
|
59
|
+
end
|
60
|
+
|
61
|
+
it "finds matching when bullet changed" do
|
62
|
+
tc = TreeCursor.new(a_aa_tree)
|
63
|
+
tc.select " + aa/"
|
64
|
+
tc.i.should == 1
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe TreeCursor, "#under" do
|
69
|
+
it "returns lines under" do
|
70
|
+
tc = TreeCursor.new(a_aa_tree+" - bb/")
|
71
|
+
tc.under.should == " - aa/\n - bb/\n"
|
72
|
+
end
|
73
|
+
|
74
|
+
it "returns none if at end" do
|
75
|
+
tc = TreeCursor.new(a_aa_tree)
|
76
|
+
tc.i = 1
|
77
|
+
tc.under.should == ""
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe TreeCursor, "#<<" do
|
82
|
+
it "inserts in tree" do
|
83
|
+
tc = TreeCursor.new(a_aa_tree)
|
84
|
+
tc << " - zz/\n"
|
85
|
+
tc.txt.should == "
|
86
|
+
- a/
|
87
|
+
- zz/
|
88
|
+
- aa/
|
89
|
+
".unindent
|
90
|
+
end
|
91
|
+
end
|
data/spec/tree_spec.rb
ADDED
@@ -0,0 +1,955 @@
|
|
1
|
+
$:.unshift "spec/"
|
2
|
+
require 'ol'
|
3
|
+
require 'tree'
|
4
|
+
require 'core_ext'
|
5
|
+
|
6
|
+
describe Tree, "#traverse" do
|
7
|
+
|
8
|
+
it "goes through each item" do
|
9
|
+
paths = []
|
10
|
+
tree = "
|
11
|
+
- a/
|
12
|
+
- b/
|
13
|
+
- c/
|
14
|
+
".unindent
|
15
|
+
|
16
|
+
Tree.traverse tree do |array|
|
17
|
+
paths << array
|
18
|
+
end
|
19
|
+
paths.should == [[["- a/"], "a/"], [["- a/", "- b/"], "a/b/"], [["- c/"], "c/"]]
|
20
|
+
end
|
21
|
+
|
22
|
+
it "handles two-level dropoff and no dropoff" do
|
23
|
+
paths = []
|
24
|
+
tree = "
|
25
|
+
- a/
|
26
|
+
- aa/
|
27
|
+
- aa2/
|
28
|
+
- aaa/
|
29
|
+
- c/
|
30
|
+
".unindent
|
31
|
+
|
32
|
+
Tree.traverse tree do |array|
|
33
|
+
paths << array
|
34
|
+
end
|
35
|
+
|
36
|
+
paths.should ==[
|
37
|
+
[["- a/"], "a/"],
|
38
|
+
[["- a/", "- aa/"], "a/aa/"],
|
39
|
+
[["- a/", "- aa2/"], "a/aa2/"],
|
40
|
+
[["- a/", "- aa2/", "- aaa/"], "a/aa2/aaa/"],
|
41
|
+
[["- c/"], "c/"]
|
42
|
+
]
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
it "leaves in comments" do
|
47
|
+
paths = []
|
48
|
+
tree = "
|
49
|
+
- hey) a/
|
50
|
+
- you) b/
|
51
|
+
- c/
|
52
|
+
".unindent
|
53
|
+
|
54
|
+
Tree.traverse tree do |array|
|
55
|
+
paths << array
|
56
|
+
end
|
57
|
+
paths.should == [
|
58
|
+
[["- hey) a/"], "hey) a/"],
|
59
|
+
[["- hey) a/", "- you) b/"], "hey) a/you) b/"],
|
60
|
+
[["- c/"], "c/"]
|
61
|
+
]
|
62
|
+
end
|
63
|
+
|
64
|
+
it "removes bullets" do
|
65
|
+
paths = []
|
66
|
+
tree = "
|
67
|
+
- a/
|
68
|
+
+ b/
|
69
|
+
".unindent
|
70
|
+
|
71
|
+
Tree.traverse tree, :no_bullets=>1 do |array|
|
72
|
+
paths << array
|
73
|
+
end
|
74
|
+
paths.should == [
|
75
|
+
[["a/"], "a/"], [["a/", "b/"], "a/b/"]
|
76
|
+
]
|
77
|
+
end
|
78
|
+
|
79
|
+
it "passes blanks as nil" do
|
80
|
+
paths = []
|
81
|
+
tree = "
|
82
|
+
- a/
|
83
|
+
|
84
|
+
- b/
|
85
|
+
".unindent
|
86
|
+
|
87
|
+
Tree.traverse tree, :no_bullets=>1 do |array|
|
88
|
+
paths << array
|
89
|
+
end
|
90
|
+
|
91
|
+
paths.should == [
|
92
|
+
[["a/"], "a/"],
|
93
|
+
[[nil], ""],
|
94
|
+
[["b/"], "b/"],
|
95
|
+
]
|
96
|
+
end
|
97
|
+
|
98
|
+
it "passes blanks as nil one level down" do
|
99
|
+
paths = []
|
100
|
+
tree = "
|
101
|
+
- a/
|
102
|
+
- aa/
|
103
|
+
|
104
|
+
- ab/
|
105
|
+
".unindent
|
106
|
+
|
107
|
+
Tree.traverse tree, :no_bullets=>1 do |array|
|
108
|
+
paths << array
|
109
|
+
end
|
110
|
+
paths.should == [
|
111
|
+
[["a/"], "a/"],
|
112
|
+
[["a/", "aa/"], "a/aa/"],
|
113
|
+
[["a/", nil], "a/"],
|
114
|
+
[["a/", "ab/"], "a/ab/"],
|
115
|
+
]
|
116
|
+
end
|
117
|
+
|
118
|
+
it "when blanks, use indent of next line" do
|
119
|
+
paths = []
|
120
|
+
tree = "
|
121
|
+
a/
|
122
|
+
aa/
|
123
|
+
aaa/
|
124
|
+
|
125
|
+
aab/
|
126
|
+
|
127
|
+
ab/
|
128
|
+
aba/
|
129
|
+
|
130
|
+
b/
|
131
|
+
".unindent
|
132
|
+
|
133
|
+
Tree.traverse tree, :no_bullets=>1 do |array|
|
134
|
+
paths << array
|
135
|
+
end
|
136
|
+
paths.should == [
|
137
|
+
[["a/"], "a/"],
|
138
|
+
[["a/", "aa/"], "a/aa/"],
|
139
|
+
[["a/", "aa/", "aaa/"], "a/aa/aaa/"],
|
140
|
+
[["a/", "aa/", nil], "a/aa/"],
|
141
|
+
[["a/", "aa/", "aab/"], "a/aa/aab/"],
|
142
|
+
[["a/", nil], "a/"],
|
143
|
+
[["a/", "ab/"], "a/ab/"],
|
144
|
+
[["a/", "ab/", "aba/"], "a/ab/aba/"],
|
145
|
+
[[nil], ""],
|
146
|
+
[["b/"], "b/"],
|
147
|
+
]
|
148
|
+
end
|
149
|
+
|
150
|
+
|
151
|
+
it "error when blank line between parent and child" do
|
152
|
+
|
153
|
+
# For simplicity, we're just erroring, as opposed to looking ahead
|
154
|
+
# to see what the assumed indent would be.
|
155
|
+
#
|
156
|
+
# It could be possible to assume that the indent is one lower if
|
157
|
+
# there's a child following. But, since we're not allowing space
|
158
|
+
# between a parent and child, this may not be necessary.
|
159
|
+
|
160
|
+
paths = []
|
161
|
+
tree = "
|
162
|
+
- a/
|
163
|
+
|
164
|
+
- aa/
|
165
|
+
".unindent
|
166
|
+
|
167
|
+
lambda {
|
168
|
+
Tree.traverse tree, :no_bullets=>1 do |array|
|
169
|
+
paths << array
|
170
|
+
end
|
171
|
+
}.should raise_error(RuntimeError)
|
172
|
+
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
|
177
|
+
describe Tree, "#dotify" do
|
178
|
+
|
179
|
+
it "adds dot to path when dot in tree" do
|
180
|
+
tree = "
|
181
|
+
- .a/
|
182
|
+
- aa/
|
183
|
+
- b/
|
184
|
+
".unindent
|
185
|
+
|
186
|
+
path = ["a"]
|
187
|
+
Tree.dotify! tree, path
|
188
|
+
path.should == [".a"]
|
189
|
+
end
|
190
|
+
|
191
|
+
it "adds dot one level deep" do
|
192
|
+
tree = "
|
193
|
+
- sample/
|
194
|
+
- .delete/
|
195
|
+
".unindent
|
196
|
+
|
197
|
+
path = ["sample", "delete"]
|
198
|
+
Tree.dotify!(tree, path)
|
199
|
+
path.should == ["sample", ".delete"]
|
200
|
+
end
|
201
|
+
|
202
|
+
it "adds dots at multiple levels" do
|
203
|
+
tree = "
|
204
|
+
- .sample/
|
205
|
+
- .delete/
|
206
|
+
".unindent
|
207
|
+
|
208
|
+
path = ["sample", "delete"]
|
209
|
+
Tree.dotify!(tree, path)
|
210
|
+
path.should == [".sample", ".delete"]
|
211
|
+
end
|
212
|
+
|
213
|
+
|
214
|
+
it "adds dot when same name as other leaf" do
|
215
|
+
tree = "
|
216
|
+
- .delete/
|
217
|
+
- sample/
|
218
|
+
- .add/
|
219
|
+
- sample/
|
220
|
+
".unindent
|
221
|
+
|
222
|
+
path = ["add", "sample"]
|
223
|
+
Tree.dotify!(tree, path)
|
224
|
+
path.should == [".add", "sample"]
|
225
|
+
end
|
226
|
+
|
227
|
+
it "doesn't add dot when already there" do
|
228
|
+
tree = "
|
229
|
+
- .a/
|
230
|
+
- b/
|
231
|
+
".unindent
|
232
|
+
|
233
|
+
path = [".a"]
|
234
|
+
Tree.dotify! tree, path
|
235
|
+
path.should == [".a"]
|
236
|
+
end
|
237
|
+
|
238
|
+
it "adds dot when path longer than tree" do
|
239
|
+
tree = "
|
240
|
+
- .keys/
|
241
|
+
- .start/
|
242
|
+
".unindent
|
243
|
+
|
244
|
+
path = ["keys", "a"]
|
245
|
+
Tree.dotify!(tree, path)
|
246
|
+
path.should == [".keys", "a"]
|
247
|
+
end
|
248
|
+
|
249
|
+
it "shouldn't modify initial tree" do
|
250
|
+
tree = "
|
251
|
+
hi
|
252
|
+
there
|
253
|
+
".unindent
|
254
|
+
|
255
|
+
orig = tree.dup
|
256
|
+
|
257
|
+
target = ["roots", "docs"]
|
258
|
+
Tree.dotify!(tree, target)
|
259
|
+
target.should == ["roots", "docs"]
|
260
|
+
|
261
|
+
tree.should == orig
|
262
|
+
end
|
263
|
+
|
264
|
+
it "adds dot to path when arrow bullets" do
|
265
|
+
tree = "
|
266
|
+
<= .a/
|
267
|
+
- aa/
|
268
|
+
".unindent
|
269
|
+
|
270
|
+
path = ["a"]
|
271
|
+
Tree.dotify! tree, path
|
272
|
+
path.should == [".a"]
|
273
|
+
end
|
274
|
+
|
275
|
+
end
|
276
|
+
|
277
|
+
|
278
|
+
describe Tree, "#leaf" do
|
279
|
+
it "returns last item" do
|
280
|
+
Tree.leaf("aa/bb").should == "bb"
|
281
|
+
Tree.leaf("bb").should == "bb"
|
282
|
+
Tree.leaf("/aa/bb").should == "bb"
|
283
|
+
Tree.leaf("/aa/bb/").should == "bb"
|
284
|
+
end
|
285
|
+
|
286
|
+
it "grabs siblings when pipe" do
|
287
|
+
Line.should_receive(:value).and_return "| bb"
|
288
|
+
Tree.should_receive(:siblings).any_number_of_times.and_return(["| aa", "| bb"])
|
289
|
+
Tree.leaf("| bb").should == "aa\nbb\n"
|
290
|
+
end
|
291
|
+
|
292
|
+
it "grabs siblings when pipe" do
|
293
|
+
Tree.leaf("aa/| bb", :dont_look=>1).should == "bb"
|
294
|
+
end
|
295
|
+
|
296
|
+
it "grabs siblings when slash after pipe" do
|
297
|
+
Line.should_receive(:value).and_return "| b/b"
|
298
|
+
Tree.should_receive(:siblings).any_number_of_times.and_return(["| aa", "| b/b"])
|
299
|
+
Tree.leaf("| b/b").should == "aa\nb/b\n"
|
300
|
+
end
|
301
|
+
|
302
|
+
it "grabs siblings when slash pipe" do
|
303
|
+
Line.should_receive(:value).and_return "| bb / hey"
|
304
|
+
Tree.should_receive(:siblings).and_return ["| aa", "| bb / hey"]
|
305
|
+
Tree.leaf("| bb / hey").should == "aa\nbb / hey\n"
|
306
|
+
end
|
307
|
+
|
308
|
+
it "uses line from path when slash pipe and not on the pipe line" do
|
309
|
+
Line.should_receive(:value).and_return "- red herring"
|
310
|
+
Tree.leaf("aa/|b/b").should == "b/b"
|
311
|
+
end
|
312
|
+
end
|
313
|
+
|
314
|
+
describe Tree, "#quote" do
|
315
|
+
it "quotes normal lines" do
|
316
|
+
Tree.quote("hey\nyou\n").should == "| hey\n| you\n".unindent
|
317
|
+
end
|
318
|
+
|
319
|
+
it "quotes blank lines" do
|
320
|
+
Tree.quote("hey\n\nyou\n").should == "| hey\n|\n| you\n".unindent
|
321
|
+
end
|
322
|
+
|
323
|
+
it "quotes when indented" do
|
324
|
+
Tree.quote("hey\n you\n").should == "| hey\n| you\n".unindent
|
325
|
+
end
|
326
|
+
|
327
|
+
# it "leaves menus unquoted" do
|
328
|
+
|
329
|
+
# TODO Where am I using Tree.quote?
|
330
|
+
|
331
|
+
# before = "
|
332
|
+
# > Using menus
|
333
|
+
# All menus can be used the same way.
|
334
|
+
|
335
|
+
# For more details, see:
|
336
|
+
# + @menu/docs/how_to_use/
|
337
|
+
# "
|
338
|
+
# Tree.quote(before).should == "
|
339
|
+
# > Using menus
|
340
|
+
# | All menus can be used the same way.
|
341
|
+
# |
|
342
|
+
# | For more details, see:
|
343
|
+
# + @menu/docs/how_to_use/
|
344
|
+
# ".unindent
|
345
|
+
# end
|
346
|
+
|
347
|
+
end
|
348
|
+
|
349
|
+
|
350
|
+
describe Tree, "#clear_empty_dirs!" do
|
351
|
+
it "removes one empty dir" do
|
352
|
+
result = Tree.clear_empty_dirs!("
|
353
|
+
/projects/
|
354
|
+
empty/
|
355
|
+
full/
|
356
|
+
database.rhtml
|
357
|
+
".unindent).join("\n")
|
358
|
+
result.should =~ /full/
|
359
|
+
result.should_not =~ /empty/
|
360
|
+
end
|
361
|
+
|
362
|
+
it "removes one empty dir when bullets" do
|
363
|
+
result = Tree.clear_empty_dirs!("
|
364
|
+
- /projects/
|
365
|
+
+ empty/
|
366
|
+
full/
|
367
|
+
database.rhtml
|
368
|
+
".unindent).join("\n")
|
369
|
+
|
370
|
+
result.should =~ /full/
|
371
|
+
result.should_not =~ /empty/
|
372
|
+
end
|
373
|
+
|
374
|
+
it "doesn't remove quoted lines" do
|
375
|
+
result = Tree.clear_empty_dirs!("
|
376
|
+
- /projects/trunk/app/views/assets/details/
|
377
|
+
+ hey/
|
378
|
+
- _database.rhtml
|
379
|
+
|Database Type
|
380
|
+
|Database Name/
|
381
|
+
".unindent).join("\n")
|
382
|
+
|
383
|
+
result.should =~ /Database Type/
|
384
|
+
result.should =~ /Database Name/
|
385
|
+
end
|
386
|
+
|
387
|
+
it "removes files without quotes" do
|
388
|
+
result = Tree.clear_empty_dirs!("
|
389
|
+
- /projects/trunk/
|
390
|
+
- hey.html
|
391
|
+
- you.html
|
392
|
+
| Database Type
|
393
|
+
".unindent, :quotes=>true).join("\n")
|
394
|
+
|
395
|
+
result.should =~ /trunk/
|
396
|
+
result.should =~ /you/
|
397
|
+
result.should_not =~ /hey/
|
398
|
+
end
|
399
|
+
end
|
400
|
+
|
401
|
+
|
402
|
+
describe Tree, "#restore" do
|
403
|
+
|
404
|
+
it "copies missing children when removed" do
|
405
|
+
treea = "
|
406
|
+
- m/
|
407
|
+
- n/
|
408
|
+
".unindent
|
409
|
+
treeb = "
|
410
|
+
- m/
|
411
|
+
- mm/
|
412
|
+
- mm2/
|
413
|
+
".unindent
|
414
|
+
|
415
|
+
Tree.restore(treea, treeb).should == "
|
416
|
+
- m/
|
417
|
+
- mm/
|
418
|
+
- mm2/
|
419
|
+
- n/
|
420
|
+
".unindent
|
421
|
+
end
|
422
|
+
end
|
423
|
+
|
424
|
+
|
425
|
+
describe Tree, "#paths_to_tree" do
|
426
|
+
|
427
|
+
# Uncomment if we mess with paths_to_tree again
|
428
|
+
|
429
|
+
# it "maintains trailing slashes" do
|
430
|
+
# paths = ["/projects/"]
|
431
|
+
|
432
|
+
# txt = Tree.paths_to_tree(paths)
|
433
|
+
# txt.should == "- /projects/\n"
|
434
|
+
# end
|
435
|
+
|
436
|
+
# it "builds a tree" do
|
437
|
+
# paths = %w[
|
438
|
+
# /projects/foo/a.txt
|
439
|
+
# /projects/foo/b.txt
|
440
|
+
# /other/c.txt
|
441
|
+
# ]
|
442
|
+
|
443
|
+
# tree = "
|
444
|
+
# - /other/
|
445
|
+
# + c.txt
|
446
|
+
# - /projects/
|
447
|
+
# - foo/
|
448
|
+
# + a.txt
|
449
|
+
# + b.txt
|
450
|
+
# ".unindent
|
451
|
+
|
452
|
+
# txt = Tree.paths_to_tree(paths)
|
453
|
+
# txt.should == tree
|
454
|
+
# end
|
455
|
+
|
456
|
+
# it "handles menus" do
|
457
|
+
# paths = %w[
|
458
|
+
# Tree/
|
459
|
+
# Tree/api/
|
460
|
+
# dotsies/apply/all views/
|
461
|
+
# dotsies/apply/one view/
|
462
|
+
# files/
|
463
|
+
# ]
|
464
|
+
|
465
|
+
# tree = "
|
466
|
+
# - Tree/
|
467
|
+
# + api
|
468
|
+
# - dotsies/
|
469
|
+
# - apply/
|
470
|
+
# + all views
|
471
|
+
# + one view
|
472
|
+
# - files/
|
473
|
+
# ".unindent
|
474
|
+
|
475
|
+
# txt = Tree.paths_to_tree(paths)
|
476
|
+
# txt.should == tree
|
477
|
+
# end
|
478
|
+
|
479
|
+
end
|
480
|
+
|
481
|
+
|
482
|
+
|
483
|
+
|
484
|
+
# TODO 2011-11-11: turn these into specs!
|
485
|
+
|
486
|
+
|
487
|
+
|
488
|
+
# describe Tree, "#acronym_regexp" do
|
489
|
+
# it "makes regex's that work" do
|
490
|
+
# ...
|
491
|
+
|
492
|
+
# def test_acronym_regexp
|
493
|
+
# str = Tree.acronym_regexp("mr")
|
494
|
+
# #puts str
|
495
|
+
# re = Regexp.new(str)
|
496
|
+
# assert " mar_roon.txt" =~ re
|
497
|
+
# assert " mar.rb" =~ re
|
498
|
+
# assert ! (" mar,rb" =~ re)
|
499
|
+
# assert ! (" mar_xu_rb" =~ re)
|
500
|
+
# end
|
501
|
+
|
502
|
+
# def test_search_dir_names
|
503
|
+
# tree =
|
504
|
+
# " - /docs/
|
505
|
+
# emacs/
|
506
|
+
# elisp.notes
|
507
|
+
# todo/
|
508
|
+
# files.notes
|
509
|
+
# /projects/
|
510
|
+
# app/
|
511
|
+
# controllers/
|
512
|
+
# pages.rb
|
513
|
+
# pages2.rb
|
514
|
+
# helpers/
|
515
|
+
# pages_helper.rb
|
516
|
+
# ".gsub(/^ /, '').split("\n")
|
517
|
+
|
518
|
+
# after =
|
519
|
+
# " /docs/
|
520
|
+
# emacs/
|
521
|
+
# todo/
|
522
|
+
# files.notes
|
523
|
+
# /projects/
|
524
|
+
# app/
|
525
|
+
# controllers/
|
526
|
+
# helpers/
|
527
|
+
# ".gsub(/^ /, '').split("\n")
|
528
|
+
|
529
|
+
# # TODO
|
530
|
+
# #assert_equal after, Tree.search_dir_names(tree, /todo/)
|
531
|
+
# end
|
532
|
+
|
533
|
+
# def test_search_dir_names_no_indent
|
534
|
+
# tree =
|
535
|
+
# "/docs/
|
536
|
+
# elisp.notes
|
537
|
+
# ".gsub(/^ /, '').split("\n")
|
538
|
+
|
539
|
+
# after =
|
540
|
+
# "/docs/
|
541
|
+
# ".gsub(/^ /, '').split("\n")
|
542
|
+
|
543
|
+
# assert_equal after, Tree.search_dir_names(tree, /todo/)
|
544
|
+
# end
|
545
|
+
|
546
|
+
# def test_clean_path
|
547
|
+
# assert_equal '/bla/', Tree.clean_path("- hey: /bla/")
|
548
|
+
# assert_equal 'bla/', Tree.clean_path("- hey: bla/")
|
549
|
+
# assert_equal '/bla/', Tree.clean_path("- /bla/")
|
550
|
+
# assert_equal 'bla/', Tree.clean_path("+ bla/")
|
551
|
+
# end
|
552
|
+
|
553
|
+
# def test_is_root?
|
554
|
+
# assert_equal true, Tree.is_root?("at left")
|
555
|
+
# assert_equal true, Tree.is_root?(" - /hey")
|
556
|
+
# assert_equal true, Tree.is_root?(" /hey")
|
557
|
+
# assert_equal true, Tree.is_root?(" ./hey")
|
558
|
+
# assert_equal false, Tree.is_root?(" .you")
|
559
|
+
# assert_equal true, Tree.is_root?(" $tr/")
|
560
|
+
# assert_equal true, Tree.is_root?(" $tr/##abc/")
|
561
|
+
# # assert_equal false, Tree.is_root?(" $tr")
|
562
|
+
# end
|
563
|
+
|
564
|
+
|
565
|
+
describe Tree, "#children" do
|
566
|
+
|
567
|
+
it "shows shallowest items when blank path" do
|
568
|
+
Tree.children("
|
569
|
+
- a/
|
570
|
+
- .b/
|
571
|
+
", "").should == "
|
572
|
+
+ a/
|
573
|
+
+ b/
|
574
|
+
".unindent
|
575
|
+
end
|
576
|
+
|
577
|
+
it "shows children of 1 deep" do
|
578
|
+
Tree.children("
|
579
|
+
- a/
|
580
|
+
- aa/
|
581
|
+
- ab/
|
582
|
+
- b/
|
583
|
+
", "a").should == "
|
584
|
+
+ aa/
|
585
|
+
+ ab/
|
586
|
+
".unindent
|
587
|
+
end
|
588
|
+
|
589
|
+
it "returns nil when no match" do
|
590
|
+
Tree.children("
|
591
|
+
- a/
|
592
|
+
- aa/
|
593
|
+
- ab/
|
594
|
+
- b/
|
595
|
+
", "x").should == nil
|
596
|
+
end
|
597
|
+
|
598
|
+
it "allows blank lines" do
|
599
|
+
result = Tree.children "
|
600
|
+
- a/
|
601
|
+
aa
|
602
|
+
|
603
|
+
ab
|
604
|
+
", "a"
|
605
|
+
result.should == "
|
606
|
+
aa
|
607
|
+
|
608
|
+
ab
|
609
|
+
".unindent
|
610
|
+
end
|
611
|
+
|
612
|
+
it "includes blank lines in root" do
|
613
|
+
result = Tree.children "
|
614
|
+
Hey
|
615
|
+
|
616
|
+
you
|
617
|
+
", ""
|
618
|
+
result.should == "
|
619
|
+
Hey
|
620
|
+
|
621
|
+
you
|
622
|
+
".unindent
|
623
|
+
end
|
624
|
+
|
625
|
+
it "doesn't show dots" do
|
626
|
+
Tree.children("
|
627
|
+
- .a/
|
628
|
+
- b/
|
629
|
+
", "").should == "
|
630
|
+
+ a/
|
631
|
+
+ b/
|
632
|
+
".unindent
|
633
|
+
end
|
634
|
+
|
635
|
+
it "doesn't show dots when arrow bullets" do
|
636
|
+
Tree.children("
|
637
|
+
<= .a/
|
638
|
+
- b/
|
639
|
+
", "").should == "
|
640
|
+
<= a/
|
641
|
+
+ b/
|
642
|
+
".unindent
|
643
|
+
end
|
644
|
+
|
645
|
+
it "returns nil if child is star" do
|
646
|
+
Tree.children("
|
647
|
+
- a/
|
648
|
+
- */
|
649
|
+
", "a").should == nil
|
650
|
+
end
|
651
|
+
|
652
|
+
it "matches when star" do
|
653
|
+
Tree.children("
|
654
|
+
- a/
|
655
|
+
- */
|
656
|
+
- aaa/
|
657
|
+
", "a/z").should == "+ aaa/\n"
|
658
|
+
end
|
659
|
+
|
660
|
+
it "includes all sub-items of items under at sign" do
|
661
|
+
Tree.children("
|
662
|
+
- @a/
|
663
|
+
- .b/
|
664
|
+
- c/
|
665
|
+
", "").should == "
|
666
|
+
+ @a/
|
667
|
+
+ b/
|
668
|
+
+ c/
|
669
|
+
".unindent
|
670
|
+
Tree.children("
|
671
|
+
- a/
|
672
|
+
- @b/
|
673
|
+
- c/
|
674
|
+
- d/
|
675
|
+
", "a").should == "
|
676
|
+
+ @b/
|
677
|
+
+ c/
|
678
|
+
+ d/
|
679
|
+
".unindent
|
680
|
+
end
|
681
|
+
|
682
|
+
# it "doesn't include items under item with at sign" do
|
683
|
+
# Tree.children("docs/\n @red/\n - herr/\n", "docs").should == "@red/\n"
|
684
|
+
# end
|
685
|
+
|
686
|
+
it "includes all sub-items when :include_subitems option" do
|
687
|
+
Tree.children("
|
688
|
+
- a/
|
689
|
+
- b/
|
690
|
+
", "", :include_subitems=>1).should == "
|
691
|
+
+ a/
|
692
|
+
+ b/
|
693
|
+
".unindent
|
694
|
+
end
|
695
|
+
|
696
|
+
it "includes all sub-items when no slashes" do
|
697
|
+
Tree.children("
|
698
|
+
- a
|
699
|
+
- b
|
700
|
+
|
701
|
+
- c
|
702
|
+
", "").should == "
|
703
|
+
- a
|
704
|
+
- b
|
705
|
+
|
706
|
+
- c
|
707
|
+
".unindent
|
708
|
+
end
|
709
|
+
|
710
|
+
it "doesn't misinterpret blank lines as children" do
|
711
|
+
result = Tree.children "
|
712
|
+
- a/
|
713
|
+
|
714
|
+
- b/
|
715
|
+
", "a"
|
716
|
+
result.should == nil
|
717
|
+
end
|
718
|
+
|
719
|
+
it "isn't confused by blank lines a level deeper" do
|
720
|
+
result = Tree.children "
|
721
|
+
a/
|
722
|
+
aa
|
723
|
+
|
724
|
+
ab
|
725
|
+
b/
|
726
|
+
", ""
|
727
|
+
result.should == "
|
728
|
+
a/
|
729
|
+
b/
|
730
|
+
".unindent
|
731
|
+
end
|
732
|
+
|
733
|
+
it "associates blank lines at end with root" do
|
734
|
+
result = Tree.children "
|
735
|
+
a/
|
736
|
+
aa
|
737
|
+
|
738
|
+
b/
|
739
|
+
", ""
|
740
|
+
result.should == "
|
741
|
+
a/
|
742
|
+
|
743
|
+
b/
|
744
|
+
".unindent
|
745
|
+
end
|
746
|
+
|
747
|
+
end
|
748
|
+
|
749
|
+
describe Tree, "#children_old" do
|
750
|
+
|
751
|
+
before(:all) do
|
752
|
+
@tree = "
|
753
|
+
- .aa
|
754
|
+
- .bb/
|
755
|
+
- .bb1/
|
756
|
+
- bb11
|
757
|
+
- .bb2
|
758
|
+
- cc/
|
759
|
+
- .cc1/
|
760
|
+
- .cc2
|
761
|
+
- dd/
|
762
|
+
| > Heading
|
763
|
+
| Underneath.
|
764
|
+
- ee/
|
765
|
+
- ee2/
|
766
|
+
| > Heading
|
767
|
+
| Underneath.
|
768
|
+
- .ff
|
769
|
+
".unindent
|
770
|
+
end
|
771
|
+
|
772
|
+
# TODO put more thought into how to mock this
|
773
|
+
# No idea how it worked when it was in AutoMenu
|
774
|
+
|
775
|
+
before(:each) do
|
776
|
+
Tree.should_receive(:child).and_return "foo"
|
777
|
+
# Line.should_receive(:indent).and_return " "
|
778
|
+
Line.should_receive(:value).with(2).and_return " hey"
|
779
|
+
end
|
780
|
+
|
781
|
+
# it "finds children of root" do
|
782
|
+
# Tree.children(@tree, nil).should == "- .aa\n- .bb/\n- cc/\n- dd/\n- ee/\n- .ff\n"
|
783
|
+
# end
|
784
|
+
|
785
|
+
# it "finds two children" do
|
786
|
+
# Tree.children(@tree, "/cc/").should == "- .cc1/\n- .cc2\n"
|
787
|
+
# end
|
788
|
+
|
789
|
+
# it "finds children 2 levels in" do
|
790
|
+
# Tree.children(@tree, "bb/bb1").should == "- bb11\n"
|
791
|
+
# end
|
792
|
+
|
793
|
+
# it "finds children that have children" do
|
794
|
+
# Tree.children(@tree, "bb").should == "- .bb1/\n- .bb2\n"
|
795
|
+
# end
|
796
|
+
|
797
|
+
# it "finds children when no period" do
|
798
|
+
# Tree.children(@tree, "cc").should == "- .cc1/\n- .cc2\n"
|
799
|
+
# end
|
800
|
+
|
801
|
+
# it "finds nothing when no children" do
|
802
|
+
# Tree.children(@tree, "aa").should == ""
|
803
|
+
# end
|
804
|
+
|
805
|
+
# it "finds nothing when no match" do
|
806
|
+
# Tree.children(@tree, "xx").should == ""
|
807
|
+
# end
|
808
|
+
|
809
|
+
# it "shows quoted children" do
|
810
|
+
# Tree.children(@tree, "/dd/").should == "| > Heading\n| Underneath.\n"
|
811
|
+
# end
|
812
|
+
|
813
|
+
# it "shows quoted children 2 levels in" do
|
814
|
+
# Tree.children(@tree, "/ee/ee2/").should == "| > Heading\n| Underneath.\n"
|
815
|
+
# end
|
816
|
+
|
817
|
+
end
|
818
|
+
|
819
|
+
|
820
|
+
describe Tree, "#target_match" do
|
821
|
+
|
822
|
+
it "matches when blanks" do
|
823
|
+
Tree.target_match("", "a").should == :longer
|
824
|
+
Tree.target_match("a", "").should == :shorter
|
825
|
+
Tree.target_match("", "").should == :same
|
826
|
+
end
|
827
|
+
|
828
|
+
it "matches when no dots" do
|
829
|
+
Tree.target_match("a", "a").should == :same
|
830
|
+
Tree.target_match("a/", "a/").should == :same
|
831
|
+
Tree.target_match("aa/bb", "aa/bb").should == :same
|
832
|
+
end
|
833
|
+
|
834
|
+
it "matches when both dots" do
|
835
|
+
Tree.target_match(".a", ".a").should == :same
|
836
|
+
Tree.target_match(".a/", ".a/").should == :same
|
837
|
+
Tree.target_match(".aa/.bb", ".aa/.bb").should == :same
|
838
|
+
end
|
839
|
+
|
840
|
+
it "matches when tree has dot" do
|
841
|
+
Tree.target_match(".a", "a").should == :same
|
842
|
+
Tree.target_match(".aa/bb", "aa/bb").should == :same
|
843
|
+
end
|
844
|
+
|
845
|
+
it "doesn't match when path has dot" do
|
846
|
+
Tree.target_match("a", ".a").should == nil
|
847
|
+
Tree.target_match("aa/bb", ".aa/bb").should == nil
|
848
|
+
end
|
849
|
+
|
850
|
+
it "doesn't match when ends with substring" do
|
851
|
+
Tree.target_match("aa", "a").should == nil
|
852
|
+
end
|
853
|
+
|
854
|
+
it "matches when target is longer" do
|
855
|
+
Tree.target_match("a/b", "a/b/c").should == :longer
|
856
|
+
end
|
857
|
+
|
858
|
+
it "recognizes longer when path has dot" do
|
859
|
+
Tree.target_match(".sample/", "sample/delete").should == :longer
|
860
|
+
end
|
861
|
+
|
862
|
+
it "matches when target is shorter" do
|
863
|
+
Tree.target_match("a/b", "a").should == :shorter
|
864
|
+
end
|
865
|
+
|
866
|
+
it "recognizes same when one has path" do
|
867
|
+
Tree.target_match("a/", "a").should == :same
|
868
|
+
end
|
869
|
+
|
870
|
+
it "recognizes match when star" do
|
871
|
+
Tree.target_match("a/*/aa/", "a/zzzz").should == :shorter
|
872
|
+
end
|
873
|
+
|
874
|
+
end
|
875
|
+
|
876
|
+
|
877
|
+
describe Tree, "#add_pluses_and_minuses" do
|
878
|
+
|
879
|
+
it "adds bullets" do
|
880
|
+
txt = "aa\n bb\n"
|
881
|
+
Tree.add_pluses_and_minuses(txt)
|
882
|
+
txt.should == "+ aa\n + bb\n"
|
883
|
+
end
|
884
|
+
|
885
|
+
it "doesn't add redundantly" do
|
886
|
+
txt = "- aa\n - bb\n"
|
887
|
+
Tree.add_pluses_and_minuses(txt)
|
888
|
+
txt.should == "- aa\n - bb\n"
|
889
|
+
end
|
890
|
+
|
891
|
+
end
|
892
|
+
|
893
|
+
describe Tree, "#to_html" do
|
894
|
+
it "handles one tag" do
|
895
|
+
Tree.to_html("
|
896
|
+
p/
|
897
|
+
hi
|
898
|
+
".unindent).should == "
|
899
|
+
<p>
|
900
|
+
hi
|
901
|
+
</p>
|
902
|
+
".unindent
|
903
|
+
end
|
904
|
+
|
905
|
+
it "handles single with no contents" do
|
906
|
+
Tree.to_html("
|
907
|
+
p/
|
908
|
+
".unindent).should == "
|
909
|
+
<p>
|
910
|
+
</p>
|
911
|
+
".unindent
|
912
|
+
end
|
913
|
+
|
914
|
+
# it "doesn't close certain tags" do
|
915
|
+
# Tree.to_html("
|
916
|
+
# hr/
|
917
|
+
# ".unindent).should == "
|
918
|
+
# <p>
|
919
|
+
# </p>
|
920
|
+
# ".unindent
|
921
|
+
# end
|
922
|
+
|
923
|
+
it "doesn't confuse comments" do
|
924
|
+
Tree.to_html("
|
925
|
+
p/
|
926
|
+
/* hey */
|
927
|
+
".unindent).should == "
|
928
|
+
<p>
|
929
|
+
/* hey */
|
930
|
+
</p>
|
931
|
+
".unindent
|
932
|
+
end
|
933
|
+
|
934
|
+
it "adds closing tags to html" do
|
935
|
+
Tree.to_html("
|
936
|
+
<p>
|
937
|
+
hi
|
938
|
+
".unindent).should == "
|
939
|
+
<p>
|
940
|
+
hi
|
941
|
+
</p>
|
942
|
+
".unindent
|
943
|
+
end
|
944
|
+
|
945
|
+
it "doesn't close comment tags" do
|
946
|
+
Tree.to_html("
|
947
|
+
<!-- hey -->
|
948
|
+
hi
|
949
|
+
".unindent).should == "
|
950
|
+
<!-- hey -->
|
951
|
+
hi
|
952
|
+
".unindent
|
953
|
+
end
|
954
|
+
|
955
|
+
end
|