spec/url_encoded_spec.rb in nyara-0.0.1.pre.9 vs spec/url_encoded_spec.rb in nyara-0.1.pre.0
- old
+ new
@@ -12,64 +12,34 @@
s = "/a/path.js"
assert_equal CGI.escape(s), Ext.escape(s, false)
end
end
- # note: this method is only used in C code
- context "Ext.parse_url_encoded_seg" do
- [false, true].each do |nested|
- context (nested ? 'nested mode' : 'flat mode') do
- it "normal parse" do
- assert_equal({'a' => 'b'}, parse('a=b', nested))
- end
+ context "Ext.decode_uri_kv" do
+ it "empty k" do
+ k, v = Ext.decode_uri_kv "=b"
+ assert_equal '', k
+ assert_equal 'b', v
+ end
- it "param seg end with '='" do
- assert_equal({'a' => ''}, parse('a=', nested))
- end
+ it "empty v" do
+ k, v = Ext.decode_uri_kv "a="
+ assert_equal 'a', k
+ assert_equal '', v
+ end
- it "param seg begin with '='" do
- assert_equal({'' => 'b'}, parse('=b', nested))
- end
-
- it "param seg without value" do
- assert_equal({'a' => ''}, parse('a', nested))
- end
-
- it "raises error" do
- assert_raise ArgumentError do
- parse 'a=&b'
- end
- end
- end
+ it "without '='" do
+ k, v = Ext.decode_uri_kv "a"
+ assert_equal 'a', k
+ assert_equal '', v
end
- context "nested key" do
- it "parses nested key" do
- res = {"a"=>{"b"=>[[{"c"=>"1"}]]}}
- assert_equal res, Ext.parse_url_encoded_seg({}, "a[b][][][c]=1", true)
+ it "raises for bad kv" do
+ assert_raise ArgumentError do
+ Ext.decode_uri_kv 'a=&b'
end
-
- it 'allows "[]" as input' do
- res = {""=>[""]}
- assert_equal res, Ext.parse_url_encoded_seg({}, "[]", true)
- end
-
- it 'ignores empty input' do
- res = {}
- assert_equal res, Ext.parse_url_encoded_seg({}, "", true)
- end
-
- it "content hash is ParamHash" do
- h = ParamHash.new
- assert_equal ParamHash, Ext.parse_url_encoded_seg(h, "a[b]=c", true)[:a].class
- end
end
-
- def parse str, nested
- h = {}
- Ext.parse_url_encoded_seg h, str, nested
- end
end
context "Ext.parse_path" do
before :each do
@output = ''
@@ -135,35 +105,9 @@
assert_equal '/a', @output
end
def parse input
Ext.parse_path @output, input
- end
- end
-
- context "Ext.parse_cookie" do
- it "parses complex cookie" do
- history = CGI.escape '历史'
- cookie = "pgv_pvi; pgv_si= ; pgv_pvi=som; sid=1d6c75f0 ; PLHistory=<#{history}>;"
- h = Ext.parse_cookie ParamHash.new, cookie
- assert_equal '1d6c75f0', h['sid']
- assert_equal '', h['pgv_si']
- assert_equal '', h['pgv_pvi'] # left orverrides right
- assert_equal '<历史>', h['PLHistory']
- end
-
- it "parses empty cookie" do
- cookie = ''
- h = Ext.parse_cookie ParamHash.new, cookie
- assert_empty h
- end
- end
-
- context "Ext.parse_param" do
- it "parses param with non-utf-8 chars" do
- bad_s = CGI.escape "\xE2"
- h = Ext.parse_param ParamHash.new, bad_s
- assert_equal "", h["\xE2"]
end
end
end
end