Sha256: 10d6680603b0ae2a76b8b51f5264e6c868bb5ecd28853d1af5ef21b408ba6579

Contents?: true

Size: 1.72 KB

Versions: 17

Compression:

Stored size: 1.72 KB

Contents

require File.expand_path(File.join(File.dirname(__FILE__), "/../../helper"))

class SwitchTest < Johnson::NodeTestCase
  def test_empty_switch
    assert_sexp([[:switch, [:name, "o"], []]],
                @parser.parse('switch(o) { }')
               )
    assert_ecma('switch(o) {  }',
                @parser.parse('switch(o) { }')
               )
  end

  def test_switch_with_body
    assert_sexp([[:switch, [:name, "o"],
                [
                  [:case, [:name, "j"], [[:name, "foo"]]]
                ]
      ]], @parser.parse('switch(o) { case j: foo; }')
    )
    assert_ecma("switch(o) {\n  case j: {\n    foo;\n}\n}",
                @parser.parse('switch(o) { case j: foo; }')
               )
  end

  def test_switch_empty_case
    assert_ecma("switch(o) {\n  case j: {  }\n}",
                @parser.parse('switch(o) { case j: }')
               )
  end

  def test_switch_with_body_2_case
    assert_sexp([[:switch, [:name, "o"],
                [
                  [:case, [:name, "j"], [[:name, "foo"]]],
                  [:case, [:name, "k"], [[:name, "bar"]]]
                ]
      ]], @parser.parse('switch(o) { case j: foo; case k: bar; }')
    )
  end

  def test_switch_with_default
    assert_sexp([[:switch, [:name, "o"], [[:default, nil, [[:name, "bar"]]]]]],
                @parser.parse('switch(o) { default: bar; }')
    )
    assert_ecma("switch(o) {\n  default: {\n    bar;\n}\n}",
                @parser.parse('switch(o) { default: bar; }')
               )
    assert_sexp([[:switch, [:name, "o"], [[:default, nil, []]]]],
                @parser.parse('switch(o) { default: }')
    )
    assert_ecma("switch(o) {\n  default: {  }\n}",
                @parser.parse('switch(o) { default: }')
    )
  end
end

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
jbarnette-johnson-1.0.0.200806240111 test/johnson/nodes/switch_test.rb
jbarnette-johnson-1.0.0.200807291507 test/johnson/nodes/switch_test.rb
jbarnette-johnson-1.0.0.200808062051 test/johnson/nodes/switch_test.rb
jbarnette-johnson-1.0.0.200808062111 test/johnson/nodes/switch_test.rb
jbarnette-johnson-1.0.0.200811251942 test/johnson/nodes/switch_test.rb
jbarnette-johnson-1.0.0.20081126120511 test/johnson/nodes/switch_test.rb
jbarnette-johnson-1.0.0.20090127202936 test/johnson/nodes/switch_test.rb
jbarnette-johnson-1.0.0.20090225110820 test/johnson/nodes/switch_test.rb
jbarnette-johnson-1.0.0.20090326122910 test/johnson/nodes/switch_test.rb
jbarnette-johnson-1.0.0.20090326154650 test/johnson/nodes/switch_test.rb
jbarnette-johnson-1.0.0.20090326161333 test/johnson/nodes/switch_test.rb
jbarnette-johnson-1.0.0.20090402144841 test/johnson/nodes/switch_test.rb
jbarnette-johnson-1.0.0.20090402155420 test/johnson/nodes/switch_test.rb
johnson-1.2.0 test/johnson/nodes/switch_test.rb
johnson-1.1.1 test/johnson/nodes/switch_test.rb
johnson-1.1.2 test/johnson/nodes/switch_test.rb
johnson-1.1.0 test/johnson/nodes/switch_test.rb