general 1.5.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +166 -20
  3. data/Rakefile +11 -2
  4. data/exp/expected/applied1.txt +1 -0
  5. data/exp/expected/applied2.txt +3 -0
  6. data/exp/expected/applied3.txt +9 -0
  7. data/exp/expected/default1.txt +1 -0
  8. data/exp/expected/default2.txt +3 -0
  9. data/exp/expected/default3.txt +9 -0
  10. data/exp/out/sample1.txt +1 -0
  11. data/exp/out/sample2.txt +3 -0
  12. data/exp/out/sample3.txt +9 -0
  13. data/exp/templates/sample0.general +7 -0
  14. data/exp/templates/sample1.general +1 -0
  15. data/exp/templates/sample2.general +3 -0
  16. data/exp/templates/sample3.general +4 -0
  17. data/exp/templates/sampleE0.general +7 -0
  18. data/exp/templates/sampleE1.general +3 -0
  19. data/exp/templates/sampleE2.general +3 -0
  20. data/exp/templates/sampleE3.general +7 -0
  21. data/lib/general.rb +3 -3
  22. data/lib/gerror.rb +33 -0
  23. data/lib/goperations.rb +95 -27
  24. data/lib/gpartials/garrayplaceholder.rb +87 -0
  25. data/lib/gpartials/gfullplaceholder.rb +63 -0
  26. data/lib/gpartials/gpartial.rb +11 -1
  27. data/lib/gpartials/gplaceholder.rb +1 -52
  28. data/lib/gpartials/gspecial.rb +81 -0
  29. data/lib/gpartials/gtext.rb +5 -33
  30. data/lib/gprepartials/gextend.rb +42 -0
  31. data/lib/gprepartials/ginclude.rb +47 -0
  32. data/lib/gprepartials/gprepartial.rb +45 -0
  33. data/lib/gprepartials/gpretext.rb +33 -0
  34. data/lib/gprepartials/gyield.rb +33 -0
  35. data/lib/{templates → gtemplates}/gbasetemplate.rb +46 -3
  36. data/lib/gtemplates/gio.rb +143 -0
  37. data/lib/gtemplates/gmeta.rb +106 -0
  38. data/lib/{templates → gtemplates}/gtemplate.rb +10 -30
  39. data/lib/{templates → gtemplates}/gtimeformat.rb +6 -12
  40. data/spec/gdothash_spec.rb +6 -10
  41. data/spec/goperations_spec.rb +112 -82
  42. data/spec/gpartial_garrayplaceholder_spec.rb +165 -0
  43. data/spec/gpartial_gfullplaceholder_spec.rb +82 -0
  44. data/spec/gpartial_gplaceholder_spec.rb +237 -0
  45. data/spec/gpartial_gspecial_spec.rb +88 -0
  46. data/spec/gpartial_gtext_spec.rb +87 -0
  47. data/spec/gtamplate_gtemplate_spec.rb +266 -0
  48. data/spec/gtemplate_gio_spec.rb +147 -0
  49. data/spec/gtemplate_gtimeformat_spec.rb +77 -0
  50. data/spec/spec_require.rb +7 -4
  51. metadata +41 -13
  52. data/exp/future.general +0 -11
  53. data/exp/out.txt +0 -1
  54. data/exp/sample.general +0 -1
  55. data/lib/templates/gio.rb +0 -68
  56. data/spec/garrayplaceholder_spec.rb +0 -163
  57. data/spec/gplaceholder_spec.rb +0 -300
  58. data/spec/gtemplates_spec.rb +0 -480
  59. data/spec/gtext_spec.rb +0 -150
@@ -1,480 +0,0 @@
1
- # General is a templating system in ruby
2
- # Copyright (C) 2016 Anshul Kharbanda
3
- #
4
- # This program is free software: you can redistribute it and/or modify
5
- # it under the terms of the GNU General Public License as published by
6
- # the Free Software Foundation, either version 3 of the License, or
7
- # (at your option) any later version.
8
- #
9
- # This program is distributed in the hope that it will be useful,
10
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
- # GNU General Public License for more details.
13
- #
14
- # You should have received a copy of the GNU General Public License
15
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
-
17
- require "spec_require"
18
-
19
- # Describe General Templates
20
- #
21
- # The system of templates in General
22
- #
23
- # Author: Anshul Kharbanda
24
- # Created: 3 - 4 - 2016
25
- describe 'General Templates' do
26
- # Describe General::GTemplate
27
- #
28
- # Implements the general templating system for strings
29
- #
30
- # Author: Anshul Kharbanda
31
- # Created: 3 - 4 - 2016
32
- describe General::GTemplate do
33
- # Before all
34
- before :all do
35
- @template1 = General::GTemplate.new "There once was a man named @(name: Gordon Ramsay). @(name) loved @(food: Cat Food)!"
36
- @template2 = General::GTemplate.new "@(user)@at;@(domain)"
37
- @template3 = General::GTemplate.new "@[greetings] Hello, @(name)! How is the @(pet)? @[\n]"
38
- @template4 = General::GTemplate.new "@(film: The Dark Knight)\nCrew:\n@[crew] \t@(name): @(role) @[\n]\nScore: @(score)/10"
39
- @template5 = General::GTemplate.new "There once was a dog named @(name: dog -> capitalize). @(name -> capitalize) earned @(amount -> money) last week."
40
- @template6 = General::GTemplate.new "There once was a cat named @(name -> capitalize all)."
41
- @template7 = General::GTemplate.new "The time is @(time -> time)"
42
- @template8 = General::GTemplate.new "The time is @(time -> time '@SS <- @MM <- @HH')"
43
- @template9 = General::GTemplate.new "The name's @(name.last)... @(name.first) @(name.last)."
44
- end
45
-
46
- # Describe General::GTemplate::new
47
- #
48
- # Creates a GTemplate with the given template string
49
- #
50
- # Parameter: string - the string being converted to a template
51
- describe "::new" do
52
- it "creates a new GTemplate with the given template string" do
53
- [@template1, @template2, @template3,
54
- @template4, @template5, @template6,
55
- @template7, @template8, @template9]
56
- .each do |template|
57
- expect(template).to be_an_instance_of General::GTemplate
58
- end
59
- end
60
- end
61
-
62
- # Describe General::GTemplate#apply
63
- #
64
- # Applies the given data to the template and returns the generated string
65
- #
66
- # Parameter: data - the data to be applied (as a hash. merges with defaults)
67
- #
68
- # Return: string of the template with the given data applied
69
- describe "#apply" do
70
- # ------------------------------------BASIC PLACEHOLDER------------------------------------
71
-
72
- # Test basic @(name: default) placeholder
73
- context 'with a general template' do
74
- # --------------------------------DATA--------------------------------
75
-
76
- before :all do
77
- @data1 = {name: "Joe", food: "Joe's Shmoes"}
78
- @name = "Dog"
79
- @food = "Denny's Fennies"
80
-
81
- @default_text = "There once was a man named Gordon Ramsay. Gordon Ramsay loved Cat Food!"
82
- @name_text = "There once was a man named Dog. Dog loved Cat Food!"
83
- @food_text = "There once was a man named Gordon Ramsay. Gordon Ramsay loved Denny's Fennies!"
84
- @all_text = "There once was a man named Joe. Joe loved Joe's Shmoes!"
85
- end
86
-
87
- # --------------------------------TEST--------------------------------
88
-
89
- context "with no data" do
90
- it "returns the template with the default data applied" do
91
- expect(@template1.apply).to eql @default_text
92
- end
93
- end
94
-
95
- context "with partial data" do
96
- it "returns the template with the given data applied to corresponding placeholders and default data applied to the rest" do
97
- expect(@template1.apply name: @name).to eql @name_text
98
- expect(@template1.apply food: @food).to eql @food_text
99
- end
100
- end
101
-
102
- context "with all data" do
103
- it "returns the template with the given data applied" do
104
- expect(@template1.apply @data1).to eql @all_text
105
- end
106
- end
107
- end
108
-
109
- # ------------------------------------SPECIAL CHARACTERS------------------------------------
110
-
111
- # Test special characters
112
- context 'with general special characters' do
113
- # --------------------------------DATA--------------------------------
114
-
115
- before :all do
116
- @data2 = { user: "hillary", domain: "clinton.org" }
117
- @text2 = "hillary@clinton.org"
118
- end
119
-
120
- # --------------------------------TEST--------------------------------
121
-
122
- it 'returns the templae with the given data applied (including the @ character)' do
123
- expect(@template2.apply @data2).to eql @text2
124
- end
125
- end
126
-
127
- # ------------------------------------ARRAY TEMPLATE------------------------------------
128
-
129
- # Test array template
130
- context "with array template" do
131
- # --------------------------------DATA--------------------------------
132
- before :all do
133
- @data3 = {
134
- greetings: [
135
- {name: "Ben", pet: "dog"},
136
- {name: "Jen", pet: "cat"},
137
- {name: "Ken", pet: "plant"}
138
- ]
139
- }
140
- @text3 = "Hello, Ben! How is the dog?\nHello, Jen! How is the cat?\nHello, Ken! How is the plant?"
141
-
142
- @data4 = {
143
- film: 'Batman Begins',
144
- crew: [
145
- {name: 'David S. Goyer', role: 'Writer'},
146
- {name: 'Chris Nolan', role: 'Director'},
147
- {name: 'Wally Pfister', role: 'Director of Photography'},
148
- {name: 'Michael Caine', role: 'Alfred Pennyworth'},
149
- {name: 'Christian Bale', role: 'Bruce Wayne/Batman'}
150
- ],
151
- score: 10
152
- }
153
- @text4 = "Batman Begins\nCrew:\n\tDavid S. Goyer: Writer\n\tChris Nolan: Director\n\tWally Pfister: Director of Photography" \
154
- "\n\tMichael Caine: Alfred Pennyworth\n\tChristian Bale: Bruce Wayne/Batman\nScore: 10/10"
155
- end
156
-
157
- # --------------------------------TEST--------------------------------
158
-
159
- context 'with no placeholder' do
160
- it "returns the template with the given array data applied and formatted according to the template" do
161
- expect(@template3.apply @data3).to eql @text3
162
- end
163
- end
164
-
165
- context 'with regular placeholder' do
166
- it "returns the template with the given data applied (including array data) and formatted according to the template" do
167
- expect(@template4.apply @data4).to eql @text4
168
- end
169
- end
170
- end
171
-
172
- # ------------------------------------OPERATIONS------------------------------------
173
-
174
- context "with placeholder operation" do
175
- # --------------------------------DATA--------------------------------
176
-
177
- before :all do
178
- @data5 = {name: "cat", amount: 19999}
179
- @text5 = "There once was a dog named Cat. Cat earned $199.99 last week."
180
-
181
- @data6 = {name: "joe schmoe"}
182
- @text6 = "There once was a cat named Joe Schmoe."
183
-
184
- hrs = 3
185
- min = 14
186
- sec = 12
187
- pm = true
188
-
189
- @data78 = {
190
- time: ( ((pm ? 11 : 0) + hrs)*3600 + min*60 + sec )
191
- }
192
-
193
- @text7 = "The time is #{hrs}:#{min.to_s.rjust(2,'0')}:#{sec.to_s.rjust(2,'0')} #{pm ? 'PM' : 'AM'}"
194
- @text8 = "The time is #{sec.to_s.rjust(2,'0')} <- #{min.to_s.rjust(2,'0')} <- #{((pm ? 11 : 0) + hrs).to_s.rjust(2,'0')}"
195
- end
196
-
197
- # --------------------------------TEST--------------------------------
198
-
199
- context 'with no arguments' do
200
- it "returns the template with the given data applied and formatted according to the format operations" do
201
- expect(@template5.apply @data5).to eql @text5
202
- expect(@template7.apply @data78).to eql @text7
203
- end
204
- end
205
-
206
- context 'with arguments' do
207
- it 'returns the template with the given data applied and formatted according to the format operations and arguments' do
208
- expect(@template6.apply @data6).to eql @text6
209
- expect(@template8.apply @data78).to eql @text8
210
- end
211
- end
212
- end
213
-
214
- # ------------------------------------DOT NOTATION------------------------------------
215
-
216
- context "with dot notation" do
217
- # --------------------------------DATA--------------------------------
218
-
219
- before :all do
220
- @data9 = General::GDotHash.new name: {first: "Gordon", last: "Ramsay"}
221
- @text9 = "The name's Ramsay... Gordon Ramsay."
222
- end
223
-
224
- # --------------------------------TEST--------------------------------
225
-
226
- it "returns the template with the given data applied appropriately" do
227
- expect(@template9.apply @data9).to eql @text9
228
- end
229
- end
230
- end
231
-
232
- # Describe General::GTemplate#apply_all
233
- #
234
- # Applies each data structure in the array independently to the template
235
- # and returns an array of the generated strings
236
- #
237
- # Parameter: array - the array of data to be applied
238
- # (each data hash will be merged with defaults)
239
- #
240
- # Return: array of strings generated from the template with the given
241
- # data applied
242
- describe '#apply_all' do
243
- before :all do
244
- @data5 = [
245
- {name: "Joe", food: "Joe's Schmoes"},
246
- {name: "Jane", food: "Jane's Danes"},
247
- {name: "Denny", food: "Denny's Fennies"}
248
- ]
249
-
250
- @text5 = [
251
- "There once was a man named Joe. Joe loved Joe's Schmoes!",
252
- "There once was a man named Jane. Jane loved Jane's Danes!",
253
- "There once was a man named Denny. Denny loved Denny's Fennies!"
254
- ]
255
- end
256
-
257
- it 'applies all the values in the data array individually' do
258
- expect(@template1.apply_all @data5).to eql @text5
259
- end
260
- end
261
-
262
- # Describe General::GTemplate#regex
263
- #
264
- # Returns the string as a regex
265
- #
266
- # Parameter: sub - true if the template is part of array template
267
- #
268
- # Returns: the string as a regex
269
- describe '#regex' do
270
- before :all do
271
- @regex1 = /\AThere once was a man named (?<name>.*)\. \k<name> loved (?<food>.*)!\z/
272
- @sub_regex1 = "There once was a man named (?<name>.*)\\. \\k<name> loved (?<food>.*)!"
273
- end
274
-
275
- context 'if template is not part of array template' do
276
- it 'returns the regex created from the GTemplate' do
277
- expect(@template1.regex).to eql @regex1
278
- end
279
- end
280
-
281
- context 'if template is part of array template' do
282
- it 'returns the sub regex string created from the GTemplate' do
283
- expect(@template1.regex true).to eql @sub_regex1
284
- end
285
- end
286
- end
287
-
288
- # Describe General::GTemplate#match
289
- #
290
- # Matches the given string against the template and returns the
291
- # collected information. Returns nil if the given string does
292
- # not match.
293
- #
294
- # If a block is given, it will be run with the generated hash
295
- # if the string matches. Alias for:
296
- #
297
- # if m = template.match(string)
298
- # # Run block
299
- # end
300
- #
301
- # Parameter: string the string to match
302
- #
303
- # Return: Information matched from the string or nil
304
- describe '#match' do
305
- context 'when the given string matches the template regex' do
306
- it 'returns the data generated from the string' do
307
- expect(@template1.match @all_text).to eql @data1
308
- end
309
- end
310
-
311
- context 'when the given string does not match the template regex' do
312
- it 'returns nil' do
313
- expect(@template1.match "").to be_nil
314
- end
315
- end
316
-
317
- context 'with a block given' do
318
- it 'passes the hash to the given block' do
319
- expect {
320
- @template1.match @all_text do |hash|
321
- expect(hash).to eql @data1
322
- end
323
- }.not_to raise_error
324
- end
325
- end
326
- end
327
- end
328
-
329
- # Describe General::GIO
330
- #
331
- # Implements the general IO writer template
332
- #
333
- # Author: Anshul Kharbanda
334
- # Created: 3 - 4 - 2016
335
- describe General::GIO do
336
- before :all do
337
- @gio = General::GIO.load("exp/sample" + General::GIO::EXTENSION)
338
- @out = "exp/out.txt"
339
- @phony = 3
340
- @default_data = {place: "virginia"}
341
- @applied_data = {name: "joe", food: "Joe's Schmoes", place: "kentucky"}
342
- @default_text = "There once was a chef name Gordon Ramsay, and he loved eating carrots. He went to Virginia."
343
- @applied_text = "There once was a chef name Joe, and he loved eating Joe's Schmoes. He went to Kentucky."
344
- end
345
-
346
- # Describe General::GIO::load
347
- #
348
- # Loads a GIO from a file with the given path
349
- #
350
- # Parameter: path - the path of the file to load
351
- #
352
- # Return: GIO loaded from the file
353
- describe "::load" do
354
- it "creates a new GIO with the given template string" do
355
- expect(@gio).to be_an_instance_of General::GIO
356
- end
357
- end
358
-
359
- # Describe General::GIO#write
360
- #
361
- # Writes the template with the given data applied to the target stream
362
- #
363
- # Parameter: ios - if String, is the name of the file to write to
364
- # if IO, is the stream to write to
365
- # Parameter: data - the data to be applied (merges with defaults)
366
- describe "#write" do
367
- # -------------------------------------------DEFAULT-------------------------------------------
368
-
369
- context "with target and default data" do
370
- context 'if target is string' do
371
- it "writes the default data to the file with the given filename (the target string)" do
372
- @gio.write @out, @default_data
373
- expect(IO.read(@out)).to eql @default_text
374
- end
375
- end
376
-
377
- context 'if target is io' do
378
- it "writes the default data to the target io" do
379
- File.open(@out, "w+") { |ios| @gio.write ios, @default_data }
380
- expect(IO.read(@out)).to eql @default_text
381
- end
382
- end
383
-
384
- context 'if target is not string or io' do
385
- it "raises TypeError" do
386
- expect{ @gio.write @phony, @default_data }.to raise_error TypeError
387
- end
388
- end
389
- end
390
-
391
- # --------------------------------------------DATA---------------------------------------------
392
-
393
- context "with target and given data" do
394
- context 'if target is string' do
395
- it "writes the given data to the file with the given filename (the target string)" do
396
- @gio.write @out, @applied_data
397
- expect(IO.read(@out)).to eql @applied_text
398
- end
399
- end
400
-
401
- context 'if target is io' do
402
- it "writes the given data to the target io" do
403
- File.open(@out, "w+") { |ios| @gio.write ios, @applied_data }
404
- expect(IO.read(@out)).to eql @applied_text
405
- end
406
- end
407
-
408
- context 'if target is not string or io' do
409
- it "raises TypeError" do
410
- expect{ @gio.write @phony, @applied_data }.to raise_error TypeError
411
- end
412
- end
413
- end
414
- end
415
- end
416
-
417
- # Describe General::GTimeFormat
418
- #
419
- # A special template used for formatting time strings
420
- #
421
- # Author: Anshul Kharbanda
422
- # Created: 7 - 2 - 2016
423
- describe General::GTimeFormat do
424
- before :all do
425
- # Time value
426
- @time = (11 + 3)*3600 + 42*60 + 9
427
-
428
- # Phony value
429
- @phony = {data: "Time, Yo!"}
430
-
431
- # Formats
432
- @format1 = General::GTimeFormat.new "@HH:@MM:@SS"
433
- @format2 = General::GTimeFormat.new "@I:@MM:@S @A"
434
- @format3 = General::GTimeFormat.new "@SS - @M - @H (@I @A)"
435
-
436
- # Applied values
437
- @applied1 = "14:42:09"
438
- @applied2 = "3:42:9 PM"
439
- @applied3 = "09 - 42 - 14 (3 PM)"
440
- end
441
-
442
- # Describe General::GTimeFormat::new
443
- #
444
- # Creates the GTimeFormat with the given string
445
- #
446
- # Parameter: string - the template string
447
- describe "::new" do
448
- it "creates a new GTimeFormat with the given format string" do
449
- expect(@format1).to be_an_instance_of General::GTimeFormat
450
- expect(@format2).to be_an_instance_of General::GTimeFormat
451
- expect(@format3).to be_an_instance_of General::GTimeFormat
452
- end
453
- end
454
-
455
- # Describe General::GTimeFormat#apply
456
- #
457
- # Applies the given integer value to the template and returns the generated string
458
- #
459
- # Parameter: value - the value to be applied (as a hash. merges with defaults)
460
- #
461
- # Return: string of the template with the given value applied
462
- describe "#apply" do
463
- context "with integer time value given" do
464
- it "returns the given value formatted according to the time format" do
465
- expect(@format1.apply(@time)).to eql @applied1
466
- expect(@format2.apply(@time)).to eql @applied2
467
- expect(@format3.apply(@time)).to eql @applied3
468
- end
469
- end
470
-
471
- context "if value given is not integer" do
472
- it "raises TypeError" do
473
- expect{ @format1.apply(@phony) }.to raise_error TypeError
474
- expect{ @format2.apply(@phony) }.to raise_error TypeError
475
- expect{ @format3.apply(@phony) }.to raise_error TypeError
476
- end
477
- end
478
- end
479
- end
480
- end
data/spec/gtext_spec.rb DELETED
@@ -1,150 +0,0 @@
1
- # General is a templating system in ruby
2
- # Copyright (C) 2016 Anshul Kharbanda
3
- #
4
- # This program is free software: you can redistribute it and/or modify
5
- # it under the terms of the GNU General Public License as published by
6
- # the Free Software Foundation, either version 3 of the License, or
7
- # (at your option) any later version.
8
- #
9
- # This program is distributed in the hope that it will be useful,
10
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
- # GNU General Public License for more details.
13
- #
14
- # You should have received a copy of the GNU General Public License
15
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
-
17
- require_relative "spec_require"
18
-
19
- # Describe General Text Partials
20
- #
21
- # Regular text parts of a General Template
22
- #
23
- # Author: Anshul Kharbanda
24
- # Created: 7 - 29 - 2016
25
- describe 'General Text Partials' do
26
- # Describe General::GText
27
- #
28
- # Represents a plain text partial in a GTemplate
29
- #
30
- # Author: Anshul Kharbanda
31
- # Created: 7 - 1 - 2016
32
- describe General::GText do
33
- before :all do
34
- @text = "foobar"
35
- @regex = "foobar"
36
- @partial = General::GText.new @text
37
- end
38
-
39
- # Describe General::GText::new
40
- #
41
- # Creates the GText with the given match
42
- #
43
- # Parameter: match - the match object of the GText
44
- describe '::new' do
45
- it 'creates the GText with the given to_s representable object' do
46
- expect(@partial).to be_an_instance_of General::GText
47
- expect(@partial.name).to eql General::GText::PTNAME
48
- expect(@partial.instance_variable_get :@text).to eql @text
49
- end
50
- end
51
-
52
- # Describe General::GText#apply
53
- #
54
- # Returns the text
55
- #
56
- # Parameter: data - the data to apply to the partial
57
- #
58
- # Returns: the text
59
- describe '#apply' do
60
- it 'returns the GText string, given a hash of data' do
61
- expect(@partial.apply @hash).to eql @text
62
- end
63
- end
64
-
65
- # Describe General::GText#string
66
- #
67
- # Returns the text as a string
68
- #
69
- # Parameter: first - true if this partial is the first of it's kind in a GTemplate
70
- #
71
- # Returns: the text as a string
72
- describe '#string' do
73
- context 'with no first argument given' do
74
- it 'returns the string' do
75
- expect(@partial.string).to eql @text
76
- end
77
- end
78
-
79
- context 'with first argument given' do
80
- context 'if first argument is true' do
81
- it 'returns the string' do
82
- expect(@partial.string true).to eql @text
83
- end
84
- end
85
-
86
- context 'if first argument is false' do
87
- it 'returns the string' do
88
- expect(@partial.string false).to eql @text
89
- end
90
- end
91
- end
92
- end
93
-
94
- # Describe General::GText#regex
95
- #
96
- # Returns the text as a regex
97
- #
98
- # Parameter: first - true if this partial is the first of it's kind in a GTemplate
99
- #
100
- # Returns: the text as a regex
101
- describe '#regex' do
102
- context 'with no first argument given' do
103
- it 'returns the regex' do
104
- expect(@partial.regex).to eql @regex
105
- end
106
- end
107
-
108
- context 'with first argument given' do
109
- context 'if first argument is true' do
110
- it 'returns the regex' do
111
- expect(@partial.regex true).to eql @regex
112
- end
113
- end
114
-
115
- context 'if first argument is false' do
116
- it 'returns the regex' do
117
- expect(@partial.regex false).to eql @regex
118
- end
119
- end
120
- end
121
- end
122
- end
123
-
124
- # Describe General::GSpecial
125
- #
126
- # Represents a special character in a GTemplate
127
- #
128
- # Author: Anshul Kharbanda
129
- # Created: 7 - 1 - 2016
130
- describe General::GSpecial do
131
- before :all do
132
- @text = "@"
133
- @regex = "@"
134
- @partial = General::GSpecial.new key: "at"
135
- end
136
-
137
- # Describe General::GSpecial::new
138
- #
139
- # Creates the GSpecial with the given match
140
- #
141
- # Parameter: match - the match object of the GSpecial
142
- describe '::new' do
143
- it 'creates the GSpecial with the given match object' do
144
- expect(@partial).to be_an_instance_of General::GSpecial
145
- expect(@partial.name).to eql General::GSpecial::PTNAME
146
- expect(@partial.instance_variable_get :@text).to eql @text
147
- end
148
- end
149
- end
150
- end