File: json_encoder.rb

package info (click to toggle)
coderay 1.1.3-8
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,368 kB
  • sloc: ruby: 9,987; makefile: 14; sh: 4; python: 1
file content (28 lines) | stat: -rw-r--r-- 901 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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