nrser 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5311c0d4f62623e09b45060dfdfb067649b17335
4
- data.tar.gz: e0081ada45abd36fab607fbf9971700a94456df0
3
+ metadata.gz: a6738d85c4a157986e23fb51cac830faf2998666
4
+ data.tar.gz: b8a22cdcdd8b36a3ae2026440b8b4844d28fb9af
5
5
  SHA512:
6
- metadata.gz: bde6122d23a49148589971a45ffbe9a55d0e5f703d72032eea32195d8d4da40f0f188b1e901532ec8c15b457fadacfee011f83eaa9a4b5bbd3198977ceee891b
7
- data.tar.gz: ca3036819080f5fd335dbcb93dbaae77be968873f44945e9138a92f9779b88fdbe510073b664130c2a274937a26a8f361347919081cd4478f5cafa3c99f40f24
6
+ metadata.gz: 1cc98bc014b43e51379d2efb4e51bc50268f97db230fdc3c606e350e27b4666398069c07a35fd2efcfbd52b96097a2e3d82de4ab7ac63273276db5b1293b1482
7
+ data.tar.gz: 6fa17fd7b7f57e24da23e2807a3d25c0cff307f84e9c7f793b3ece06eff5f92e7b5592aa5a630525890163c75860f13c96946d21f8180edf981ca546320a3483
@@ -32,6 +32,16 @@ class NRSER::MeanStreak::Document
32
32
  # ======================================================================
33
33
 
34
34
 
35
+ # Classes
36
+ # ============================================================================
37
+
38
+ # A position in a source.
39
+ #
40
+ class SourcePosition
41
+ # def initialize source,
42
+ end
43
+
44
+
35
45
  # Class Methods
36
46
  # ======================================================================
37
47
 
@@ -56,7 +66,6 @@ class NRSER::MeanStreak::Document
56
66
  singleton_class.send :alias_method, :from_s, :parse
57
67
 
58
68
 
59
-
60
69
  # Attributes
61
70
  # ======================================================================
62
71
 
@@ -114,17 +123,35 @@ class NRSER::MeanStreak::Document
114
123
  end
115
124
 
116
125
 
126
+ # @return [Hash<Symbol, Hash<Symbol, Integer>>]
127
+ # Looks like:
128
+ #
129
+ # {
130
+ # first_byte: {
131
+ # line: Non-negative Integer,
132
+ # column: Non-negative Integer,
133
+ # index: Non-negative Integer,
134
+ # },
135
+ # last_byte: {
136
+ # line: Non-negative Integer,
137
+ # column: Non-negative Integer,
138
+ # index: Non-negative Integer,
139
+ # },
140
+ # }
141
+ #
142
+ # All integers are zero-indexed byte array indexes.
143
+ #
117
144
  def source_byte_indexes node
118
145
  pos = node.sourcepos
119
146
 
120
147
  indexes = {
121
148
  first_byte: {
122
- line: pos[:start_line] - 1,
123
- column: pos[:start_column] - 1,
149
+ line: [0, pos[:start_line] - 1].max,
150
+ column: [0, pos[:start_column] - 1].max,
124
151
  },
125
152
  last_byte: {
126
- line: pos[:end_line] - 1,
127
- column: pos[:end_column] - 1,
153
+ line: [0, pos[:end_line] - 1].max,
154
+ column: [0, pos[:end_column] - 1].max,
128
155
  },
129
156
  }
130
157
 
@@ -136,7 +163,15 @@ class NRSER::MeanStreak::Document
136
163
  end
137
164
 
138
165
 
166
+ # Computes the *byte* index for a `line` and `column` in the source, both
167
+ # of which *are in bytes*.
168
+ #
169
+ # @param [Integer] line:
170
+ #
171
+ #
139
172
  def source_byte_index line:, column:
173
+ t.hash_(keys: t.sym, values: t.non_neg_int?).check( line: line, column: column)
174
+
140
175
  # source_lines[0...line].map( &:bytesize ).reduce( column, :+ )
141
176
  byte_index = column
142
177
  if line > 0
@@ -106,14 +106,34 @@ class NRSER::MeanStreak
106
106
  end # #parse
107
107
 
108
108
 
109
+ # Render a {NRSER::MeanStreak::Document} or a source string.
110
+ #
111
+ # @param [NRSER::MeanStreak::Document | String] doc_or_source
112
+ # Document or source to render.
113
+ #
114
+ # @return [String]
115
+ # Rendered string.
116
+ #
109
117
  def render doc_or_source
110
- doc = if doc_or_source.is_a? NRSER::MeanStreak::Document
111
- doc_or_source
118
+ case doc_or_source
119
+ when NRSER::MeanStreak::Document
120
+ doc_or_source.render
121
+
122
+ when ''
123
+ # Short-circuit for empty strings because CommonMark's document
124
+ # node for empty strings returns a weird `#sourcepos` that ends before it
125
+ # begins (start: line 1, column 1; end: line 0, column 0).
126
+ #
127
+ # Going to protect against line 0 / column 0 in
128
+ # {NRSER::MeanStreak::Document#source_byte_indexes} too but since the
129
+ # empty strings just renders the empty string we can just return that
130
+ # here.
131
+ #
132
+ ''
133
+
112
134
  else
113
- parse doc_or_source
135
+ parse( doc_or_source ).render
114
136
  end
115
-
116
- doc.render
117
137
  end
118
138
 
119
139
 
@@ -25,7 +25,7 @@ module NRSER::RSpex::ExampleGroup
25
25
  # @return [void]
26
26
  #
27
27
  def describe_called_with *args, &body
28
- describe_x_type List(*args),
28
+ describe_x Args(*args),
29
29
  type: :called_with,
30
30
  subject_block: -> { super().call *args },
31
31
  &body
data/lib/nrser/rspex.rb CHANGED
@@ -248,6 +248,8 @@ module NRSER::RSpex
248
248
 
249
249
  class Args < List
250
250
  def to_desc max = nil
251
+ return '()' if empty?
252
+
251
253
  if last.is_a?( Hash )
252
254
  [
253
255
  List.new( self[0..-2] ).to_desc,
data/lib/nrser/version.rb CHANGED
@@ -18,7 +18,7 @@ module NRSER
18
18
  #
19
19
  # @return [String]
20
20
  #
21
- VERSION = "0.2.0"
21
+ VERSION = '0.2.1'
22
22
 
23
23
 
24
24
  module Version
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nrser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - nrser