Sha256: b4ccef36dad57e9774a422831632ee014eeecd47652975e57037a27405c90202

Contents?: true

Size: 1.6 KB

Versions: 10

Compression:

Stored size: 1.6 KB

Contents

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

class IfTest < Johnson::NodeTestCase
  def test_if_no_else
    assert_sexp([
      [:if, [:and, [:name, "x"], [:name, "y"]],
        [:var, [[:assign, [:name, "foo"], [:lit, 20]]]],
        nil
      ]], @parser.parse('if(x && y) var foo = 20;')
    )
    assert_ecma('if(x && y) var foo = 20;',
      @parser.parse('if(x && y) var foo = 20;')
    )
  end

  def test_if_else
    assert_sexp(
      [[:if, [:and, [:lit, 5], [:lit, 10]],
        [:var, [[:assign, [:name, "foo"], [:lit, 20]]]],
        [:var, [[:assign, [:name, "bar"], [:lit, 5]]]]
      ]],
      [[:if, [:true],
        [:var, [[:assign, [:name, "foo"], [:lit, 20]]]],
        [:var, [[:assign, [:name, "bar"], [:lit, 5]]]]
      ]],
      @parser.parse('if(5 && 10) var foo = 20; else var bar = 5;')
    )
    assert_ecma('if(x && y) var foo = 20; else var bar = 5;',
      @parser.parse('if(x && y) var foo = 20; else var bar = 5;')
    )
  end

  def test_if_else_block
    assert_sexp(
      [[:if, [:and, [:lit, 5], [:lit, 10]],
        [[:var, [[:assign, [:name, "foo"], [:lit, 20]]]]],
        [:var, [[:assign, [:name, "bar"], [:lit, 5]]]]
      ]],
      [[:if, [:true],
        [[:var, [[:assign, [:name, "foo"], [:lit, 20]]]]],
        [:var, [[:assign, [:name, "bar"], [:lit, 5]]]]
      ]],
      @parser.parse('if(5 && 10){ var foo = 20; } else var bar = 5;')
    )
    assert_ecma(
     "if(5 && 10) {\n  var foo = 20;\n} else var bar = 5;",
     "if(true) {\n  var foo = 20;\n} else var bar = 5;",
      @parser.parse('if(5 && 10){ var foo = 20; } else var bar = 5;')
    )
  end
end

Version data entries

10 entries across 10 versions & 4 rubygems

Version Path
johnson19-2.0.0.pre3 test/johnson/generic/nodes/if_test.rb
pre-johnson-2.0.0 test/johnson/generic/nodes/if_test.rb
johnson-2.0.0.pre3 test/johnson/generic/nodes/if_test.rb
johnson-2.0.0.pre2 test/johnson/generic/nodes/if_test.rb
johnson-2.0.0.pre1 test/johnson/generic/nodes/if_test.rb
johnson-2.0.0.pre0 test/johnson/generic/nodes/if_test.rb
smparkes-johnson-1.1.2.6 test/johnson/generic/nodes/if_test.rb
smparkes-johnson-1.1.2.5 test/johnson/generic/nodes/if_test.rb
smparkes-johnson-1.1.2.4 test/johnson/generic/nodes/if_test.rb
smparkes-johnson-1.1.2.3 test/johnson/generic/nodes/if_test.rb