readline-ffi 0.0.2

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.
Files changed (41) hide show
  1. data/.gitignore +2 -0
  2. data/Gemfile +3 -0
  3. data/LICENSE +22 -0
  4. data/README.rdoc +9 -0
  5. data/Rakefile +37 -0
  6. data/ext/.gitignore +0 -0
  7. data/lib/ffi/readline.rb +71 -0
  8. data/lib/readline-ffi/version.rb +3 -0
  9. data/lib/readline.rb +300 -0
  10. data/readline-ffi.gemspec +25 -0
  11. data/spec/default.mspec +3 -0
  12. data/spec/library/readline/basic_quote_characters_spec.rb +20 -0
  13. data/spec/library/readline/basic_word_break_characters_spec.rb +20 -0
  14. data/spec/library/readline/completer_quote_characters_spec.rb +20 -0
  15. data/spec/library/readline/completer_word_break_characters_spec.rb +20 -0
  16. data/spec/library/readline/completion_append_character_spec.rb +20 -0
  17. data/spec/library/readline/completion_case_fold_spec.rb +22 -0
  18. data/spec/library/readline/completion_proc_spec.rb +26 -0
  19. data/spec/library/readline/constants_spec.rb +22 -0
  20. data/spec/library/readline/emacs_editing_mode_spec.rb +13 -0
  21. data/spec/library/readline/filename_quote_characters_spec.rb +20 -0
  22. data/spec/library/readline/history/append_spec.rb +32 -0
  23. data/spec/library/readline/history/delete_at_spec.rb +49 -0
  24. data/spec/library/readline/history/each_spec.rb +33 -0
  25. data/spec/library/readline/history/element_reference_spec.rb +44 -0
  26. data/spec/library/readline/history/element_set_spec.rb +39 -0
  27. data/spec/library/readline/history/empty_spec.rb +17 -0
  28. data/spec/library/readline/history/history_spec.rb +13 -0
  29. data/spec/library/readline/history/length_spec.rb +13 -0
  30. data/spec/library/readline/history/pop_spec.rb +34 -0
  31. data/spec/library/readline/history/push_spec.rb +30 -0
  32. data/spec/library/readline/history/shared/size.rb +14 -0
  33. data/spec/library/readline/history/shift_spec.rb +34 -0
  34. data/spec/library/readline/history/size_spec.rb +13 -0
  35. data/spec/library/readline/history/to_s_spec.rb +13 -0
  36. data/spec/library/readline/readline_spec.rb +38 -0
  37. data/spec/library/readline/vi_editing_mode_spec.rb +13 -0
  38. data/spec/spec.opts +4 -0
  39. data/spec/spec_helper.rb +53 -0
  40. data/test/test_readline.rb +69 -0
  41. metadata +106 -0
@@ -0,0 +1,25 @@
1
+ # -*- mode: ruby; coding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require 'readline-ffi/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "readline-ffi"
7
+ s.version = ReadlineFFI::VERSION
8
+ s.author = "Koichiro Ohba"
9
+ s.email = "koichiro@meadowy.org"
10
+ s.homepage="https://github.com/koichiro/readline-ffi"
11
+ s.summary = "Readline-ffi is a wrapper library of Readline, using Ruby-FFI."
12
+ s.description = s.summary
13
+ s.rubyforge_project = s.name
14
+ #s.files += %w(docs ext/readline.dll test README.rdoc Rakefile)
15
+ s.rdoc_options << '--exclude' << 'ext' << '--main' << 'README'
16
+ s.extra_rdoc_files = ["README.rdoc"]
17
+ s.has_rdoc = true
18
+ s.required_ruby_version = '>= 1.8.7'
19
+
20
+ s.files = `git ls-files`.split("\n")
21
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
22
+ s.require_paths = ["lib"]
23
+
24
+ s.add_dependency 'ffi', ['>= 1.0.0']
25
+ end
@@ -0,0 +1,3 @@
1
+ class MSpecScript
2
+ set :library, 'library'
3
+ end
@@ -0,0 +1,20 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ process_is_foreground do
4
+
5
+ not_supported_on :ironruby do
6
+ require 'readline'
7
+ describe "Readline.basic_quote_characters" do
8
+ it "returns not nil" do
9
+ Readline.basic_quote_characters.should_not be_nil
10
+ end
11
+ end
12
+
13
+ describe "Readline.basic_quote_characters=" do
14
+ it "returns the passed string" do
15
+ Readline.basic_quote_characters = "test"
16
+ Readline.basic_quote_characters.should == "test"
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ process_is_foreground do
4
+
5
+ not_supported_on :ironruby do
6
+ require 'readline'
7
+ describe "Readline.basic_word_break_characters" do
8
+ it "returns not nil" do
9
+ Readline.basic_word_break_characters.should_not be_nil
10
+ end
11
+ end
12
+
13
+ describe "Readline.basic_word_break_characters=" do
14
+ it "returns the passed string" do
15
+ Readline.basic_word_break_characters = "test"
16
+ Readline.basic_word_break_characters.should == "test"
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ process_is_foreground do
4
+
5
+ not_supported_on :ironruby do
6
+ require 'readline'
7
+ describe "Readline.completer_quote_characters" do
8
+ it "returns nil" do
9
+ Readline.completer_quote_characters.should be_nil
10
+ end
11
+ end
12
+
13
+ describe "Readline.completer_quote_characters=" do
14
+ it "returns the passed string" do
15
+ Readline.completer_quote_characters = "test"
16
+ Readline.completer_quote_characters.should == "test"
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ process_is_foreground do
4
+
5
+ not_supported_on :ironruby do
6
+ require 'readline'
7
+ describe "Readline.completer_word_break_characters" do
8
+ it "returns nil" do
9
+ Readline.completer_word_break_characters.should be_nil
10
+ end
11
+ end
12
+
13
+ describe "Readline.completer_word_break_characters=" do
14
+ it "returns the passed string" do
15
+ Readline.completer_word_break_characters = "test"
16
+ Readline.completer_word_break_characters.should == "test"
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ process_is_foreground do
4
+
5
+ not_supported_on :ironruby do
6
+ require 'readline'
7
+ describe "Readline.completion_append_character" do
8
+ it "returns not nil" do
9
+ Readline.completion_append_character.should_not be_nil
10
+ end
11
+ end
12
+
13
+ describe "Readline.completion_append_character=" do
14
+ it "returns the first character of the passed string" do
15
+ Readline.completion_append_character = "test"
16
+ Readline.completion_append_character.should == "t"
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,22 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ process_is_foreground do
4
+
5
+ not_supported_on :ironruby do
6
+ require 'readline'
7
+ describe "Readline.completion_case_fold" do
8
+ it "returns nil" do
9
+ Readline.completion_case_fold.should be_nil
10
+ end
11
+ end
12
+
13
+ describe "Readline.completion_case_fold=" do
14
+ it "returns the passed boolean" do
15
+ Readline.completion_case_fold = true
16
+ Readline.completion_case_fold.should == true
17
+ Readline.completion_case_fold = false
18
+ Readline.completion_case_fold.should == false
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,26 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ process_is_foreground do
4
+
5
+ not_supported_on :ironruby do
6
+ require 'readline'
7
+ describe "Readline.completion_proc" do
8
+ it "returns nil" do
9
+ Readline.completion_proc.should be_nil
10
+ end
11
+ end
12
+
13
+ describe "Readline.completion_proc=" do
14
+ it "set the proc" do
15
+ proc = Proc.new do |e|
16
+ end
17
+ Readline.completion_proc = proc
18
+ Readline.completion_proc.should == proc
19
+ end
20
+
21
+ it "returns an ArgumentError if not fiven an Proc or #call" do
22
+ lambda { Readline.completion_proc = "test" }.should raise_error(ArgumentError)
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,22 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ process_is_foreground do
4
+
5
+ not_supported_on :ironruby do
6
+ require 'readline'
7
+ # Note: additional specs for HISTORY are in 'history' subdir.
8
+ describe "Readline::HISTORY" do
9
+ it "is defined" do
10
+ Readline.const_defined?(:HISTORY).should == true
11
+ end
12
+ end
13
+
14
+ describe "Readline::VERSION" do
15
+ it "is defined and is a non-empty String" do
16
+ Readline.const_defined?(:VERSION).should == true
17
+ Readline::VERSION.should be_kind_of(String)
18
+ Readline::VERSION.should_not be_empty
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,13 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ process_is_foreground do
4
+
5
+ not_supported_on :ironruby do
6
+ require 'readline'
7
+ describe "Readline.emacs_editing_mode" do
8
+ it "returns nil" do
9
+ Readline.emacs_editing_mode.should be_nil
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,20 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ process_is_foreground do
4
+
5
+ not_supported_on :ironruby do
6
+ require 'readline'
7
+ describe "Readline.filename_quote_characters" do
8
+ it "returns nil" do
9
+ Readline.filename_quote_characters.should be_nil
10
+ end
11
+ end
12
+
13
+ describe "Readline.filename_quote_characters=" do
14
+ it "set the character" do
15
+ Readline.filename_quote_characters = "test"
16
+ Readline.filename_quote_characters.should == "test"
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,32 @@
1
+ require File.dirname(__FILE__) + '/../../../spec_helper'
2
+
3
+ process_is_foreground do
4
+
5
+ not_supported_on :ironruby do
6
+ require 'readline'
7
+ describe "Readline::HISTORY.<<" do
8
+ it "appends the given Object to the history" do
9
+ Readline::HISTORY << "1"
10
+ Readline::HISTORY.size.should == 1
11
+
12
+ Readline::HISTORY << "2"
13
+ Readline::HISTORY.size.should == 2
14
+
15
+ Readline::HISTORY.pop.should == "2"
16
+ Readline::HISTORY.pop.should == "1"
17
+ end
18
+
19
+ it "tries to convert the passed Object to a String using #to_str" do
20
+ obj = mock("Converted to String")
21
+ obj.should_receive(:to_str).and_return("converted")
22
+
23
+ Readline::HISTORY << obj
24
+ Readline::HISTORY.pop.should == "converted"
25
+ end
26
+
27
+ it "raises a TypeError when the passed Object can't be converted to a String" do
28
+ lambda { Readline::HISTORY << mock("Object") }.should raise_error(TypeError)
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,49 @@
1
+ require File.dirname(__FILE__) + '/../../../spec_helper'
2
+
3
+ process_is_foreground do
4
+
5
+ not_supported_on :ironruby do
6
+ require 'readline'
7
+ describe "Readline::HISTORY.delete_at" do
8
+ it "deletes and returns the history entry at the specified index" do
9
+ Readline::HISTORY.push("1", "2", "3")
10
+
11
+ Readline::HISTORY.delete_at(1).should == "2"
12
+ Readline::HISTORY.size.should == 2
13
+
14
+ Readline::HISTORY.delete_at(1).should == "3"
15
+ Readline::HISTORY.size.should == 1
16
+
17
+ Readline::HISTORY.delete_at(0).should == "1"
18
+ Readline::HISTORY.size.should == 0
19
+
20
+
21
+ Readline::HISTORY.push("1", "2", "3", "4")
22
+
23
+ Readline::HISTORY.delete_at(-2).should == "3"
24
+ Readline::HISTORY.size.should == 3
25
+
26
+ Readline::HISTORY.delete_at(-2).should == "2"
27
+ Readline::HISTORY.size.should == 2
28
+
29
+ Readline::HISTORY.delete_at(0).should == "1"
30
+ Readline::HISTORY.size.should == 1
31
+
32
+ Readline::HISTORY.delete_at(0).should == "4"
33
+ Readline::HISTORY.size.should == 0
34
+ end
35
+
36
+ it "raises an IndexError when the given index is greater than the history size" do
37
+ lambda { Readline::HISTORY.delete_at(10) }.should raise_error(IndexError)
38
+ lambda { Readline::HISTORY.delete_at(-10) }.should raise_error(IndexError)
39
+ end
40
+
41
+ it "taints the returned strings" do
42
+ Readline::HISTORY.push("1", "2", "3")
43
+ Readline::HISTORY.delete_at(0).tainted?.should be_true
44
+ Readline::HISTORY.delete_at(0).tainted?.should be_true
45
+ Readline::HISTORY.delete_at(0).tainted?.should be_true
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,33 @@
1
+ require File.dirname(__FILE__) + '/../../../spec_helper'
2
+
3
+ process_is_foreground do
4
+
5
+ not_supported_on :ironruby do
6
+ require 'readline'
7
+ describe "Readline::HISTORY.each" do
8
+ before(:each) do
9
+ Readline::HISTORY.push("1", "2", "3")
10
+ end
11
+
12
+ after(:each) do
13
+ Readline::HISTORY.pop
14
+ Readline::HISTORY.pop
15
+ Readline::HISTORY.pop
16
+ end
17
+
18
+ it "yields each item in the history" do
19
+ result = []
20
+ Readline::HISTORY.each do |x|
21
+ result << x
22
+ end
23
+ result.should == ["1", "2", "3"]
24
+ end
25
+
26
+ it "yields tainted Objects" do
27
+ Readline::HISTORY.each do |x|
28
+ x.tainted?.should be_true
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,44 @@
1
+ require File.dirname(__FILE__) + '/../../../spec_helper'
2
+
3
+ process_is_foreground do
4
+
5
+ not_supported_on :ironruby do
6
+ require 'readline'
7
+ describe "Readline::HISTORY.[]" do
8
+ before(:each) do
9
+ Readline::HISTORY.push("1", "2", "3")
10
+ end
11
+
12
+ after(:each) do
13
+ Readline::HISTORY.pop
14
+ Readline::HISTORY.pop
15
+ Readline::HISTORY.pop
16
+ end
17
+
18
+ it "returns tainted objects" do
19
+ Readline::HISTORY[0].tainted?.should be_true
20
+ Readline::HISTORY[1].tainted?.should be_true
21
+ end
22
+
23
+ it "returns the history item at the passed index" do
24
+ Readline::HISTORY[0].should == "1"
25
+ Readline::HISTORY[1].should == "2"
26
+ Readline::HISTORY[2].should == "3"
27
+
28
+ Readline::HISTORY[-1].should == "3"
29
+ Readline::HISTORY[-2].should == "2"
30
+ Readline::HISTORY[-3].should == "1"
31
+ end
32
+
33
+ it "raises an IndexError when there is no item at the passed index" do
34
+ lambda { Readline::HISTORY[-10] }.should raise_error(IndexError)
35
+ lambda { Readline::HISTORY[-9] }.should raise_error(IndexError)
36
+ lambda { Readline::HISTORY[-8] }.should raise_error(IndexError)
37
+
38
+ lambda { Readline::HISTORY[8] }.should raise_error(IndexError)
39
+ lambda { Readline::HISTORY[9] }.should raise_error(IndexError)
40
+ lambda { Readline::HISTORY[10] }.should raise_error(IndexError)
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,39 @@
1
+ require File.dirname(__FILE__) + '/../../../spec_helper'
2
+
3
+ process_is_foreground do
4
+
5
+ not_supported_on :ironruby do
6
+ require 'readline'
7
+ describe "Readline::HISTORY.[]=" do
8
+ before(:each) do
9
+ Readline::HISTORY.push("1", "2", "3")
10
+ end
11
+
12
+ after(:each) do
13
+ Readline::HISTORY.pop
14
+ Readline::HISTORY.pop
15
+ Readline::HISTORY.pop
16
+ end
17
+
18
+ it "returns the new value for the passed index" do
19
+ (Readline::HISTORY[1] = "second test").should == "second test"
20
+ end
21
+
22
+ it "raises an IndexError when there is no item at the passed positive index" do
23
+ lambda { Readline::HISTORY[10] = "test" }.should raise_error(IndexError)
24
+ end
25
+
26
+ it "sets the item at the given index" do
27
+ Readline::HISTORY[0] = "test"
28
+ Readline::HISTORY[0].should == "test"
29
+
30
+ Readline::HISTORY[1] = "second test"
31
+ Readline::HISTORY[1].should == "second test"
32
+ end
33
+
34
+ it "raises an IndexError when there is no item at the passed negative index" do
35
+ lambda { Readline::HISTORY[10] = "test" }.should raise_error(IndexError)
36
+ end
37
+ end
38
+ end
39
+ end