rufus-dollar 1.0 → 1.0.1

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.
data/CHANGELOG.txt CHANGED
@@ -2,5 +2,10 @@
2
2
  = rufus-dollar CHANGELOG.txt
3
3
 
4
4
 
5
+ == rufus-dollar - 1.0.1 released 2008/02/19
6
+
7
+ - bug #18161 : problem with nested simple {} (not ${}). Fixed - s179
8
+
9
+
5
10
  == rufus-dollar - 1.0 released 2008/01/24
6
11
 
data/README.txt CHANGED
@@ -1,7 +1,7 @@
1
1
 
2
2
  = rufus-dollar
3
3
 
4
- A one-method library for substituting ${stuff} in text strings
4
+ A one-method library for substituting ${stuff} in text strings.
5
5
 
6
6
 
7
7
  == getting it
@@ -19,12 +19,19 @@ http://rubyforge.org/frs/?group_id=4812
19
19
  require 'rufus/dollar'
20
20
 
21
21
  h = {
22
- "name" => "Fred Brooke",
23
- "title" => "Silver Bullet"
22
+ "name" => "Fred Brooks",
23
+ "title" => "Silver Bullet",
24
+ "left" => "na",
25
+ "right" => "me",
24
26
  }
25
27
 
26
28
  puts Rufus::dsub "${name} wrote '${title}'", h
27
- # => "Fred Brooke wrote 'Silver Bullet'"
29
+ # => "Fred Brooks wrote 'Silver Bullet'"
30
+
31
+ # dollar notations are nestable
32
+
33
+ puts Rufus::dsub "${${left}${right}}", h
34
+ # => "${name}" => "Fred Brooks"
28
35
 
29
36
 
30
37
  == dependencies
data/lib/rufus/dollar.rb CHANGED
@@ -28,6 +28,7 @@
28
28
  # John Mettraux at openwfe.org
29
29
  #
30
30
 
31
+
31
32
  module Rufus
32
33
 
33
34
  #
@@ -45,16 +46,14 @@ module Rufus
45
46
  # puts Rufus::dsub "${name} wrote '${title}'", h
46
47
  # # => "Fred Brooke wrote 'Silver Bullet'"
47
48
  #
48
- def Rufus.dsub (text, dict)
49
+ def self.dsub (text, dict, offset=nil)
49
50
 
50
51
  text = text.to_s
51
52
 
52
- #puts "### text is >#{text}<"
53
+ #puts "### text is >#{text}<"
53
54
  #puts "### dict is of class #{dict.class.name}"
54
55
 
55
- #return nil unless text
56
-
57
- j = text.index("}")
56
+ j = text.index("}", offset || 0)
58
57
 
59
58
  return text if not j
60
59
 
@@ -63,15 +62,21 @@ module Rufus
63
62
  i = t.rindex("${")
64
63
  ii = t.rindex("\\${")
65
64
 
65
+ iii = t.rindex("{")
66
+ iii = nil if offset
67
+
66
68
  #puts "i is #{i}"
69
+ #puts "j is #{j}"
67
70
  #puts "ii is #{ii}"
71
+ #puts "iii is #{iii}"
68
72
 
69
- return text if not i
73
+ return text if (not i)
74
+ return dsub(text, dict, j+1) if (iii) and (iii-1 > i)
70
75
 
71
76
  return unescape(text) if (i) and (i != 0) and (ii == i-1)
72
77
  #
73
78
  # found "\${"
74
-
79
+
75
80
  key = text[i+2..j-1]
76
81
 
77
82
  #puts "### key is '#{key}'"
@@ -92,8 +97,8 @@ module Rufus
92
97
 
93
98
  #puts "### value 1 is '#{value}'"
94
99
 
95
- #puts "pre is >#{text[0..i-1]}<"
96
- #puts "post is >#{text[j+1..-1]}<"
100
+ #puts "### pre is >#{text[0..i-1]}<"
101
+ #puts "### post is >#{text[j+1..-1]}<"
97
102
 
98
103
  pre = if i > 0
99
104
  text[0..i-1]
@@ -101,7 +106,7 @@ module Rufus
101
106
  ""
102
107
  end
103
108
 
104
- dsub("#{pre}#{value}#{text[j+1..-1]}", dict)
109
+ dsub "#{pre}#{value}#{text[j+1..-1]}", dict
105
110
  end
106
111
 
107
112
  private
@@ -0,0 +1,84 @@
1
+
2
+ #
3
+ # Testing rufus-dollar
4
+ #
5
+ # John Mettraux at openwfe.org
6
+ #
7
+ # Mon Oct 9 22:19:44 JST 2006
8
+ #
9
+
10
+ require 'test/unit'
11
+ require 'rufus/dollar'
12
+ require 'test_base'
13
+
14
+ #
15
+ # testing the 'dollar notation'
16
+ #
17
+
18
+ class DollarTest < Test::Unit::TestCase
19
+ include TestBase
20
+
21
+ #def setup
22
+ #end
23
+
24
+ #def teardown
25
+ #end
26
+
27
+ def test_0
28
+
29
+ dict = {}
30
+
31
+ dict['renard'] = 'goupil'
32
+ dict['cane'] = 'oie'
33
+ dict['oie blanche'] = 'poule'
34
+
35
+ dotest "le petit renard", dict, "le petit renard"
36
+ dotest "le petit {renard}", dict, "le petit {renard}"
37
+ dotest "le petit ${renard}", dict, "le petit goupil"
38
+ dotest "le petit ${renard} noir", dict, "le petit goupil noir"
39
+
40
+ dotest "la grande ${${cane} blanche}", dict, "la grande poule"
41
+
42
+ dotest "le ${renard} et la ${cane}", dict, "le goupil et la oie"
43
+ #
44
+ # excuse my french...
45
+
46
+ dotest "le \\${renard} encore", dict, "le \\${renard} encore"
47
+
48
+ dotest "", dict, ""
49
+
50
+ dotest("""
51
+ """, dict, """
52
+ """)
53
+ dotest("""
54
+ """, dict, """
55
+ """)
56
+ end
57
+
58
+ def test_1
59
+
60
+ dict = {}
61
+ dict['x'] = 'y'
62
+
63
+ dotest "${x}", dict, "y"
64
+ dotest "\\${x}", dict, "\\${x}"
65
+ end
66
+
67
+ def test_2
68
+
69
+ dict = {}
70
+ dict['A'] = 'a'
71
+ dict['B'] = 'b'
72
+ dict['ab'] = 'ok'
73
+
74
+ dotest "${${A}${B}}", dict, "ok"
75
+ end
76
+
77
+ #def test_3
78
+ # assert_equal OpenWFE.unescape("toto and ${toto}"), "toto and ${toto}"
79
+ # assert_equal OpenWFE.unescape("toto & \${toto}"), "toto & ${toto}"
80
+ # assert_equal "toto & \\${toto}", "toto & ${toto}"
81
+ # #assert_equal OpenWFE.unescape('toto & \${toto}'), "toto & ${toto}"
82
+ #end
83
+
84
+ end
@@ -0,0 +1,31 @@
1
+
2
+ #
3
+ # Testing rufus-dollar
4
+ #
5
+ # John Mettraux at openwfe.org
6
+ #
7
+ # Mon Feb 18 23:32:12 JST 2008
8
+ #
9
+
10
+ require 'test/unit'
11
+ require 'rufus/dollar'
12
+ require 'test_base'
13
+
14
+ class NestedTest < Test::Unit::TestCase
15
+ include TestBase
16
+
17
+ #def setup
18
+ #end
19
+
20
+ #def teardown
21
+ #end
22
+
23
+ def test_0
24
+
25
+ dotest " ${a${b}e} ", {}, " "
26
+ dotest " ${a{b}e} ", {}, " "
27
+ dotest "${a{b}e}", {}, ""
28
+ dotest " \\${a{b}e} ", {}, " \\${a{b}e} "
29
+ dotest "{a${b}c}", { "b" => 2 }, "{a2c}"
30
+ end
31
+ end
data/test/test.rb CHANGED
@@ -1,91 +1,4 @@
1
1
 
2
- #
3
- # Testing rufus-dollar
4
- #
5
- # John Mettraux at openwfe.org
6
- #
7
- # Mon Oct 9 22:19:44 JST 2006
8
- #
2
+ require 'test/dollar_test'
3
+ require 'test/nested_test'
9
4
 
10
- require 'test/unit'
11
- require 'rufus/dollar'
12
-
13
- #
14
- # testing the 'dollar notation'
15
- #
16
-
17
- class DollarTest < Test::Unit::TestCase
18
-
19
- #def setup
20
- #end
21
-
22
- #def teardown
23
- #end
24
-
25
- def test_0
26
-
27
- dict = {}
28
-
29
- dict['renard'] = 'goupil'
30
- dict['cane'] = 'oie'
31
- dict['oie blanche'] = 'poule'
32
-
33
- dotest("le petit renard", dict, "le petit renard")
34
- dotest("le petit {renard}", dict, "le petit {renard}")
35
- dotest("le petit ${renard}", dict, "le petit goupil")
36
- dotest("le petit ${renard} noir", dict, "le petit goupil noir")
37
-
38
- dotest("la grande ${${cane} blanche}", dict, "la grande poule")
39
-
40
- dotest("le ${renard} et la ${cane}", dict, "le goupil et la oie")
41
- #
42
- # excuse my french...
43
-
44
- dotest("le \\${renard} encore", dict, "le \\${renard} encore")
45
-
46
- dotest("", dict, "")
47
-
48
- dotest("""
49
- """, dict, """
50
- """)
51
- dotest("""
52
- """, dict, """
53
- """)
54
- end
55
-
56
- def test_1
57
-
58
- dict = {}
59
- dict['x'] = 'y'
60
-
61
- dotest("${x}", dict, "y")
62
- dotest("\\${x}", dict, "\\${x}")
63
- end
64
-
65
- def test_2
66
-
67
- dict = {}
68
- dict['A'] = 'a'
69
- dict['B'] = 'b'
70
- dict['ab'] = 'ok'
71
-
72
- dotest("${${A}${B}}", dict, "ok")
73
- end
74
-
75
- #def test_3
76
- # assert_equal OpenWFE.unescape("toto and ${toto}"), "toto and ${toto}"
77
- # assert_equal OpenWFE.unescape("toto & \${toto}"), "toto & ${toto}"
78
- # assert_equal "toto & \\${toto}", "toto & ${toto}"
79
- # #assert_equal OpenWFE.unescape('toto & \${toto}'), "toto & ${toto}"
80
- #end
81
-
82
- def dotest (text, dict, target)
83
-
84
- result = Rufus::dsub(text, dict)
85
- #puts "..>#{text}<"
86
- #puts "...->"
87
- #puts "..>#{result}<"
88
- #puts
89
- assert_equal result, target
90
- end
91
- end
data/test/test_base.rb ADDED
@@ -0,0 +1,20 @@
1
+
2
+ #
3
+ # Testing rufus-dollar
4
+ #
5
+ # John Mettraux at openwfe.org
6
+ #
7
+ # Mon Feb 18 23:30:37 JST 2008
8
+ #
9
+
10
+ module TestBase
11
+
12
+ protected
13
+
14
+ def dotest (text, dict, target)
15
+
16
+ result = Rufus::dsub text, dict
17
+
18
+ assert_equal target, result
19
+ end
20
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rufus-dollar
3
3
  version: !ruby/object:Gem::Version
4
- version: "1.0"
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Mettraux
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-01-24 00:00:00 +09:00
12
+ date: 2008-02-19 00:00:00 +09:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -26,7 +26,10 @@ extra_rdoc_files:
26
26
  files:
27
27
  - lib/rufus
28
28
  - lib/rufus/dollar.rb
29
+ - test/dollar_test.rb
30
+ - test/nested_test.rb
29
31
  - test/test.rb
32
+ - test/test_base.rb
30
33
  - README.txt
31
34
  - CHANGELOG.txt
32
35
  - LICENSE.txt