format_engine 0.5.4 → 0.6.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d4ae6ded21313ff4d99c029eb6e278e5f5de82e8
4
- data.tar.gz: 6c3db7919e7a21366f7ca7d835a86b37e1404719
3
+ metadata.gz: de6ff33cc2d740c1ac1721bc6f2a40bf745208b0
4
+ data.tar.gz: 9ef57766216651bd454e32ff5cecb8d0c187c39e
5
5
  SHA512:
6
- metadata.gz: f7cfb0b7d0bd449b0996d281bb59989fa5578a752007cd7b1d9add50e765bc3658054456898dec3ded0d83cfe50aae84f33ce91934bab3fe787d43e6de769995
7
- data.tar.gz: bca710cf89db0b058a24b35a735902b1f33ca7db0e3f001ee4c7f2b105ee9c51c0e7fabf430d888806f5f02c0e33083a7fed23a0b09374ee5f6937a063b31f5d
6
+ metadata.gz: 915a1c8a1bcda84ae78e197f990a67519511be97174b36574028af18fded89589bf3425cb666c23e85508057fa876c521038c390d2c164a10e8926caa9f3f972
7
+ data.tar.gz: 8d80d8e21223443b3806633d7b2ccbf1fbd714a2488c1dd3a67a8096a988eaba26cd04f9b38e0bca0cb42261394bd1927b98213802335d5e30d9ea496e3bf5a0
data/README.md CHANGED
@@ -52,17 +52,17 @@ class Customer
52
52
 
53
53
  #Demo defn of the strfmt method for formatted string output!
54
54
  attr_formatter :strfmt,
55
- {"%a" => lambda {cat "%#{fmt.width_str}d" % src.age },
56
- "%f" => lambda {cat "%#{fmt.width_str}s" % src.first_name },
57
- "%l" => lambda {cat "%#{fmt.width_str}s" % src.last_name }
55
+ {"%a" => lambda {cat "%#{fmt.width_str}d" % src.age },
56
+ "%f" => lambda {cat "%#{fmt.width_str}s" % src.first_name },
57
+ "%l" => lambda {cat "%#{fmt.width_str}s" % src.last_name }
58
58
  }
59
59
 
60
60
  #Demo defn of the strprs method for formatted string input!
61
61
  attr_parser :strprs,
62
- {"%a" => lambda { tmp[:age] = found.to_i if parse(/(\d)+/ ) },
63
- "%f" => lambda { tmp[:fn] = found if parse(/(\w)+/ ) },
64
- "%l" => lambda { tmp[:ln] = found if parse(/(\w)+/ ) },
65
- :after => lambda { set dst.new(tmp[:fn], tmp[:ln], tmp[:age]) }
62
+ {"%a" => lambda { tmp[:age] = found.to_i if parse(/(\d)+/ ) },
63
+ "%f" => lambda { tmp[:fn] = found if parse(/(\w)+/ ) },
64
+ "%l" => lambda { tmp[:ln] = found if parse(/(\w)+/ ) },
65
+ :after => lambda { set dst.new(tmp[:fn], tmp[:ln], tmp[:age]) }
66
66
  }
67
67
 
68
68
  #Create an instance of the demo customer.
@@ -75,7 +75,7 @@ end
75
75
 
76
76
  cust = Customer.strprs('Jane, Smith 22', "%f, %l %a")
77
77
 
78
- # snd still in another part of Gotham City...
78
+ # and in another part of Gotham City...
79
79
 
80
80
  puts cust.strfmt('%f %l is %a years old.')
81
81
 
@@ -88,34 +88,58 @@ puts cust.strfmt('%f %l is %a years old.')
88
88
 
89
89
  Format String Specification Syntax (Regex):
90
90
 
91
+ The parsing of format specification strings is based on the following regular
92
+ expression. This expression is applied repeatedly until all the specifications
93
+ have been extracted from the input string.
94
+
91
95
  REGEX = %r{(?<lead> (^|(?<=[^\\]))%){0}
92
- (?<flags> [~@#$^&*\=?_<>|!]*){0}
93
- (?<parms> [-+]?(\d+(\.\d+)?)?){0}
94
- (?<var> \g<lead>\g<flags>\g<parms>[a-zA-Z]){0}
95
- (?<set> \g<lead>\g<flags>\d*\[([^\]\\]|\\.)+\]){0}
96
+ (?<flags> [~@#$^&*=?_<>|!]*){0}
97
+
98
+ (?<var> \g<lead>\g<flags>[-+]?(\d+(\.\d+)?)?[a-zA-Z]){0}
99
+ (?<set> \g<lead>\g<flags>(\d+(,\d+)?)?\[([^\]\\]|\\.)+\]){0}
96
100
  (?<per> \g<lead>%){0}
101
+
97
102
  \g<var> | \g<set> | \g<per>
98
103
  }x
99
104
 
100
- Where _var_ describes a format specification, _set_ describes a regex
101
- set (or unset) specification, and _per_ describes a %% literal.
105
+ ### Var
106
+ A format specification of the classical form:
107
+
108
+ %[flags][+/-][width[.precision]]letter
109
+
110
+ ### Set
111
+ A reguluar expression set (or un-set) of the form:
112
+
113
+ %[flags][[min_width,]max_width]"["[^]set_chars"]"
102
114
 
103
- ###Samples:
115
+ ### Per
116
+ A %% which evaluates to a literal character %.
117
+
118
+ ### Literal
119
+ Text in between the various format specifications is treated as literal text.
120
+
121
+ ###Format Internals:
104
122
 
105
123
  The format specification:
106
124
  ```ruby
107
- "Elapsed = %*02H:%M:%-5.2S!"
125
+ "Elapsed = %*02H:%M:%-5.2S %d%% %@1[!?]"
108
126
  ```
109
127
  creates the following format specification array:
110
128
 
111
129
  ```ruby
112
- [Literal("Elapsed = "),
113
- Variable("%*H", ["02"]),
114
- Literal(":"),
115
- Variable("%M", nil).
116
- Literal(":"),
117
- Variable("%S", ["-5", "2"]),
118
- Literal("!")]
130
+ #<FormatEngine::FormatSpec:0x1b4e288
131
+ @specs=
132
+ [Literal("Elapsed = "),
133
+ Variable("%*H", ["02"]),
134
+ Literal(":"),
135
+ Variable("%M", nil),
136
+ Literal(":"),
137
+ Variable("%S", ["-5", "2"]),
138
+ Literal(" "),
139
+ Variable("%d", nil),
140
+ Literal("%"),
141
+ Literal(" "),
142
+ Set("%@[!?]", "%@[", /[!?]{1,1}/)]>
119
143
  ```
120
144
  Where literals are processed as themselves, except:
121
145
  * If that literal ends with a space, that space will parse zero or more spaces.
@@ -125,7 +149,14 @@ When formatting, the trailing space is just another space.
125
149
  character. Thus \\% is equivalent to %%.
126
150
 
127
151
  Variables are executed by looking up the format string (without the width or
128
- precision fields) in the library and executing the corresponding block.
152
+ precision fields) in the library and executing the corresponding block. The
153
+ format string can be seen in the above sample as the first string in the
154
+ Variable
155
+
156
+ Sets work by looking into the input string with their regular expression. Sets
157
+ are only ever used when parsing, never for formatting. Sets are executed by
158
+ first looking up their long name, listed first, and then if the long name is not
159
+ found, their short name, listed second is tried.
129
160
 
130
161
  **Note:** If a format string does not correspond to an entry in the library,
131
162
  an exception occurs.
@@ -160,6 +191,7 @@ Methods
160
191
  * set - Set the return value of the parsing operation to the value that follows.
161
192
  * parse - Look for the string or regex parm that follows. Return the data found or nil.
162
193
  * parse! - Like parse but raises an exception (with optional msg) if not found.
194
+ * grab - Grab some text based on the width of the format.
163
195
  * found? - Did the last parse succeed?
164
196
  * found - The text found by the last parse (or parse!) operation.
165
197
 
@@ -174,17 +206,6 @@ fmt attribute, has itself, the following attributes:
174
206
  * prec_str - The actual precision text or an empty string.
175
207
  * parm_str - The actual parameter (width and precision) text or an empty string.
176
208
 
177
- ## Philosophy
178
-
179
- When designing this gem, a concerted effort has been applied to keeping it as
180
- simple as possible. To this end, many subtle programming techniques have been
181
- avoided in favor of simpler, more obvious approaches. This is based on the
182
- observation that I don't trust code that I don't understand and I avoid code
183
- that I don't trust.
184
-
185
- Feedback on the convenience/clarity balance as well as any other topics are
186
- most welcomed.
187
-
188
209
  ## Contributing
189
210
 
190
211
  #### Plan A
@@ -200,7 +221,7 @@ most welcomed.
200
221
  Go to the GitHub repository and raise an issue calling attention to some
201
222
  aspect that could use some TLC or a suggestion or idea. Apply labels to
202
223
  the issue that match the point you are trying to make. Then follow your
203
- issue and keep up-to-date as it is worked on. Or not as pleases you.
204
- All input are greatly appreciated.
224
+ issue and keep up-to-date as it is worked on. All input are greatly
225
+ appreciated.
205
226
 
206
227
 
@@ -9,6 +9,7 @@ module FormatEngine
9
9
  #Set up base data structures.
10
10
  def initialize(library)
11
11
  @library = library
12
+ @spec_pool = {}
12
13
 
13
14
  #Set up defaults for pre and post amble blocks.
14
15
  nop = lambda { }
@@ -59,7 +60,7 @@ module FormatEngine
59
60
  #* spec_str - The format specification string.
60
61
  #* block - A code block performed for each format specification.
61
62
  def due_process(spec_info, spec_str)
62
- format_spec = FormatSpec.get_spec(spec_str)
63
+ format_spec = get_spec(spec_str)
63
64
 
64
65
  spec_info.instance_exec(&self[:before])
65
66
 
@@ -72,5 +73,10 @@ module FormatEngine
72
73
  spec_info.dst
73
74
  end
74
75
 
76
+ #Get a format specification with caching.
77
+ def get_spec(spec_str)
78
+ @spec_pool[spec_str] ||= FormatSpec.new(spec_str).validate(self)
79
+ end
80
+
75
81
  end
76
82
  end
@@ -18,6 +18,11 @@ module FormatEngine
18
18
  0
19
19
  end
20
20
 
21
+ #Is this format item supported by the engine's library?
22
+ def validate(_engine)
23
+ true
24
+ end
25
+
21
26
  # Format onto the output string
22
27
  def do_format(spec_info)
23
28
  spec_info.dst << @literal
@@ -3,8 +3,11 @@ module FormatEngine
3
3
  #A format engine set specification.
4
4
  class FormatSet
5
5
 
6
- #The fixed part of this set specification.
7
- attr_reader :format
6
+ #The full name of the set.
7
+ attr_reader :long_name
8
+
9
+ #The short form name of the set.
10
+ attr_reader :short_name
8
11
 
9
12
  #The regular expression part of this set specification.
10
13
  attr_reader :regex
@@ -18,14 +21,16 @@ module FormatEngine
18
21
  def initialize(format)
19
22
  @raw = format
20
23
 
21
- if format =~ /(\d+)(?=\[)/
22
- qualifier = "{1,#{$MATCH}}"
23
- @format = $PREMATCH + "["
24
- set = $POSTMATCH
24
+ if (match_data = /(\d+,)?(\d+)(?=\[)/.match(format))
25
+ qualifier = "{#{match_data[1] || "1,"}#{match_data[2]}}"
26
+ @short_name = match_data.pre_match + "["
27
+ @long_name = match_data.pre_match + match_data.post_match
28
+ set = match_data.post_match
25
29
  elsif format =~ /\[/
26
- qualifier = "+"
27
- @format = $PREMATCH + $MATCH
28
- set = $MATCH + $POSTMATCH
30
+ qualifier = "+"
31
+ @short_name = $PREMATCH + $MATCH
32
+ @long_name = format
33
+ set = $MATCH + $POSTMATCH
29
34
  else
30
35
  fail "Invalid set string #{format}"
31
36
  end
@@ -33,6 +38,13 @@ module FormatEngine
33
38
  @regex = Regexp.new("#{set}#{qualifier}")
34
39
  end
35
40
 
41
+ #Is this format item supported by the engine's library?
42
+ def validate(engine)
43
+ @block = engine[@long_name] || engine[@short_name]
44
+ fail "Unsupported tag = #{@raw.inspect}" unless @block
45
+ true
46
+ end
47
+
36
48
  #Format onto the output string
37
49
  def do_format(spec_info)
38
50
  fail "The tag %{@raw} may not be used in formatting."
@@ -40,16 +52,12 @@ module FormatEngine
40
52
 
41
53
  #Parse from the input string
42
54
  def do_parse(spec_info)
43
- unless (block = spec_info.engine[format])
44
- fail "Unsupported tag = #{format.inspect}"
45
- end
46
-
47
- spec_info.instance_exec(&block)
55
+ spec_info.instance_exec(&@block)
48
56
  end
49
57
 
50
58
  #Inspect for debugging.
51
59
  def inspect
52
- "Set(#{format.inspect}, #{regex.inspect})"
60
+ "Set(#{@long_name.inspect}, #{@short_name.inspect}, #{regex.inspect})"
53
61
  end
54
62
 
55
63
  end
@@ -61,14 +61,21 @@ module FormatEngine
61
61
  has_prec? ? parms[1] : ""
62
62
  end
63
63
 
64
+ #Is this format item supported by the engine's library?
65
+ def validate(engine)
66
+ @block = engine[format]
67
+ fail "Unsupported tag = #{format.inspect}" unless @block
68
+ true
69
+ end
70
+
64
71
  #Format onto the output string
65
72
  def do_format(spec_info)
66
- spec_info.instance_exec(&get_block(spec_info.engine))
73
+ spec_info.instance_exec(&@block)
67
74
  end
68
75
 
69
76
  #Parse from the input string
70
77
  def do_parse(spec_info)
71
- spec_info.instance_exec(&get_block(spec_info.engine))
78
+ spec_info.instance_exec(&@block)
72
79
  end
73
80
 
74
81
  #Inspect for debugging.
@@ -76,14 +83,6 @@ module FormatEngine
76
83
  "Variable(#{format.inspect}, #{parms.inspect})"
77
84
  end
78
85
 
79
- private
80
-
81
- #Get the execution block from the engine.
82
- def get_block(engine)
83
- block = engine[format]
84
- fail "Unsupported tag = #{format.inspect}" unless block
85
- block
86
- end
87
86
  end
88
87
 
89
88
  end
@@ -10,35 +10,28 @@ module FormatEngine
10
10
  class FormatSpec
11
11
  #The regex used to parse variable specifications.
12
12
  REGEX = %r{(?<lead> (^|(?<=[^\\]))%){0}
13
- (?<flags> [~@#$^&*\=?_<>|!]*){0}
14
- (?<parms> [-+]?(\d+(\.\d+)?)?){0}
15
- (?<var> \g<lead>\g<flags>\g<parms>[a-zA-Z]){0}
16
- (?<set> \g<lead>\g<flags>\d*\[([^\]\\]|\\.)+\]){0}
13
+ (?<flags> [~@#$^&*=?_<>|!]*){0}
14
+ (?<var> \g<lead>\g<flags>[-+]?(\d+(\.\d+)?)?[a-zA-Z]){0}
15
+ (?<set> \g<lead>\g<flags>(\d+(,\d+)?)?\[([^\]\\]|\\.)+\]){0}
17
16
  (?<per> \g<lead>%){0}
18
17
  \g<var> | \g<set> | \g<per>
19
18
  }x
20
19
 
21
- #Don't use new, use get_spec instead.
22
- private_class_method :new
23
-
24
- #Either get a format specification from the pool or create one.
25
- def self.get_spec(fmt_string)
26
- @spec_pool ||= {}
27
- @spec_pool[fmt_string] ||= new(fmt_string)
28
- end
29
-
30
20
  #The array of specifications that were extracted.
31
21
  attr_reader :specs
32
22
 
33
23
  #Set up an instance of a format specification.
34
- #<br>Note
35
- #This is a private method (rdoc gets it wrong). To create new instances of
36
- #\FormatSpec do not use \FormatSpec.new, but use \FormatSpec.get_spec instead.
37
24
  def initialize(fmt_string)
38
25
  @specs = []
39
26
  scan_spec(fmt_string)
40
27
  end
41
28
 
29
+ # Validate the specs of this format against the engine.
30
+ def validate(engine)
31
+ specs.each {|item| item.validate(engine)}
32
+ self
33
+ end
34
+
42
35
  #Scan the format string extracting literals and variables.
43
36
  def scan_spec(fmt_string)
44
37
  until fmt_string.empty?
@@ -52,7 +52,7 @@ module FormatEngine
52
52
  head, tail = src, ""
53
53
  end
54
54
 
55
- #Do the parse on the input string.
55
+ #Do the parse on the input string or regex.
56
56
  @prematch, @match, @postmatch = head.partition(target)
57
57
 
58
58
  #Analyze the results.
@@ -1,5 +1,5 @@
1
1
 
2
2
  module FormatEngine
3
3
  # The version of the format_engine gem.
4
- VERSION = "0.5.4"
4
+ VERSION = "0.6.0"
5
5
  end
data/sire.rb CHANGED
@@ -29,6 +29,10 @@ class SIRE
29
29
  #Set up the interactive session.
30
30
  def initialize
31
31
  @_done = false
32
+ @_edit = MiniReadline::Readline.new(history: true,
33
+ auto_complete: true,
34
+ auto_source: MiniReadline::QuotedFileFolderSource,
35
+ eoi_detect: true)
32
36
 
33
37
  puts "Welcome to a Simple Interactive Ruby Environment\n"
34
38
  puts "FormatEngine version = #{FormatEngine::VERSION}"
@@ -69,12 +73,12 @@ class SIRE
69
73
  def run_sire
70
74
  until @_done
71
75
  @_break = false
72
- exec_line(MiniReadline.readline('SIRE>', true))
76
+ exec_line(@_edit.readline(prompt: 'SIRE>'))
73
77
  end
74
78
 
75
79
  puts "\n\n"
76
80
 
77
- rescue Interrupt => e
81
+ rescue MiniReadlineEOI, Interrupt => e
78
82
  puts "\nInterrupted! Program Terminating."
79
83
  end
80
84
 
@@ -9,7 +9,7 @@ class FormatSpecTester < Minitest::Test
9
9
  include MinitestVisible
10
10
 
11
11
  def test_that_it_scans_literal_formats
12
- test = FormatEngine::FormatSpec.get_spec "ABCDEFG!"
12
+ test = FormatEngine::FormatSpec.new "ABCDEFG!"
13
13
  assert_equal(Array, test.specs.class)
14
14
  assert_equal(1, test.specs.length)
15
15
  assert_equal(FormatEngine::FormatLiteral, test.specs[0].class)
@@ -17,7 +17,7 @@ class FormatSpecTester < Minitest::Test
17
17
  end
18
18
 
19
19
  def test_that_backslash_quotes
20
- test = FormatEngine::FormatSpec.get_spec "ABC\\%DEFG!"
20
+ test = FormatEngine::FormatSpec.new "ABC\\%DEFG!"
21
21
  assert_equal(Array, test.specs.class)
22
22
  assert_equal(1, test.specs.length)
23
23
  assert_equal(FormatEngine::FormatLiteral, test.specs[0].class)
@@ -25,7 +25,7 @@ class FormatSpecTester < Minitest::Test
25
25
  end
26
26
 
27
27
  def test_that_it_scans_simple_variable_formats
28
- test = FormatEngine::FormatSpec.get_spec "%A"
28
+ test = FormatEngine::FormatSpec.new "%A"
29
29
  assert_equal(Array, test.specs.class)
30
30
  assert_equal(1, test.specs.length)
31
31
  assert_equal(FormatEngine::FormatVariable, test.specs[0].class)
@@ -34,44 +34,48 @@ class FormatSpecTester < Minitest::Test
34
34
  end
35
35
 
36
36
  def test_that_it_scans_set_formats
37
- test = FormatEngine::FormatSpec.get_spec "%[A]"
37
+ test = FormatEngine::FormatSpec.new "%[A]"
38
38
  assert_equal(Array, test.specs.class)
39
39
  assert_equal(1, test.specs.length)
40
40
  assert_equal(FormatEngine::FormatSet, test.specs[0].class)
41
- assert_equal("%[", test.specs[0].format)
41
+ assert_equal("%[", test.specs[0].short_name)
42
+ assert_equal("%[A]", test.specs[0].long_name)
42
43
  assert_equal(/[A]+/, test.specs[0].regex)
43
44
 
44
- test = FormatEngine::FormatSpec.get_spec "%*[A]"
45
+ test = FormatEngine::FormatSpec.new "%*[A]"
45
46
  assert_equal(Array, test.specs.class)
46
47
  assert_equal(1, test.specs.length)
47
48
  assert_equal(FormatEngine::FormatSet, test.specs[0].class)
48
- assert_equal("%*[", test.specs[0].format)
49
+ assert_equal("%*[", test.specs[0].short_name)
50
+ assert_equal("%*[A]", test.specs[0].long_name)
49
51
  assert_equal(/[A]+/, test.specs[0].regex)
50
52
 
51
- test = FormatEngine::FormatSpec.get_spec "%7[A]"
53
+ test = FormatEngine::FormatSpec.new "%7[A]"
52
54
  assert_equal(Array, test.specs.class)
53
55
  assert_equal(1, test.specs.length)
54
56
  assert_equal(FormatEngine::FormatSet, test.specs[0].class)
55
- assert_equal("%[", test.specs[0].format)
57
+ assert_equal("%[", test.specs[0].short_name)
58
+ assert_equal("%[A]", test.specs[0].long_name)
56
59
  assert_equal(/[A]{1,7}/, test.specs[0].regex)
57
60
 
58
- test = FormatEngine::FormatSpec.get_spec "%*7[A]"
61
+ test = FormatEngine::FormatSpec.new "%*7[A]"
59
62
  assert_equal(Array, test.specs.class)
60
63
  assert_equal(1, test.specs.length)
61
64
  assert_equal(FormatEngine::FormatSet, test.specs[0].class)
62
- assert_equal("%*[", test.specs[0].format)
65
+ assert_equal("%*[", test.specs[0].short_name)
66
+ assert_equal("%*[A]", test.specs[0].long_name)
63
67
  assert_equal(/[A]{1,7}/, test.specs[0].regex)
64
68
  end
65
69
 
66
70
  def test_a_mixed_set
67
- test = FormatEngine::FormatSpec.get_spec "%f %l %[age] %a"
71
+ test = FormatEngine::FormatSpec.new "%f %l %[age] %a"
68
72
  assert_equal(Array, test.specs.class)
69
73
  assert_equal(7, test.specs.length)
70
74
 
71
75
  end
72
76
 
73
77
  def test_that_it_scans_tab_seperators
74
- test = FormatEngine::FormatSpec.get_spec "%A\t%B"
78
+ test = FormatEngine::FormatSpec.new "%A\t%B"
75
79
  assert_equal(Array, test.specs.class)
76
80
  assert_equal(3, test.specs.length)
77
81
 
@@ -89,7 +93,7 @@ class FormatSpecTester < Minitest::Test
89
93
 
90
94
  def test_that_it_scans_option_variable_formats
91
95
  "~@#&^&*-+=?_<>|".each_char do |char|
92
- test = FormatEngine::FormatSpec.get_spec "%#{char}A"
96
+ test = FormatEngine::FormatSpec.new "%#{char}A"
93
97
  assert_equal(Array, test.specs.class)
94
98
  assert_equal(1, test.specs.length)
95
99
  assert_equal(FormatEngine::FormatVariable, test.specs[0].class)
@@ -103,7 +107,7 @@ class FormatSpecTester < Minitest::Test
103
107
  end
104
108
 
105
109
  def test_that_it_scans_single_variable_formats
106
- test = FormatEngine::FormatSpec.get_spec "%123A"
110
+ test = FormatEngine::FormatSpec.new "%123A"
107
111
  assert_equal(Array, test.specs.class)
108
112
  assert_equal(1, test.specs.length)
109
113
  assert_equal(FormatEngine::FormatVariable, test.specs[0].class)
@@ -120,7 +124,7 @@ class FormatSpecTester < Minitest::Test
120
124
  end
121
125
 
122
126
  def test_that_it_scans_double_variable_formats
123
- test = FormatEngine::FormatSpec.get_spec "%123.456A"
127
+ test = FormatEngine::FormatSpec.new "%123.456A"
124
128
  assert_equal(Array, test.specs.class)
125
129
  assert_equal(1, test.specs.length)
126
130
  assert_equal(FormatEngine::FormatVariable, test.specs[0].class)
@@ -138,7 +142,7 @@ class FormatSpecTester < Minitest::Test
138
142
  end
139
143
 
140
144
  def test_negative_variable_formats
141
- test = FormatEngine::FormatSpec.get_spec "%-123.456A"
145
+ test = FormatEngine::FormatSpec.new "%-123.456A"
142
146
  assert_equal(Array, test.specs.class)
143
147
  assert_equal(1, test.specs.length)
144
148
  assert_equal(FormatEngine::FormatVariable, test.specs[0].class)
@@ -156,7 +160,7 @@ class FormatSpecTester < Minitest::Test
156
160
  end
157
161
 
158
162
  def test_multipart_formats
159
- test = FormatEngine::FormatSpec.get_spec "T(%+02A:%3B:%4.1C)"
163
+ test = FormatEngine::FormatSpec.new "T(%+02A:%3B:%4.1C)"
160
164
 
161
165
  assert_equal(Array, test.specs.class)
162
166
  assert_equal(7, test.specs.length)
@@ -190,16 +194,4 @@ class FormatSpecTester < Minitest::Test
190
194
  assert_equal(")", test.specs[6].literal)
191
195
  end
192
196
 
193
- def test_that_it_caches
194
- t1 = FormatEngine::FormatSpec.get_spec "%123.456A"
195
- t2 = FormatEngine::FormatSpec.get_spec "%123.456A"
196
- assert(t1.object_id == t2.object_id)
197
-
198
- t3 = FormatEngine::FormatSpec.get_spec "%123.457A"
199
- assert(t1.object_id != t3.object_id)
200
-
201
- t4 = FormatEngine::FormatSpec.get_spec "%123.457A"
202
- assert(t4.object_id == t3.object_id)
203
- end
204
-
205
197
  end
@@ -0,0 +1,25 @@
1
+ require_relative '../lib/format_engine'
2
+ gem 'minitest'
3
+ require 'minitest/autorun'
4
+ require 'minitest_visible'
5
+
6
+ class SetSpecTester < Minitest::Test
7
+
8
+ #Track mini-test progress.
9
+ include MinitestVisible
10
+
11
+ def test_the_parms
12
+ test = FormatEngine::FormatSet.new("%[ABC]")
13
+ assert_equal(0, test.width)
14
+ assert_equal(/[ABC]+/, test.regex)
15
+
16
+ test = FormatEngine::FormatSet.new("%10[ABC]")
17
+ assert_equal(0, test.width)
18
+ assert_equal(/[ABC]{1,10}/, test.regex)
19
+
20
+ test = FormatEngine::FormatSet.new("%5,10[ABC]")
21
+ assert_equal(0, test.width)
22
+ assert_equal(/[ABC]{5,10}/, test.regex)
23
+
24
+ end
25
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: format_engine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.4
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Camilleri
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-18 00:00:00.000000000 Z
11
+ date: 2016-02-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -119,6 +119,7 @@ files:
119
119
  - tests/literal_spec_tests.rb
120
120
  - tests/parser_engine_tests.rb
121
121
  - tests/scan_tests.rb
122
+ - tests/set_spec_tests.rb
122
123
  - tests/variable_spec_tests.rb
123
124
  homepage: http://teuthida-technologies.com/
124
125
  licenses: