php4r 0.0.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.
@@ -0,0 +1,98 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Php4r" do
4
+ it "explode" do
5
+ teststr = "1;2;3"
6
+ arr = Php4r.explode(";", teststr)
7
+
8
+ raise "Invalid length." if arr.length != 3
9
+ raise "Invalid first." if arr[0] != "1"
10
+ raise "Invalid second." if arr[1] != "2"
11
+ raise "Invalid third." if arr[2] != "3"
12
+ end
13
+
14
+ it "is_numeric" do
15
+ raise "Failed." if !Php4r.is_numeric(123)
16
+ raise "Failed." if !Php4r.is_numeric("123")
17
+ raise "Failed." if Php4r.is_numeric("kasper123")
18
+ raise "Failed." if Php4r.is_numeric("123kasper")
19
+ raise "Failed." if !Php4r.is_numeric(123.12)
20
+ raise "Failed." if !Php4r.is_numeric("123.12")
21
+ end
22
+
23
+ it "number_format" do
24
+ tests = {
25
+ Php4r.number_format(123123.12, 3, ",", ".") => "123.123,120",
26
+ Php4r.number_format(123123.12, 4, ".", ",") => "123,123.1200",
27
+ Php4r.number_format(-123123.12, 2, ",", ".") => "-123.123,12",
28
+ Php4r.number_format(-120, 2, ",", ".") => "-120,00",
29
+ Php4r.number_format(-12, 2, ".", ",") => "-12.00"
30
+ }
31
+
32
+ tests.each do |key, val|
33
+ if key != val
34
+ raise "Key was not the same as value (#{key}) (#{val})."
35
+ end
36
+ end
37
+ end
38
+
39
+ it "substr" do
40
+ res = Php4r.substr("selcol_15", 7)
41
+ raise "substr should have returned '15' but didnt: '#{res}'." if res != "15"
42
+
43
+ res = Php4r.substr("test_kasper", -6, 6)
44
+ raise "substr should have returned 'kasper' but didnt: '#{res}'." if res != "kasper"
45
+
46
+ res = Php4r.substr("test_kasper", 1, 3)
47
+ raise "substr should have returned 'est' but didnt: '#{res}'." if res != "est"
48
+
49
+ res = Php4r.substr("test_kasper", 0, -3)
50
+ raise "substr should have returned 'test_kas' but didnt: '#{res}'." if res != "test_kas"
51
+ end
52
+
53
+ it "parse_str" do
54
+ teststr = "first=value&arr[]=foo+bar&arr[]=baz&hash[trala]=hmm&hash[trala2]=wtf"
55
+
56
+ hash = {}
57
+ Php4r.parse_str(teststr, hash)
58
+
59
+ raise "Invalid value for first." if hash["first"] != "value"
60
+ raise "Invalid value for first in arr." if hash["arr"]["0"] != "foo bar"
61
+ raise "Invalid value for second in arr." if hash["arr"]["1"] != "baz"
62
+ raise "Invalid value for hash-trala." if hash["hash"]["trala"] != "hmm"
63
+ raise "Invalid value for hash-trala2." if hash["hash"]["trala2"] != "wtf"
64
+ end
65
+
66
+ it "file_get_contents - http" do
67
+ cont = Php4r.file_get_contents("https://www.kaspernj.org/myip.php")
68
+ raise "Not IP: '#{cont}'." if !cont.to_s.match(/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/)
69
+ end
70
+
71
+ #Moved from "knjrbfw_spec.rb".
72
+ it "should be able to execute various Php4r functions correctly." do
73
+ str = "Kasper Johansen"
74
+
75
+ #substr
76
+ teststr = Php4r.substr(str, 7, 8)
77
+ if teststr != "Johansen"
78
+ raise "substr did not return expected result: '#{teststr}'"
79
+ end
80
+
81
+ teststr = Php4r.substr(str, -8, 8)
82
+ if teststr != "Johansen"
83
+ raise "substr did not returned expected result when using negative positions: '#{teststr}'."
84
+ end
85
+
86
+ #strtoupper
87
+ teststr = Php4r.strtoupper(str)
88
+ if teststr != "KASPER JOHANSEN"
89
+ raise "strtoupper did not return expected result: '#{teststr}'."
90
+ end
91
+
92
+ #strtolower
93
+ teststr = Php4r.strtolower(str)
94
+ if teststr != "kasper johansen"
95
+ raise "strtolower did not return expected result: '#{teststr}'."
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'php4r'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: php4r
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.0
6
+ platform: ruby
7
+ authors:
8
+ - Kasper Johansen
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2012-07-28 00:00:00 +02:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: http2
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: datet
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: "0"
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: rspec
40
+ requirement: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 2.8.0
46
+ type: :development
47
+ prerelease: false
48
+ version_requirements: *id003
49
+ - !ruby/object:Gem::Dependency
50
+ name: rdoc
51
+ requirement: &id004 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ~>
55
+ - !ruby/object:Gem::Version
56
+ version: "3.12"
57
+ type: :development
58
+ prerelease: false
59
+ version_requirements: *id004
60
+ - !ruby/object:Gem::Dependency
61
+ name: bundler
62
+ requirement: &id005 !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: 1.0.0
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: *id005
71
+ - !ruby/object:Gem::Dependency
72
+ name: jeweler
73
+ requirement: &id006 !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ~>
77
+ - !ruby/object:Gem::Version
78
+ version: 1.8.4
79
+ type: :development
80
+ prerelease: false
81
+ version_requirements: *id006
82
+ description: A lib containing various PHP-functions coded in Ruby. You can either use it or use it as a reference, if you are coming from PHP to Ruby or the other way around.
83
+ email: k@spernj.org
84
+ executables: []
85
+
86
+ extensions: []
87
+
88
+ extra_rdoc_files:
89
+ - LICENSE.txt
90
+ - README.rdoc
91
+ files:
92
+ - .document
93
+ - .rspec
94
+ - Gemfile
95
+ - Gemfile.lock
96
+ - LICENSE.txt
97
+ - README.rdoc
98
+ - Rakefile
99
+ - VERSION
100
+ - lib/php4r.rb
101
+ - spec/php4r_spec.rb
102
+ - spec/spec_helper.rb
103
+ has_rdoc: true
104
+ homepage: http://github.com/kaspernj/php4r
105
+ licenses:
106
+ - MIT
107
+ post_install_message:
108
+ rdoc_options: []
109
+
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ hash: -841571319118547036
118
+ segments:
119
+ - 0
120
+ version: "0"
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: "0"
127
+ requirements: []
128
+
129
+ rubyforge_project:
130
+ rubygems_version: 1.6.2
131
+ signing_key:
132
+ specification_version: 3
133
+ summary: A lib containing various PHP-functions coded in Ruby.
134
+ test_files: []
135
+