fjson 0.1.0 → 0.1.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.
Files changed (44) hide show
  1. data/CHANGES +0 -3
  2. data/Rakefile +43 -41
  3. data/ext/extensions/array_ext/array_ext.c +13 -81
  4. data/ext/extensions/array_ext/array_ext.h +4 -8
  5. data/ext/extensions/array_ext/extconf.mkmf.rb +3 -0
  6. data/ext/extensions/enumerable/enumerable.c +70 -0
  7. data/ext/extensions/enumerable/enumerable.h +9 -0
  8. data/ext/extensions/hash_ext/extconf.mkmf.rb +3 -0
  9. data/ext/extensions/hash_ext/hash_ext.c +13 -81
  10. data/ext/extensions/hash_ext/hash_ext.h +3 -8
  11. data/ext/json_ext/json_ext.c +12 -13
  12. data/ext/json_ext/json_ext.h +2 -0
  13. data/ext/state_ext/state_ext.c +16 -85
  14. data/ext/state_ext/state_ext.h +3 -7
  15. data/ext/state_ext/state_lib.c +107 -0
  16. data/ext/state_ext/state_lib.h +15 -0
  17. data/hash_benchmark.rb +0 -2
  18. data/hash_benchmark_action_support.rb +4 -0
  19. data/hash_benchmark_fjson.rb +3 -0
  20. data/hash_benchmark_json.rb +4 -0
  21. data/lib/json/editor.rb +1 -1
  22. data/mkmf_tasks.rb +99 -0
  23. data/rake_helper.rb +1 -1
  24. data/spec/array_spec.rb +12 -2
  25. data/spec/false_class_spec.rb +1 -1
  26. data/spec/float_spec.rb +1 -1
  27. data/spec/hash_spec.rb +13 -0
  28. data/spec/integer_spec.rb +1 -1
  29. data/spec/mkmf_tasks_spec.rb +110 -0
  30. data/spec/nil_class_spec.rb +1 -1
  31. data/spec/object_spec.rb +1 -1
  32. data/spec/spec_helper.rb +10 -0
  33. data/spec/spec_suite.rb +3 -8
  34. data/spec/state_spec.rb +10 -11
  35. data/spec/string_spec.rb +1 -1
  36. data/spec/string_when_not_supporting_unicode_and_kcode_is_not_utf8_json_spec.rb +1 -1
  37. data/spec/string_when_supporting_unicode_and_kcode_is_not_utf8_json_spec.rb +1 -1
  38. data/spec/string_with_latin1_character_set_json_spec.rb +15 -15
  39. data/spec/string_with_utf8_values_when_supporting_unicode_json_spec.rb +12 -12
  40. data/spec/true_class_spec.rb +1 -1
  41. metadata +58 -53
  42. data/mkmf_rake_builder.rb +0 -170
  43. data/spec/mkmf_rake_builder_spec.rb +0 -217
  44. data/spec/rake_helper_spec.rb +0 -9
@@ -5,4 +5,4 @@ require 'rake/clean'
5
5
  require 'rake/testtask'
6
6
  require 'rake/rdoctask'
7
7
  dir = File.dirname(__FILE__)
8
- require "#{dir}/mkmf_rake_builder"
8
+ require "#{dir}/mkmf_tasks"
@@ -7,14 +7,24 @@ require File.expand_path("#{dir}/../lib/fjson")
7
7
  context "A one dimensional Array" do
8
8
  specify "should create json" do
9
9
  array = [1, 'hello', :hello]
10
- array.to_json.should == '[1,"hello","hello"]'
10
+ array.to_json.should_eql '[1,"hello","hello"]'
11
+ end
12
+
13
+ specify "should allow child object to have to_json with no arguments" do
14
+ obj = Object.new
15
+ def obj.to_json
16
+ "json".to_json
17
+ end
18
+
19
+ array = [obj]
20
+ array.to_json.should_eql "[\"json\"]"
11
21
  end
12
22
  end
13
23
 
14
24
  context "A multi-dimensional Array" do
15
25
  specify "should create json" do
16
26
  array = [1, ['hello', [:hello]]]
17
- array.to_json.should == '[1,["hello",["hello"]]]'
27
+ array.to_json.should_eql '[1,["hello",["hello"]]]'
18
28
  end
19
29
 
20
30
  specify "should not support circular dependencies" do
@@ -6,7 +6,7 @@ require File.expand_path("#{dir}/../lib/fjson")
6
6
 
7
7
  context "A false object" do
8
8
  specify "should convert to json" do
9
- false.to_json.should == "false"
9
+ false.to_json.should_eql "false"
10
10
  end
11
11
 
12
12
  specify "to_json should accept any number of arguments" do
@@ -6,7 +6,7 @@ require File.expand_path("#{dir}/../lib/fjson")
6
6
 
7
7
  context "A float number" do
8
8
  specify "should convert to json" do
9
- (3.14).to_json.should == "3.14"
9
+ (3.14).to_json.should_eql "3.14"
10
10
  end
11
11
 
12
12
  specify "to_json should accept any number of arguments" do
@@ -14,6 +14,19 @@ context "A one dimensional Hash" do
14
14
  json.should_include "\"one\":1"
15
15
  json.should_include "\"hello\":\"hello\""
16
16
  end
17
+
18
+ specify "should allow child object to have to_json with no arguments" do
19
+ obj = Object.new
20
+ def obj.to_json
21
+ "json".to_json
22
+ end
23
+
24
+ hash = {
25
+ "key" => obj
26
+ }
27
+
28
+ hash.to_json.should_eql "{\"key\":\"json\"}"
29
+ end
17
30
  end
18
31
 
19
32
  context "A multi-dimensional Hash" do
@@ -6,7 +6,7 @@ require File.expand_path("#{dir}/../lib/fjson")
6
6
 
7
7
  context "An integer" do
8
8
  specify "should convert to json" do
9
- 5.to_json.should == "5"
9
+ 5.to_json.should_eql "5"
10
10
  end
11
11
 
12
12
  specify "to_json should accept any number of arguments" do
@@ -0,0 +1,110 @@
1
+ dir = File.dirname(__FILE__)
2
+ require "#{dir}/spec_helper"
3
+
4
+ context "A MkmfTasks" do
5
+ setup do
6
+ @actor = mock("Rake Actor")
7
+ @tasks = MkmfTasks.new(@actor)
8
+
9
+ dir = File.dirname(__FILE__)
10
+ @extconf_file_name = @tasks.extconf_file_name = "extconf.mkmf.rb"
11
+ @project_dir = @tasks.project_dir = "/project/dir"
12
+ end
13
+
14
+ specify "default is compile" do
15
+ @tasks.should_receive(:compile)
16
+ @tasks.default
17
+ end
18
+
19
+ specify "compile makes files" do
20
+ @tasks.extension_paths = ["foo", "extensions/bar"]
21
+ @tasks.extconf_arguments = "-extconfarg"
22
+ @tasks.extconf_file_name = "extconf.rb"
23
+
24
+ verify_extconf = proc do |dir, blk|
25
+ extconf_mock = mock("Extconf is called")
26
+ extconf_mock.should_receive(:sh).with("ruby -extconfarg extconf.rb")
27
+ extconf_mock.instance_eval(&blk)
28
+ end
29
+
30
+ verify_make = proc do |dir, blk|
31
+ make_mock = mock("Make is called")
32
+ make_mock.should_receive(:sh).with('make')
33
+ make_mock.instance_eval(&blk)
34
+ end
35
+
36
+ Dir.should_receive(:chdir).with("ext/foo").twice.and_yield
37
+ Dir.should_receive(:chdir).with("ext/extensions/bar").twice.and_yield
38
+
39
+ @actor.should_receive(:sh).with("ruby -extconfarg extconf.rb").twice
40
+ @actor.should_receive(:sh).with("make").twice
41
+
42
+ @tasks.compile
43
+ end
44
+
45
+ specify "spec calls compile, install, and runs the specs" do
46
+ @tasks.should_receive(:compile).ordered
47
+ @tasks.should_receive(:install).ordered
48
+ @tasks.should_receive(:require).with("#{@project_dir}/spec/spec_suite").ordered
49
+ @tasks.spec
50
+ end
51
+
52
+ specify "lib create lib directory" do
53
+ @tasks.should_receive(:directory).with("lib")
54
+ @tasks.lib
55
+ end
56
+
57
+ specify "install copies the build path to the library path" do
58
+ @tasks.extension_paths = ["foo", "extensions/bar"]
59
+ @tasks.file_extension = "so"
60
+ File.stub!(:exists?).and_return(true)
61
+ @tasks.should_receive(:cp).with("/project/dir/ext/foo/foo.so", "/project/dir/lib/foo.so")
62
+ @tasks.should_receive(:cp).with("/project/dir/ext/extensions/bar/bar.so", "/project/dir/lib/extensions/bar.so")
63
+ @tasks.install
64
+ end
65
+
66
+ specify "install raises an exception when the source file does not exist" do
67
+ @tasks.extension_paths = ["foo", "extensions/bar"]
68
+ @tasks.file_extension = "so"
69
+ File.should_receive(:exists?).with("/project/dir/ext/foo/foo.so").and_return(false)
70
+ proc do
71
+ @tasks.install
72
+ end.should_raise(Exception, "File /project/dir/ext/foo/foo.so does not exist")
73
+ end
74
+
75
+ specify "cleanup removes all of the build artifacts" do
76
+ @tasks.extension_paths = ["extensions/foo", "extensions/bar"]
77
+ @tasks.file_extension = "file_extension"
78
+
79
+ File.should_receive(:dirname).at_least(1).with("extensions/foo").and_return("extensions")
80
+ File.should_receive(:dirname).at_least(1).with("extensions/bar").and_return("extensions")
81
+ File.should_receive(:basename).at_least(1).with("extensions/foo").and_return("foo")
82
+ File.should_receive(:basename).at_least(1).with("extensions/bar").and_return("bar")
83
+ File.should_receive(:exists?).at_least(1).
84
+ with("/project/dir/ext/extensions/foo/foo.file_extension").and_return(true)
85
+ File.should_receive(:exists?).at_least(1).
86
+ with("/project/dir/ext/extensions/bar/bar.file_extension").and_return(true)
87
+ File.should_receive(:exists?).at_least(1).
88
+ with("/project/dir/ext/extensions/foo/foo.o").and_return(true)
89
+ File.should_receive(:exists?).at_least(1).
90
+ with("/project/dir/ext/extensions/bar/bar.o").and_return(true)
91
+ File.should_receive(:exists?).at_least(1).
92
+ with("/project/dir/lib/extensions/foo.file_extension").and_return(true)
93
+ File.should_receive(:exists?).at_least(1).
94
+ with("/project/dir/lib/extensions/bar.file_extension").and_return(true)
95
+ File.should_receive(:exists?).at_least(1).
96
+ with("/project/dir/ext/extensions/foo/Makefile").and_return(true)
97
+ File.should_receive(:exists?).at_least(1).
98
+ with("/project/dir/ext/extensions/bar/Makefile").and_return(true)
99
+
100
+ @actor.should_receive(:rm).with("/project/dir/lib/extensions/foo.file_extension")
101
+ @actor.should_receive(:rm).with("/project/dir/ext/extensions/foo/foo.file_extension")
102
+ @actor.should_receive(:rm).with("/project/dir/ext/extensions/foo/foo.o")
103
+ @actor.should_receive(:rm).with("/project/dir/ext/extensions/foo/Makefile")
104
+ @actor.should_receive(:rm).with("/project/dir/lib/extensions/bar.file_extension")
105
+ @actor.should_receive(:rm).with("/project/dir/ext/extensions/bar/bar.file_extension")
106
+ @actor.should_receive(:rm).with("/project/dir/ext/extensions/bar/bar.o")
107
+ @actor.should_receive(:rm).with("/project/dir/ext/extensions/bar/Makefile")
108
+ @tasks.cleanup
109
+ end
110
+ end
@@ -6,7 +6,7 @@ require File.expand_path("#{dir}/../lib/fjson")
6
6
 
7
7
  context "A nil object" do
8
8
  specify "should convert to json" do
9
- nil.to_json.should == "null"
9
+ nil.to_json.should_eql "null"
10
10
  end
11
11
 
12
12
  specify "to_json should accept any number of arguments" do
@@ -8,7 +8,7 @@ context "An object" do
8
8
  specify "should convert its string representation to json" do
9
9
  obj = Object.new
10
10
  obj_str = obj.to_s
11
- obj.to_json.should == '"' + obj_str + '"'
11
+ obj.to_json.should_eql '"' + obj_str + '"'
12
12
  end
13
13
 
14
14
  specify "to_json should accept any number of arguments" do
@@ -12,3 +12,13 @@ class Object
12
12
  metaclass.__send__(:define_method, sym, &block)
13
13
  end
14
14
  end
15
+
16
+ module Spec
17
+ module Mocks
18
+ class MockHandler
19
+ def __pre_proxied_method_name method_name
20
+ "original_#{method_name.to_s.delete('!').delete('=').delete('?').delete('[').delete('\]')}_before_proxy"
21
+ end
22
+ end
23
+ end
24
+ end
@@ -8,16 +8,11 @@ unless args.include?("-f") || args.include?("--format")
8
8
  end
9
9
  args << $0
10
10
 
11
- $context_runner = ::Spec::Runner::OptionParser.new.create_context_runner(args, false, STDERR, STDOUT)
12
-
13
- at_exit do
14
- unless context_runner.instance_eval {@reporter}.instance_eval {@start_time}
15
- context_runner.run(false)
16
- end
17
- end
11
+ $context_runner = ::Spec::Runner::OptionParser.new.create_context_runner(args, false, STDOUT, STDERR)
18
12
 
19
13
  dir = File.dirname(__FILE__)
20
-
21
14
  Dir["#{dir}/**/*_spec.rb"].each do |file|
22
15
  require File.expand_path(file)
23
16
  end
17
+
18
+ $context_runner.run(false)
@@ -7,7 +7,7 @@ require File.expand_path("#{dir}/../lib/fjson")
7
7
  context "A JSON state" do
8
8
  specify "method from_state should return the passed in object when a state is passed in" do
9
9
  state = JSON::State.new
10
- JSON::State.from_state(state).should == state
10
+ JSON::State.from_state(state).should_eql state
11
11
  end
12
12
 
13
13
  specify "method from_state should return a new state with hash values when a hash is passed in" do
@@ -18,7 +18,7 @@ context "A JSON state" do
18
18
 
19
19
  args = {}
20
20
  shim_state_class.from_state(args)
21
- passed_params.should == args
21
+ passed_params.should_eql args
22
22
  end
23
23
 
24
24
  specify "method from_state should return a new state with default parameters when an object that is not " +
@@ -29,11 +29,10 @@ context "A JSON state" do
29
29
 
30
30
  specify "should initialize its attributes to their defaults" do
31
31
  state = JSON::State.new
32
- state.indent.should == ""
33
- state.space.should == ""
34
- state.object_nl.should == ""
35
- state.array_nl.should == ""
36
- state.instance_eval {@seen}.should ==({})
32
+ state.indent.should_eql ""
33
+ state.space.should_eql ""
34
+ state.object_nl.should_eql ""
35
+ state.array_nl.should_eql ""
37
36
  end
38
37
 
39
38
  specify "should initialize its attributes with passed in values" do
@@ -44,10 +43,10 @@ context "A JSON state" do
44
43
  :array_nl => Object.new
45
44
  }
46
45
  state = JSON::State.new(params)
47
- state.indent.should == params[:indent]
48
- state.space.should == params[:space]
49
- state.object_nl.should == params[:object_nl]
50
- state.array_nl.should == params[:array_nl]
46
+ state.indent.should_eql params[:indent]
47
+ state.space.should_eql params[:space]
48
+ state.object_nl.should_eql params[:object_nl]
49
+ state.array_nl.should_eql params[:array_nl]
51
50
  end
52
51
 
53
52
  specify "should remember objects" do
@@ -6,7 +6,7 @@ require File.expand_path("#{dir}/../lib/fjson")
6
6
 
7
7
  context "A string" do
8
8
  specify "should convert to json" do
9
- "test".to_json.should == '"test"'
9
+ "test".to_json.should_eql '"test"'
10
10
  end
11
11
 
12
12
  specify "to_json should accept any number of arguments" do
@@ -13,6 +13,6 @@ context "String when not supporting unicode and KCODE is not UTF8 json" do
13
13
  specify "should let high values pass through when " +
14
14
  "not supporting unicode and KCODE is not UTF8" do
15
15
  val = [0xcf].pack("U")
16
- JSON.utf8_to_json(val).should == "\303\217"
16
+ JSON.utf8_to_json(val).should_eql "\303\217"
17
17
  end
18
18
  end
@@ -13,6 +13,6 @@ context "String when supporting unicode and KCODE is not utf8 json" do
13
13
  specify "should let high values pass through when " +
14
14
  "supporting unicode and KCODE is not UTF8" do
15
15
  val = [0xcf].pack("U")
16
- JSON.utf8_to_json(val).should == "\303\217"
16
+ JSON.utf8_to_json(val).should_eql "\303\217"
17
17
  end
18
18
  end
@@ -7,61 +7,61 @@ require File.expand_path("#{dir}/../lib/fjson")
7
7
  context "String with latin1 character set Json" do
8
8
  specify 'should format \b' do
9
9
  utf_8_val = [?\b].pack("U")
10
- JSON.utf8_to_json(utf_8_val).should == '\b'
10
+ JSON.utf8_to_json(utf_8_val).should_eql '\b'
11
11
  end
12
12
 
13
13
  specify 'should format \t' do
14
14
  utf_8_val = [?\t].pack("U")
15
- JSON.utf8_to_json(utf_8_val).should == '\t'
15
+ JSON.utf8_to_json(utf_8_val).should_eql '\t'
16
16
  end
17
17
 
18
18
  specify 'should format \n' do
19
19
  utf_8_val = [?\n].pack("U")
20
- JSON.utf8_to_json(utf_8_val).should == '\n'
20
+ JSON.utf8_to_json(utf_8_val).should_eql '\n'
21
21
  end
22
22
 
23
23
  specify 'should format \f' do
24
24
  utf_8_val = [?\f].pack("U")
25
- JSON.utf8_to_json(utf_8_val).should == '\f'
25
+ JSON.utf8_to_json(utf_8_val).should_eql '\f'
26
26
  end
27
27
 
28
28
  specify 'should format \r' do
29
29
  utf_8_val = [?\r].pack("U")
30
- JSON.utf8_to_json(utf_8_val).should == '\r'
30
+ JSON.utf8_to_json(utf_8_val).should_eql '\r'
31
31
  end
32
32
 
33
33
  specify 'should format ?"' do
34
34
  utf_8_val = [?"].pack("U")
35
- JSON.utf8_to_json(utf_8_val).should == '\"'
35
+ JSON.utf8_to_json(utf_8_val).should_eql '\"'
36
36
  end
37
37
 
38
38
  specify 'should format ?\\' do
39
39
  utf_8_val = [?\\].pack("U")
40
- JSON.utf8_to_json(utf_8_val).should == '\\\\'
40
+ JSON.utf8_to_json(utf_8_val).should_eql '\\\\'
41
41
  end
42
42
 
43
43
  specify "should format values between 0x00 and 0x1f" do
44
44
  utf_8_val = [0x0f].pack("U")
45
- JSON.utf8_to_json(utf_8_val).should == '\\u000f'
45
+ JSON.utf8_to_json(utf_8_val).should_eql '\\u000f'
46
46
  utf_8_val = [0x1e].pack("U")
47
- JSON.utf8_to_json(utf_8_val).should == '\\u001e'
47
+ JSON.utf8_to_json(utf_8_val).should_eql '\\u001e'
48
48
  end
49
49
 
50
50
  specify "should let ordinary text pass through" do
51
- JSON.utf8_to_json("test").should == "test"
52
- JSON.utf8_to_json('1').should == '1'
51
+ JSON.utf8_to_json("test").should_eql "test"
52
+ JSON.utf8_to_json('1').should_eql '1'
53
53
  end
54
54
 
55
55
  specify "should support backslashes" do
56
56
  json = '"\\\\.(?i:gif|jpe?g|png)$"'
57
57
  data = JSON.parse(json)
58
- JSON.unparse(data).should == json
58
+ JSON.unparse(data).should_eql json
59
59
  json = '"\\""'
60
60
  data = JSON.parse(json)
61
- JSON.unparse(data).should == json
61
+ JSON.unparse(data).should_eql json
62
62
  json = '"\/"'
63
63
  data = JSON.parse(json)
64
- data.should == '/'
65
- JSON.unparse(data).should == json
64
+ data.should_eql '/'
65
+ JSON.unparse(data).should_eql json
66
66
  end
67
67
  end
@@ -12,42 +12,42 @@ context "String with UTF8 values when supporting unicode Json" do
12
12
 
13
13
  specify "should format values between 0x00000080 and 0x000007ff" do
14
14
  val = [0x0080].pack("U")
15
- JSON.utf8_to_json(val).should == "\\u0080"
15
+ JSON.utf8_to_json(val).should_eql "\\u0080"
16
16
 
17
17
  val = [0x07ff].pack("U")
18
- JSON.utf8_to_json(val).should == "\\u07ff"
18
+ JSON.utf8_to_json(val).should_eql "\\u07ff"
19
19
  end
20
20
 
21
21
  specify "should format values between 0x00001000 and 0x0000ffff" do
22
22
  val = [0x1000].pack("U")
23
- JSON.utf8_to_json(val).should == "\\u1000"
23
+ JSON.utf8_to_json(val).should_eql "\\u1000"
24
24
 
25
25
  val = [0xffff].pack("U")
26
- JSON.utf8_to_json(val).should == "\\uffff"
26
+ JSON.utf8_to_json(val).should_eql "\\uffff"
27
27
  end
28
28
 
29
29
  specify "should format values between 0x00010000 and 0x0010ffff" do
30
30
  val = [0x010000].pack("U")
31
- JSON.utf8_to_json(val).should == "\\ud800dc00"
31
+ JSON.utf8_to_json(val).should_eql "\\ud800dc00"
32
32
 
33
33
  val = [0x10ffff].pack("U")
34
- JSON.utf8_to_json(val).should == "\\udbffdfff"
34
+ JSON.utf8_to_json(val).should_eql "\\udbffdfff"
35
35
  end
36
36
 
37
37
  specify "should parse unicode values" do
38
38
  utf8 = '© ≠ €!'
39
39
  json = '"\u00a9 \u2260 \u20ac!"'
40
- utf8.to_json.should == json
41
- JSON.parse(json).should == utf8
40
+ utf8.to_json.should_eql json
41
+ JSON.parse(json).should_eql utf8
42
42
 
43
43
  utf8 = "\343\201\202\343\201\204\343\201\206\343\201\210\343\201\212"
44
44
  json = '"\u3042\u3044\u3046\u3048\u304a"'
45
- utf8.to_json.should == json
46
- JSON.parse(json).should == utf8
45
+ utf8.to_json.should_eql json
46
+ JSON.parse(json).should_eql utf8
47
47
 
48
48
  utf8 = 'საქართველო'
49
49
  json = '"\u10e1\u10d0\u10e5\u10d0\u10e0\u10d7\u10d5\u10d4\u10da\u10dd"'
50
- utf8.to_json.should == json
51
- JSON.parse(json).should == utf8
50
+ utf8.to_json.should_eql json
51
+ JSON.parse(json).should_eql utf8
52
52
  end
53
53
  end