yap-rawline 0.6.3 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -70,22 +70,34 @@ describe RawLine::KeycodeParser do
70
70
  end
71
71
  end
72
72
 
73
- end
73
+ context "given multiple bytes which could map to multiple sequences" do
74
+ let(:keymap) do
75
+ { escape: [?\e.ord] }
76
+ { left_arrow: [?\e.ord, ?[.ord, ?D.ord] }
77
+ end
78
+ let(:bytes) { ["a".ord, ?\e.ord, ?[.ord, ?D.ord, "C".ord] }
74
79
 
75
- end
80
+ it "returns the longest sequence matching" do
81
+ expect(parse).to eq ["a", [?\e.ord, ?[.ord, ?D.ord], "C"]
82
+ end
83
+ end
76
84
 
85
+ context "given a lot of bytes" do
86
+ let(:keymap) do
87
+ { left_arrow: [?\e.ord, ?[.ord, ?D.ord] }
88
+ end
89
+ let(:alphabet_chars) do
90
+ ["a"].tap { |bytes| 256**256.times { bytes << bytes.last.succ } }
91
+ end
92
+ let(:bytes) { alphabet_chars.map(&:ord) }
93
+
94
+ it "returns the keycodes speedily" do
95
+ Timeout.timeout(0.5) do
96
+ parse
97
+ end
98
+ end
77
99
 
78
- __END__
79
- @escape_codes = [?\e.ord]
80
- @keys.merge!(
81
- {
82
- :up_arrow => [?\e.ord, ?[.ord, ?A.ord],
83
- :down_arrow => [?\e.ord, ?[.ord, ?B.ord],
84
- :right_arrow => [?\e.ord, ?[.ord, ?C.ord],
85
- :left_arrow => [?\e.ord, ?[.ord, ?D.ord],
86
- :insert => [?\e.ord, ?[, ?2.ord, ?~.ord],
87
- :delete => [?\e.ord, ?[, ?3.ord, ?~.ord],
88
- :backspace => [?\C-?.ord],
89
- :enter => (HighLine::SystemExtensions::CHARACTER_MODE == 'termios' ? [?\n.ord] : [?\r.ord]),
90
-
91
- :ctrl_alt_a => [?\e.ord, ?\C-a.ord],
100
+ end
101
+ end
102
+
103
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yap-rawline
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.3
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fabio Cevasco
@@ -51,14 +51,14 @@ dependencies:
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 0.4.2
54
+ version: 0.4.3
55
55
  type: :runtime
56
56
  prerelease: false
57
57
  version_requirements: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 0.4.2
61
+ version: 0.4.3
62
62
  - !ruby/object:Gem::Dependency
63
63
  name: term-ansicolor
64
64
  requirement: !ruby/object:Gem::Requirement