rufus-dollar 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.txt +6 -0
- data/LICENSE.txt +1 -1
- data/README.txt +6 -1
- data/Rakefile +85 -0
- data/lib/rufus/dollar.rb +64 -48
- data/rufus-dollar.gemspec +31 -0
- data/spec/dollar_spec.rb +118 -0
- data/spec/spec_base.rb +15 -0
- data/spec/support/dollar_helper.rb +9 -0
- metadata +69 -36
- data/test/dollar_test.rb +0 -80
- data/test/nested_test.rb +0 -30
- data/test/test.rb +0 -4
- data/test/test_base.rb +0 -27
data/CHANGELOG.txt
CHANGED
data/LICENSE.txt
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
|
2
|
-
Copyright (c) 2006-
|
2
|
+
Copyright (c) 2006-2011, John Mettraux, jmettraux@gmail.com
|
3
3
|
|
4
4
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
5
|
of this software and associated documentation files (the "Software"), to deal
|
data/README.txt
CHANGED
@@ -6,7 +6,7 @@ A one-method library for substituting ${stuff} in text strings.
|
|
6
6
|
|
7
7
|
== getting it
|
8
8
|
|
9
|
-
|
9
|
+
gem install rufus-dollar
|
10
10
|
|
11
11
|
or at
|
12
12
|
|
@@ -33,6 +33,11 @@ http://rubyforge.org/frs/?group_id=4812
|
|
33
33
|
puts Rufus::dsub "${${left}${right}}", h
|
34
34
|
# => "${name}" => "Fred Brooks"
|
35
35
|
|
36
|
+
# prefixing the key with a ' or a " makes it quotable
|
37
|
+
|
38
|
+
puts Rufus::dsub "${name} wrote ${'title}", h
|
39
|
+
# => 'Fred Brooks wrote "Silver Bullet"'
|
40
|
+
|
36
41
|
|
37
42
|
== dependencies
|
38
43
|
|
data/Rakefile
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
|
2
|
+
$:.unshift('.') # 1.9.2
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
|
6
|
+
require 'rake'
|
7
|
+
require 'rake/clean'
|
8
|
+
require 'rake/rdoctask'
|
9
|
+
|
10
|
+
|
11
|
+
#
|
12
|
+
# clean
|
13
|
+
|
14
|
+
CLEAN.include('pkg', 'rdoc')
|
15
|
+
|
16
|
+
|
17
|
+
#
|
18
|
+
# test / spec
|
19
|
+
|
20
|
+
#task :spec => :check_dependencies do
|
21
|
+
task :spec do
|
22
|
+
sh 'rspec spec/'
|
23
|
+
end
|
24
|
+
task :test => :spec
|
25
|
+
|
26
|
+
task :default => :spec
|
27
|
+
|
28
|
+
|
29
|
+
#
|
30
|
+
# gem
|
31
|
+
|
32
|
+
GEMSPEC_FILE = Dir['*.gemspec'].first
|
33
|
+
GEMSPEC = eval(File.read(GEMSPEC_FILE))
|
34
|
+
GEMSPEC.validate
|
35
|
+
|
36
|
+
|
37
|
+
desc %{
|
38
|
+
builds the gem and places it in pkg/
|
39
|
+
}
|
40
|
+
task :build do
|
41
|
+
|
42
|
+
sh "gem build #{GEMSPEC_FILE}"
|
43
|
+
sh "mkdir pkg" rescue nil
|
44
|
+
sh "mv #{GEMSPEC.name}-#{GEMSPEC.version}.gem pkg/"
|
45
|
+
end
|
46
|
+
|
47
|
+
desc %{
|
48
|
+
builds the gem and pushes it to rubygems.org
|
49
|
+
}
|
50
|
+
task :push => :build do
|
51
|
+
|
52
|
+
sh "gem push pkg/#{GEMSPEC.name}-#{GEMSPEC.version}.gem"
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
#
|
57
|
+
# rdoc
|
58
|
+
#
|
59
|
+
# make sure to have rdoc 2.5.x to run that
|
60
|
+
|
61
|
+
Rake::RDocTask.new do |rd|
|
62
|
+
|
63
|
+
rd.main = 'README.txt'
|
64
|
+
rd.rdoc_dir = 'rdoc'
|
65
|
+
|
66
|
+
rd.rdoc_files.include('README.txt', 'CHANGELOG.txt', 'lib/**/*.rb')
|
67
|
+
|
68
|
+
rd.title = "#{GEMSPEC.name} #{GEMSPEC.version}"
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
#
|
73
|
+
# upload_rdoc
|
74
|
+
|
75
|
+
desc %{
|
76
|
+
upload the rdoc to rubyforge
|
77
|
+
}
|
78
|
+
task :upload_rdoc => [ :clean, :rdoc ] do
|
79
|
+
|
80
|
+
account = 'jmettraux@rubyforge.org'
|
81
|
+
webdir = "/var/www/gforge-projects/rufus"
|
82
|
+
|
83
|
+
sh "rsync -azv -e ssh rdoc/#{GEMSPEC.name} #{account}:#{webdir}/"
|
84
|
+
end
|
85
|
+
|
data/lib/rufus/dollar.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
|
-
#
|
2
1
|
#--
|
3
|
-
# Copyright (c) 2006-
|
2
|
+
# Copyright (c) 2006-2011, John Mettraux, jmettraux@gmail.com
|
4
3
|
#
|
5
4
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
5
|
# of this software and associated documentation files (the "Software"), to deal
|
@@ -20,76 +19,93 @@
|
|
20
19
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
20
|
# THE SOFTWARE.
|
22
21
|
#++
|
23
|
-
#
|
24
|
-
|
25
|
-
#
|
26
|
-
# "made in Japan"
|
27
|
-
#
|
28
|
-
# John Mettraux at openwfe.org
|
29
|
-
#
|
30
22
|
|
31
23
|
|
32
24
|
module Rufus
|
33
25
|
|
34
|
-
#
|
35
26
|
# Performs 'dollar substitution' on a piece of text with a given
|
36
27
|
# dictionary.
|
37
28
|
#
|
38
|
-
#
|
39
|
-
#
|
40
|
-
#
|
41
|
-
# h = {
|
42
|
-
# "name" => "Fred Brooke",
|
43
|
-
# "title" => "Silver Bullet"
|
44
|
-
# }
|
29
|
+
# Please use Rufus::Dollar.dsub instead, this Rufus.dsub is kept
|
30
|
+
# for backward compatibility.
|
45
31
|
#
|
46
|
-
|
47
|
-
# # => "Fred Brooke wrote 'Silver Bullet'"
|
48
|
-
#
|
49
|
-
def self.dsub (text, dict, offset=nil)
|
32
|
+
def self.dsub(text, dict)
|
50
33
|
|
51
|
-
text
|
34
|
+
Rufus::Dollar.dsub(text, dict)
|
35
|
+
end
|
52
36
|
|
53
|
-
|
37
|
+
module Dollar
|
54
38
|
|
55
|
-
|
39
|
+
VERSION = '1.0.3'
|
56
40
|
|
57
|
-
|
41
|
+
# Performs 'dollar substitution' on a piece of text with a given
|
42
|
+
# dictionary.
|
43
|
+
#
|
44
|
+
# require 'rubygems'
|
45
|
+
# require 'rufus/dollar'
|
46
|
+
#
|
47
|
+
# h = {
|
48
|
+
# "name" => "Fred Brooke",
|
49
|
+
# "title" => "Silver Bullet"
|
50
|
+
# }
|
51
|
+
#
|
52
|
+
# puts Rufus::Dollar.dsub "${name} wrote '${title}'", h
|
53
|
+
# # => "Fred Brooke wrote 'Silver Bullet'"
|
54
|
+
#
|
55
|
+
# == ${'key} or ${"key}
|
56
|
+
#
|
57
|
+
# puts Rufus::Dollar.dsub "${name} wrote ${title}", h
|
58
|
+
# # => "Fred Brooke wrote Silver Bullet"
|
59
|
+
#
|
60
|
+
# puts Rufus::Dollar.dsub "${name} wrote ${'title}", h
|
61
|
+
# # => 'Fred Brooke wrote "Silver Bullet"'
|
62
|
+
#
|
63
|
+
def self.dsub(text, dict, offset=nil)
|
58
64
|
|
59
|
-
|
60
|
-
ii = t.rindex("\\${")
|
65
|
+
text = text.to_s
|
61
66
|
|
62
|
-
|
63
|
-
iii = nil if offset
|
67
|
+
j = text.index('}', offset || 0)
|
64
68
|
|
65
|
-
|
66
|
-
return dsub(text, dict, j+1) if (iii) and (iii-1 > i)
|
69
|
+
return text unless j
|
67
70
|
|
68
|
-
|
69
|
-
#
|
70
|
-
# found "\${"
|
71
|
+
t = text[0, j]
|
71
72
|
|
72
|
-
|
73
|
+
i = t.rindex('${')
|
74
|
+
ii = t.rindex("\\${")
|
73
75
|
|
74
|
-
|
76
|
+
iii = t.rindex('{')
|
77
|
+
iii = nil if offset
|
75
78
|
|
76
|
-
|
77
|
-
|
78
|
-
else
|
79
|
-
dict.has_key?(key) ? 'false' : ''
|
80
|
-
end
|
79
|
+
return text unless i
|
80
|
+
return dsub(text, dict, j+1) if (iii) and (iii-1 > i)
|
81
81
|
|
82
|
-
|
82
|
+
return unescape(text) if (i) and (i != 0) and (ii == i-1)
|
83
|
+
#
|
84
|
+
# found "\${"
|
83
85
|
|
84
|
-
|
85
|
-
|
86
|
+
key = text[i+2..j-1]
|
87
|
+
quote = false
|
86
88
|
|
87
|
-
|
89
|
+
if m = key.match(/^['"](.+)$/)
|
90
|
+
key = m[1]
|
91
|
+
quote = true
|
92
|
+
end
|
88
93
|
|
89
|
-
|
94
|
+
value = dict[key]
|
95
|
+
value = value.nil? ? '' : value.to_s
|
96
|
+
value = value.inspect if quote
|
90
97
|
|
91
|
-
|
92
|
-
|
98
|
+
pre = (i > 0) ? text[0..i-1] : ''
|
99
|
+
|
100
|
+
dsub("#{pre}#{value}#{text[j+1..-1]}", dict)
|
101
|
+
end
|
93
102
|
|
103
|
+
private
|
104
|
+
|
105
|
+
def self.unescape(text)
|
106
|
+
|
107
|
+
text.gsub("\\\\\\$\\{", "\\${")
|
108
|
+
end
|
109
|
+
end
|
94
110
|
end
|
95
111
|
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
|
5
|
+
s.name = 'rufus-dollar'
|
6
|
+
s.version = File.read('lib/rufus/dollar.rb').match(/VERSION = '([^']+)'/)[1]
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.authors = [ 'John Mettraux' ]
|
9
|
+
s.email = [ 'jmettraux@gmail.com' ]
|
10
|
+
s.homepage = 'http://rufus.rubyforge.org'
|
11
|
+
s.rubyforge_project = 'rufus'
|
12
|
+
s.summary = '${xxx} substitutions'
|
13
|
+
s.description = %{
|
14
|
+
${xxx} substitutions
|
15
|
+
}
|
16
|
+
|
17
|
+
#s.files = `git ls-files`.split("\n")
|
18
|
+
s.files = Dir[
|
19
|
+
'Rakefile',
|
20
|
+
'lib/**/*.rb', 'spec/**/*.rb', 'test/**/*.rb',
|
21
|
+
'*.gemspec', '*.txt', '*.rdoc', '*.md'
|
22
|
+
]
|
23
|
+
|
24
|
+
#s.add_runtime_dependency 'rufus-json', '>= 0.2.5'
|
25
|
+
|
26
|
+
s.add_development_dependency 'rake'
|
27
|
+
s.add_development_dependency 'rspec', ">= 2.0"
|
28
|
+
|
29
|
+
s.require_path = 'lib'
|
30
|
+
end
|
31
|
+
|
data/spec/dollar_spec.rb
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
|
2
|
+
#
|
3
|
+
# Specifying rufus-dollar
|
4
|
+
#
|
5
|
+
# Tue Dec 21 15:48:43 JST 2010
|
6
|
+
#
|
7
|
+
|
8
|
+
require File.join(File.dirname(__FILE__), 'spec_base')
|
9
|
+
|
10
|
+
|
11
|
+
describe Rufus::Dollar do
|
12
|
+
|
13
|
+
context 'simple usage' do
|
14
|
+
|
15
|
+
let(:dict) do
|
16
|
+
{
|
17
|
+
'renard' => 'goupil',
|
18
|
+
'cane' => 'oie',
|
19
|
+
'oie blanche' => 'poule',
|
20
|
+
'x' => 'y'
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '.dsub' do
|
25
|
+
|
26
|
+
it "doesn't substitute if there are no ${}" do
|
27
|
+
|
28
|
+
dsub("le petit renard").should == "le petit renard"
|
29
|
+
end
|
30
|
+
|
31
|
+
it "doesn't substitute if there is only {}" do
|
32
|
+
|
33
|
+
dsub("le petit {renard}").should == "le petit {renard}"
|
34
|
+
end
|
35
|
+
|
36
|
+
it "substitutes at the end" do
|
37
|
+
|
38
|
+
dsub("le petit ${renard}").should == "le petit goupil"
|
39
|
+
end
|
40
|
+
|
41
|
+
it "substitutes in the middle" do
|
42
|
+
|
43
|
+
dsub("le petit ${renard} noir").should == "le petit goupil noir"
|
44
|
+
end
|
45
|
+
|
46
|
+
it "substitutes when there are two ${}" do
|
47
|
+
|
48
|
+
dsub("le ${renard} et la ${cane}").should == "le goupil et la oie"
|
49
|
+
# excuse my french
|
50
|
+
end
|
51
|
+
|
52
|
+
it "doesn't substitute when escaped \\\\${renard}" do
|
53
|
+
|
54
|
+
dsub("le petit \\${renard} noir").should == "le petit \\${renard} noir"
|
55
|
+
end
|
56
|
+
|
57
|
+
it "leaves \\n untouched" do
|
58
|
+
|
59
|
+
dsub("\n").should == "\n"
|
60
|
+
end
|
61
|
+
|
62
|
+
it "substitutes to a blank when there is no entry in the dict" do
|
63
|
+
|
64
|
+
dsub("le petit ${chien} suisse").should == "le petit suisse"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
#def test_0
|
70
|
+
# dotest " ${a${b}e} ", {}, " "
|
71
|
+
# dotest " ${a{b}e} ", {}, " "
|
72
|
+
# dotest "${a{b}e}", {}, ""
|
73
|
+
# dotest " \\${a{b}e} ", {}, " \\${a{b}e} "
|
74
|
+
# dotest "{a${b}c}", { "b" => 2 }, "{a2c}"
|
75
|
+
#end
|
76
|
+
# no need to integrate that for now
|
77
|
+
|
78
|
+
context 'nested brackets' do
|
79
|
+
|
80
|
+
let(:dict) do
|
81
|
+
{
|
82
|
+
'B' => 'b',
|
83
|
+
'ab' => 'ok'
|
84
|
+
}
|
85
|
+
end
|
86
|
+
|
87
|
+
describe '.dsub' do
|
88
|
+
|
89
|
+
it 'substitutes successively' do
|
90
|
+
|
91
|
+
dsub("${a${B}}").should == 'ok'
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
context 'dollar bracket double-quote' do
|
97
|
+
|
98
|
+
let(:dict) do
|
99
|
+
{
|
100
|
+
'renard' => 'goupil',
|
101
|
+
}
|
102
|
+
end
|
103
|
+
|
104
|
+
describe '.dsub' do
|
105
|
+
|
106
|
+
it 'encloses in double-quotes when ${\'renard}' do
|
107
|
+
|
108
|
+
dsub("${'renard}").should == '"goupil"'
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'encloses in double-quotes when ${"renard}' do
|
112
|
+
|
113
|
+
dsub('${"renard}').should == '"goupil"'
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
data/spec/spec_base.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
|
2
|
+
$:.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')))
|
3
|
+
|
4
|
+
require 'rufus-dollar'
|
5
|
+
|
6
|
+
|
7
|
+
#
|
8
|
+
# rspec helpers
|
9
|
+
|
10
|
+
Dir[File.join(File.dirname(__FILE__), 'support/*.rb')].each { |f| require(f) }
|
11
|
+
|
12
|
+
RSpec.configure do |config|
|
13
|
+
config.include DollarHelper
|
14
|
+
end
|
15
|
+
|
metadata
CHANGED
@@ -1,64 +1,97 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rufus-dollar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 1
|
7
|
+
- 0
|
8
|
+
- 3
|
9
|
+
version: 1.0.3
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
|
-
- John Mettraux
|
12
|
+
- John Mettraux
|
8
13
|
autorequire:
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date:
|
17
|
+
date: 2010-12-22 00:00:00 +09:00
|
13
18
|
default_executable:
|
14
|
-
dependencies:
|
15
|
-
|
16
|
-
|
17
|
-
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rake
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
version: "0"
|
30
|
+
type: :development
|
31
|
+
version_requirements: *id001
|
32
|
+
- !ruby/object:Gem::Dependency
|
33
|
+
name: rspec
|
34
|
+
prerelease: false
|
35
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
segments:
|
40
|
+
- 2
|
41
|
+
- 0
|
42
|
+
version: "2.0"
|
43
|
+
type: :development
|
44
|
+
version_requirements: *id002
|
45
|
+
description: "\n\
|
46
|
+
${xxx} substitutions\n "
|
47
|
+
email:
|
48
|
+
- jmettraux@gmail.com
|
18
49
|
executables: []
|
19
50
|
|
20
51
|
extensions: []
|
21
52
|
|
22
|
-
extra_rdoc_files:
|
23
|
-
|
24
|
-
- CHANGELOG.txt
|
25
|
-
- LICENSE.txt
|
53
|
+
extra_rdoc_files: []
|
54
|
+
|
26
55
|
files:
|
27
|
-
-
|
28
|
-
- lib/rufus
|
29
|
-
- lib/rufus
|
30
|
-
-
|
31
|
-
-
|
32
|
-
-
|
33
|
-
-
|
34
|
-
-
|
35
|
-
-
|
36
|
-
-
|
56
|
+
- Rakefile
|
57
|
+
- lib/rufus-dollar.rb
|
58
|
+
- lib/rufus/dollar.rb
|
59
|
+
- spec/dollar_spec.rb
|
60
|
+
- spec/spec_base.rb
|
61
|
+
- spec/support/dollar_helper.rb
|
62
|
+
- rufus-dollar.gemspec
|
63
|
+
- CHANGELOG.txt
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.txt
|
37
66
|
has_rdoc: true
|
38
|
-
homepage: http://rufus.rubyforge.org
|
67
|
+
homepage: http://rufus.rubyforge.org
|
68
|
+
licenses: []
|
69
|
+
|
39
70
|
post_install_message:
|
40
71
|
rdoc_options: []
|
41
72
|
|
42
73
|
require_paths:
|
43
|
-
- lib
|
74
|
+
- lib
|
44
75
|
required_ruby_version: !ruby/object:Gem::Requirement
|
45
76
|
requirements:
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
segments:
|
80
|
+
- 0
|
81
|
+
version: "0"
|
50
82
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
83
|
requirements:
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
segments:
|
87
|
+
- 0
|
88
|
+
version: "0"
|
56
89
|
requirements: []
|
57
90
|
|
58
|
-
rubyforge_project:
|
59
|
-
rubygems_version: 1.3.
|
91
|
+
rubyforge_project: rufus
|
92
|
+
rubygems_version: 1.3.6
|
60
93
|
signing_key:
|
61
|
-
specification_version:
|
94
|
+
specification_version: 3
|
62
95
|
summary: ${xxx} substitutions
|
63
|
-
test_files:
|
64
|
-
|
96
|
+
test_files: []
|
97
|
+
|
data/test/dollar_test.rb
DELETED
@@ -1,80 +0,0 @@
|
|
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 File.dirname(__FILE__) + '/test_base'
|
12
|
-
|
13
|
-
|
14
|
-
class DollarTest < 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
|
-
dict = {}
|
26
|
-
|
27
|
-
dict['renard'] = 'goupil'
|
28
|
-
dict['cane'] = 'oie'
|
29
|
-
dict['oie blanche'] = 'poule'
|
30
|
-
|
31
|
-
dotest "le petit renard", dict, "le petit renard"
|
32
|
-
dotest "le petit {renard}", dict, "le petit {renard}"
|
33
|
-
dotest "le petit ${renard}", dict, "le petit goupil"
|
34
|
-
dotest "le petit ${renard} noir", dict, "le petit goupil noir"
|
35
|
-
|
36
|
-
dotest "la grande ${${cane} blanche}", dict, "la grande poule"
|
37
|
-
|
38
|
-
dotest "le ${renard} et la ${cane}", dict, "le goupil et la oie"
|
39
|
-
#
|
40
|
-
# excuse my french...
|
41
|
-
|
42
|
-
dotest "le \\${renard} encore", dict, "le \\${renard} encore"
|
43
|
-
|
44
|
-
dotest "", dict, ""
|
45
|
-
|
46
|
-
dotest("""
|
47
|
-
""", dict, """
|
48
|
-
""")
|
49
|
-
dotest("""
|
50
|
-
""", dict, """
|
51
|
-
""")
|
52
|
-
end
|
53
|
-
|
54
|
-
def test_1
|
55
|
-
|
56
|
-
dict = {}
|
57
|
-
dict['x'] = 'y'
|
58
|
-
|
59
|
-
dotest "${x}", dict, "y"
|
60
|
-
dotest "\\${x}", dict, "\\${x}"
|
61
|
-
end
|
62
|
-
|
63
|
-
def test_2
|
64
|
-
|
65
|
-
dict = {}
|
66
|
-
dict['A'] = 'a'
|
67
|
-
dict['B'] = 'b'
|
68
|
-
dict['ab'] = 'ok'
|
69
|
-
|
70
|
-
dotest "${${A}${B}}", dict, "ok"
|
71
|
-
end
|
72
|
-
|
73
|
-
#def test_3
|
74
|
-
# assert_equal OpenWFE.unescape("toto and ${toto}"), "toto and ${toto}"
|
75
|
-
# assert_equal OpenWFE.unescape("toto & \${toto}"), "toto & ${toto}"
|
76
|
-
# assert_equal "toto & \\${toto}", "toto & ${toto}"
|
77
|
-
# #assert_equal OpenWFE.unescape('toto & \${toto}'), "toto & ${toto}"
|
78
|
-
#end
|
79
|
-
|
80
|
-
end
|
data/test/nested_test.rb
DELETED
@@ -1,30 +0,0 @@
|
|
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 File.dirname(__FILE__) + '/test_base'
|
11
|
-
|
12
|
-
|
13
|
-
class NestedTest < Test::Unit::TestCase
|
14
|
-
include TestBase
|
15
|
-
|
16
|
-
#def setup
|
17
|
-
#end
|
18
|
-
|
19
|
-
#def teardown
|
20
|
-
#end
|
21
|
-
|
22
|
-
def test_0
|
23
|
-
|
24
|
-
dotest " ${a${b}e} ", {}, " "
|
25
|
-
dotest " ${a{b}e} ", {}, " "
|
26
|
-
dotest "${a{b}e}", {}, ""
|
27
|
-
dotest " \\${a{b}e} ", {}, " \\${a{b}e} "
|
28
|
-
dotest "{a${b}c}", { "b" => 2 }, "{a2c}"
|
29
|
-
end
|
30
|
-
end
|
data/test/test.rb
DELETED
data/test/test_base.rb
DELETED
@@ -1,27 +0,0 @@
|
|
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
|
-
$:.unshift File.dirname(__FILE__) + '/../lib/'
|
11
|
-
|
12
|
-
require 'test/unit'
|
13
|
-
require 'rufus/dollar'
|
14
|
-
|
15
|
-
|
16
|
-
module TestBase
|
17
|
-
|
18
|
-
protected
|
19
|
-
|
20
|
-
def dotest (text, dict, target)
|
21
|
-
|
22
|
-
result = Rufus.dsub(text, dict)
|
23
|
-
|
24
|
-
assert_equal target, result
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|