Sha256: 6498bd2886cf97017178acd140696df09eda9f77023a89bd80471b81876c08b1

Contents?: true

Size: 1.93 KB

Versions: 17

Compression:

Stored size: 1.93 KB

Contents

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

class TryTest < Johnson::NodeTestCase
  def test_try_finally
    assert_sexp([[:try,
        [[:var, [[:assign, [:name, "x"], [:lit, 10]]]]],
        nil,
        [[:var, [[:assign, [:name, "x"], [:lit, 20]]]]]
      ]],
      @parser.parse('try { var x = 10; } finally { var x = 20; }'))
    assert_ecma(
      "try {\n  var x = 10;\n} finally {\n  var x = 20;\n}",
      @parser.parse('try { var x = 10; } finally { var x = 20; }'))
  end

  def test_try_catch
    assert_sexp([
    [:try,
      [[:var, [[:assign, [:name, "x"], [:lit, 10]]]]],
      [[:catch, [:name, "a"], nil,
      [
        [:var, [[:assign, [:name, "x"], [:lit, 20]]]],
        [:postfix_inc, [:name, "x"]]
      ]
      ]],
    nil]],
    @parser.parse('try { var x = 10; } catch(a) { var x = 20; x++; }'))
    assert_ecma("try {\n  var x = 10;\n} catch(a) {\n  var x = 20;\n  x++;\n}",
      @parser.parse('try { var x = 10; } catch(a) { var x = 20; x++; }'))
  end

  def test_try_multi_catch
    assert_sexp([
      [:try,
        [[:var, [[:assign, [:name, "x"], [:lit, 10]]]]],
      [
        [:catch, [:name, "a"], [:true],
        [
          [:var, [[:assign, [:name, "x"], [:lit, 20]]]],
          [:postfix_inc, [:name, "x"]]
        ]],
        [:catch, [:name, "b"], [:true],
        [
          [:var, [[:assign, [:name, "x"], [:lit, 20]]]],
          [:postfix_inc, [:name, "x"]]
        ]]
      ],
      nil]],
      @parser.parse(' try { var x = 10; }
                      catch(a if true) { var x = 20; x++; }
                      catch(b if true) { var x = 20; x++; }
                    '))
    assert_ecma("try {\n  var x = 10;\n} catch(a) {\n  var x = 20;\n  x++;\n} catch(b) {\n  var x = 20;\n  x++;\n}",
      @parser.parse(' try { var x = 10; }
                      catch(a if true) { var x = 20; x++; }
                      catch(b if true) { var x = 20; x++; }
                    '))
  end
end

Version data entries

17 entries across 17 versions & 2 rubygems

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