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,17 @@
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.empty?" do
8
+ it "returns true when the history is empty" do
9
+ Readline::HISTORY.should be_empty
10
+ Readline::HISTORY.push("test")
11
+ Readline::HISTORY.should_not be_empty
12
+ Readline::HISTORY.pop
13
+ Readline::HISTORY.should be_empty
14
+ end
15
+ end
16
+ end
17
+ 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::HISTORY" do
8
+ it "is extended with the Enumerable module" do
9
+ Readline::HISTORY.should be_kind_of(Enumerable)
10
+ end
11
+ end
12
+ end
13
+ 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
+ require File.dirname(__FILE__) + '/shared/size'
8
+
9
+ describe "Readline::HISTORY.length" do
10
+ it_behaves_like :readline_history_size, :length
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,34 @@
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.pop" do
8
+ it "returns nil when the history is empty" do
9
+ Readline::HISTORY.pop.should be_nil
10
+ end
11
+
12
+ it "returns and removes the last item from the history" do
13
+ Readline::HISTORY.push("1", "2", "3")
14
+ Readline::HISTORY.size.should == 3
15
+
16
+ Readline::HISTORY.pop.should == "3"
17
+ Readline::HISTORY.size.should == 2
18
+
19
+ Readline::HISTORY.pop.should == "2"
20
+ Readline::HISTORY.size.should == 1
21
+
22
+ Readline::HISTORY.pop.should == "1"
23
+ Readline::HISTORY.size.should == 0
24
+ end
25
+
26
+ it "taints the returned strings" do
27
+ Readline::HISTORY.push("1", "2", "3")
28
+ Readline::HISTORY.pop.tainted?.should be_true
29
+ Readline::HISTORY.pop.tainted?.should be_true
30
+ Readline::HISTORY.pop.tainted?.should be_true
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,30 @@
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.push" do
8
+ it "pushes all passed Objects into the history" do
9
+ Readline::HISTORY.push("1", "2", "3")
10
+ Readline::HISTORY.size.should == 3
11
+
12
+ Readline::HISTORY.pop.should == "3"
13
+ Readline::HISTORY.pop.should == "2"
14
+ Readline::HISTORY.pop.should == "1"
15
+ end
16
+
17
+ it "tries to convert the passed Object to a String using #to_str" do
18
+ obj = mock("Converted to String")
19
+ obj.should_receive(:to_str).and_return("converted")
20
+
21
+ Readline::HISTORY.push(obj)
22
+ Readline::HISTORY.pop.should == "converted"
23
+ end
24
+
25
+ it "raises a TypeError when the passed Object can't be converted to a String" do
26
+ lambda { Readline::HISTORY.push(mock("Object")) }.should raise_error(TypeError)
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,14 @@
1
+ describe :readline_history_size, :shared => true do
2
+ it "returns the size of the history" do
3
+ Readline::HISTORY.send(@method).should == 0
4
+ Readline::HISTORY.push("1", "2", "")
5
+ Readline::HISTORY.send(@method).should == 3
6
+
7
+ Readline::HISTORY.pop
8
+ Readline::HISTORY.send(@method).should == 2
9
+
10
+ Readline::HISTORY.pop
11
+ Readline::HISTORY.pop
12
+ Readline::HISTORY.send(@method).should == 0
13
+ end
14
+ end
@@ -0,0 +1,34 @@
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.shift" do
8
+ it "returns nil when the history is empty" do
9
+ Readline::HISTORY.shift.should be_nil
10
+ end
11
+
12
+ it "returns and removes the first item from the history" do
13
+ Readline::HISTORY.push("1", "2", "3")
14
+ Readline::HISTORY.size.should == 3
15
+
16
+ Readline::HISTORY.shift.should == "1"
17
+ Readline::HISTORY.size.should == 2
18
+
19
+ Readline::HISTORY.shift.should == "2"
20
+ Readline::HISTORY.size.should == 1
21
+
22
+ Readline::HISTORY.shift.should == "3"
23
+ Readline::HISTORY.size.should == 0
24
+ end
25
+
26
+ it "taints the returned strings" do
27
+ Readline::HISTORY.push("1", "2", "3")
28
+ Readline::HISTORY.shift.tainted?.should be_true
29
+ Readline::HISTORY.shift.tainted?.should be_true
30
+ Readline::HISTORY.shift.tainted?.should be_true
31
+ end
32
+ end
33
+ end
34
+ 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
+ require File.dirname(__FILE__) + '/shared/size'
8
+
9
+ describe "Readline::HISTORY.size" do
10
+ it_behaves_like :readline_history_size, :size
11
+ end
12
+ end
13
+ 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::HISTORY.to_s" do
8
+ it "returns 'HISTORY'" do
9
+ Readline::HISTORY.to_s.should == "HISTORY"
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,38 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ process_is_foreground do
4
+
5
+ not_supported_on :ironruby, :jruby do
6
+ require 'readline'
7
+
8
+ describe "Readline.readline" do
9
+ before :each do
10
+ @file = tmp('readline')
11
+ File.open(@file, 'w') do |file|
12
+ file.puts "test\n"
13
+ end
14
+ @stdin_back = STDIN.dup
15
+ @stdout_back = STDOUT.dup
16
+ STDIN.reopen(@file, 'r')
17
+ STDOUT.reopen("/dev/null")
18
+ end
19
+
20
+ after :each do
21
+ File.delete(@file) if File.exists?(@file)
22
+ STDIN.reopen(@stdin_back)
23
+ STDOUT.reopen(@stdout_back)
24
+ end
25
+
26
+ it "returns the input string" do
27
+ Readline.readline.should == "test"
28
+ end
29
+
30
+ # ruby_version_is "" ... "1.8" do
31
+ # Exclude MRI 1.9.1.p0 because it segfaults.
32
+ it "taints the returned strings" do
33
+ Readline.readline.tainted?.should be_true
34
+ end
35
+ #end
36
+ end
37
+ end
38
+ 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.vi_editing_mode" do
8
+ it "returns nil" do
9
+ Readline.vi_editing_mode.should be_nil
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,4 @@
1
+ --colour
2
+ --format progress
3
+ --loadby mtime
4
+ --reverse
@@ -0,0 +1,53 @@
1
+ if RUBY_PLATFORM == "java"
2
+ $LOAD_PATH.insert(0, "./lib")
3
+ end
4
+
5
+ unless ENV['MSPEC_RUNNER']
6
+ begin
7
+ require "pp"
8
+ require 'mspec/version'
9
+ require 'mspec/helpers'
10
+ require 'mspec/guards'
11
+ require 'mspec/runner/shared'
12
+ require 'mspec/matchers/be_ancestor_of'
13
+ require 'mspec/matchers/output'
14
+ require 'mspec/matchers/output_to_fd'
15
+ require 'mspec/matchers/complain'
16
+ require 'mspec/matchers/equal_element'
17
+ require 'mspec/matchers/equal_utf16'
18
+ require 'mspec/matchers/match_yaml'
19
+
20
+ # Code to setup HOME directory correctly on Windows
21
+ # This duplicates Ruby 1.9 semantics for defining HOME
22
+ platform_is :windows do
23
+ if ENV['HOME']
24
+ ENV['HOME'] = ENV['HOME'].tr '\\', '/'
25
+ elsif ENV['HOMEDIR'] && ENV['HOMEDRIVE']
26
+ ENV['HOME'] = File.join(ENV['HOMEDRIVE'], ENV['HOMEDIR'])
27
+ elsif ENV['HOMEDIR']
28
+ ENV['HOME'] = ENV['HOMEDIR']
29
+ elsif ENV['HOMEDRIVE']
30
+ ENV['HOME'] = ENV['HOMEDRIVE']
31
+ elsif ENV['USERPROFILE']
32
+ ENV['HOME'] = ENV['USERPROFILE']
33
+ else
34
+ puts "No suitable HOME environment found. This means that all of"
35
+ puts "HOME, HOMEDIR, HOMEDRIVE, and USERPROFILE are not set"
36
+ exit 1
37
+ end
38
+ end
39
+
40
+ TOLERANCE = 0.00003 unless Object.const_defined?(:TOLERANCE)
41
+ rescue LoadError
42
+ puts "Please install the MSpec gem to run the specs."
43
+ exit 1
44
+ end
45
+ end
46
+
47
+ minimum_version = "1.5.10"
48
+ unless MSpec::VERSION >= minimum_version
49
+ puts "Please install MSpec version >= #{minimum_version} to run the specs"
50
+ exit 1
51
+ end
52
+
53
+ $VERBOSE = nil unless ENV['OUTPUT_WARNINGS']
@@ -0,0 +1,69 @@
1
+ require 'test/unit'
2
+ require File.dirname(__FILE__) + "/../lib/readline"
3
+
4
+ class TestReadline < Test::Unit::TestCase
5
+
6
+ def test_completion_proc_error
7
+ assert_raise(ArgumentError, "Need ArgumentError exception") { Readline.completion_proc = nil }
8
+ end
9
+
10
+ def test_library_version
11
+ assert_match(/\(FFI wrapper \d\.\d\.\d\)/, Readline::VERSION)
12
+ end
13
+
14
+ def test_implimented_methods
15
+ assert_nil(Readline.completer_word_break_characters)
16
+ assert(Readline.completer_word_break_characters = "test")
17
+ assert_equal("\"'", Readline.basic_quote_characters)
18
+ assert(Readline.basic_quote_characters = "test")
19
+ assert_nil(Readline.completer_quote_characters)
20
+ assert(Readline.completer_quote_characters = "test")
21
+ assert_nil(Readline.filename_quote_characters)
22
+ assert(Readline.filename_quote_characters = "test")
23
+ assert_equal(" \t\n\"\\'`@$><=;|&{(", Readline.basic_word_break_characters)
24
+ assert(Readline.basic_word_break_characters = "test")
25
+ assert_equal(" ", Readline.completion_append_character)
26
+ assert(Readline.completion_append_character = "_")
27
+ assert_nil(Readline.vi_editing_mode)
28
+ assert_nil(Readline.emacs_editing_mode)
29
+ assert_nil(Readline.completion_proc)
30
+ assert_equal(0, Readline.refresh_line)
31
+ end
32
+
33
+ def test_history
34
+ his = Readline::HISTORY
35
+ assert_equal("HISTORY", his.to_s)
36
+ assert_raise(IndexError, "need index error") { his[0] }
37
+
38
+ assert(his.empty?)
39
+ assert_equal("HISTORY", (his << "hist1").to_s)
40
+ assert_equal(false, his.empty?)
41
+ assert_equal("hist1", his.pop)
42
+
43
+ assert_equal("HISTORY", (his << "hist1").to_s)
44
+ assert_equal("HISTORY", (his << "hist2").to_s)
45
+ assert_equal("hist1", his.shift)
46
+ assert_equal("hist2", his.shift)
47
+
48
+ assert_equal("HISTORY", (his << "hist1").to_s)
49
+ assert_equal("hist1", his.delete_at(0))
50
+ assert(his.empty?)
51
+ end
52
+
53
+ # def test_completion
54
+ # words = %w[foo foobar foobaz]
55
+ # Readline.completion_proc = proc do |word|
56
+ # words.grep(/\A#{Regexp.quote word}/)
57
+ # end
58
+ # while buf = Readline.readline("> ")
59
+ # p buf
60
+ # end
61
+ # end
62
+
63
+ # def test_completion2
64
+ # Readline.completion_proc = Readline::FILENAME_COMPLETION_PROC
65
+ # while buf = Readline.readline("> ")
66
+ # p buf
67
+ # end
68
+ # end
69
+ end
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: readline-ffi
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.2
6
+ platform: ruby
7
+ authors:
8
+ - Koichiro Ohba
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-08-29 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: ffi
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.0.0
24
+ type: :runtime
25
+ version_requirements: *id001
26
+ description: Readline-ffi is a wrapper library of Readline, using Ruby-FFI.
27
+ email: koichiro@meadowy.org
28
+ executables: []
29
+
30
+ extensions: []
31
+
32
+ extra_rdoc_files:
33
+ - README.rdoc
34
+ files:
35
+ - .gitignore
36
+ - Gemfile
37
+ - LICENSE
38
+ - README.rdoc
39
+ - Rakefile
40
+ - ext/.gitignore
41
+ - lib/ffi/readline.rb
42
+ - lib/readline-ffi/version.rb
43
+ - lib/readline.rb
44
+ - readline-ffi.gemspec
45
+ - spec/default.mspec
46
+ - spec/library/readline/basic_quote_characters_spec.rb
47
+ - spec/library/readline/basic_word_break_characters_spec.rb
48
+ - spec/library/readline/completer_quote_characters_spec.rb
49
+ - spec/library/readline/completer_word_break_characters_spec.rb
50
+ - spec/library/readline/completion_append_character_spec.rb
51
+ - spec/library/readline/completion_case_fold_spec.rb
52
+ - spec/library/readline/completion_proc_spec.rb
53
+ - spec/library/readline/constants_spec.rb
54
+ - spec/library/readline/emacs_editing_mode_spec.rb
55
+ - spec/library/readline/filename_quote_characters_spec.rb
56
+ - spec/library/readline/history/append_spec.rb
57
+ - spec/library/readline/history/delete_at_spec.rb
58
+ - spec/library/readline/history/each_spec.rb
59
+ - spec/library/readline/history/element_reference_spec.rb
60
+ - spec/library/readline/history/element_set_spec.rb
61
+ - spec/library/readline/history/empty_spec.rb
62
+ - spec/library/readline/history/history_spec.rb
63
+ - spec/library/readline/history/length_spec.rb
64
+ - spec/library/readline/history/pop_spec.rb
65
+ - spec/library/readline/history/push_spec.rb
66
+ - spec/library/readline/history/shared/size.rb
67
+ - spec/library/readline/history/shift_spec.rb
68
+ - spec/library/readline/history/size_spec.rb
69
+ - spec/library/readline/history/to_s_spec.rb
70
+ - spec/library/readline/readline_spec.rb
71
+ - spec/library/readline/vi_editing_mode_spec.rb
72
+ - spec/spec.opts
73
+ - spec/spec_helper.rb
74
+ - test/test_readline.rb
75
+ homepage: https://github.com/koichiro/readline-ffi
76
+ licenses: []
77
+
78
+ post_install_message:
79
+ rdoc_options:
80
+ - --exclude
81
+ - ext
82
+ - --main
83
+ - README
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: 1.8.7
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ none: false
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: "0"
98
+ requirements: []
99
+
100
+ rubyforge_project: readline-ffi
101
+ rubygems_version: 1.8.9
102
+ signing_key:
103
+ specification_version: 3
104
+ summary: Readline-ffi is a wrapper library of Readline, using Ruby-FFI.
105
+ test_files: []
106
+