summaryrefslogtreecommitdiff
path: root/test/unit/json.rb
diff options
context:
space:
mode:
authormurphy <murphy@rubychan.de>2010-06-29 06:32:30 +0000
committermurphy <murphy@rubychan.de>2010-06-29 06:32:30 +0000
commit93dfad17309f46d00d1043592efdb282d13963fe (patch)
tree60cbfc2fbc3497f95f5d02de1e9ec8c7b10515ff /test/unit/json.rb
parent87764c224cc8c808688e83d7c1f93c8dbbbd9b4f (diff)
downloadcoderay-93dfad17309f46d00d1043592efdb282d13963fe.tar.gz
Added lots of unit tests.
Theses actually come from the library files; now they are included. Also, rake test and test:all don't test the scanners now; you have to start them using rake test:scanners.
Diffstat (limited to 'test/unit/json.rb')
-rw-r--r--test/unit/json.rb28
1 files changed, 28 insertions, 0 deletions
diff --git a/test/unit/json.rb b/test/unit/json.rb
new file mode 100644
index 0000000..4e44a64
--- /dev/null
+++ b/test/unit/json.rb
@@ -0,0 +1,28 @@
+require 'test/unit'
+require 'coderay'
+
+class JSONEncoderTest < Test::Unit::TestCase
+
+ def test_json_output
+ old_load_paths = $:.dup
+ begin
+ $:.delete '.'
+ $:.delete File.dirname(__FILE__)
+ json = CodeRay.scan('puts "Hello world!"', :ruby).json
+ assert_equal [
+ {"type"=>"text", "text"=>"puts", "kind"=>"ident"},
+ {"type"=>"text", "text"=>" ", "kind"=>"space"},
+ {"type"=>"block", "action"=>"open", "kind"=>"string"},
+ {"type"=>"text", "text"=>"\"", "kind"=>"delimiter"},
+ {"type"=>"text", "text"=>"Hello world!", "kind"=>"content"},
+ {"type"=>"text", "text"=>"\"", "kind"=>"delimiter"},
+ {"type"=>"block", "action"=>"close", "kind"=>"string"},
+ ], JSON.load(json)
+ ensure
+ for path in old_load_paths - $:
+ $: << path
+ end
+ end
+ end
+
+end \ No newline at end of file