require 'test/yarvtest'

# test of syntax
class TestMassign < YarvTestBase
  def test_simle
    ae %q{
      a = :a; b = :b; c = :c
      x, y = a, b
      [x, y]
    }
    ae %q{
      a = :a; b = :b; c = :c
      x, y, z = a, b, c
      [x, y, z]
    }
  end

  def test_diff_elems
    ae %q{
      a = :a ; b = :b ; c = :c
      x, y, z = a, b
      [x, y, z]
    }
    ae %q{
      a = :a; b = :b; c = :c
      x, y = a, b, c
      [x, y]
    }
  end

  def test_single_l
    ae %q{
      a = :a; b = :b
      x = a, b
      x
    }
    ae %q{
      a = [1, 2]; b = [3, 4]
      x = a, b
      x
    }
  end

  def test_single_r
    ae %q{
      a = :a
      x, y = a
      [x, y]
    }
    ae %q{
      a = [1, 2]
      x, y = a
      [x, y]
    }
    ae %q{
      a = [1, 2, 3]
      x, y = a
      [x, y]
    }
  end
  
  def test_splat_l
    ae %q{
      a = :a; b = :b; c = :c
      *x = a, b
      [x]
    }
    ae %q{
      a = :a; b = :b; c = :c
      *x = a, b
      [x]
    }
    ae %q{
      a = :a; b = :b; c = :c
      x, * = a, b
      [x]
    }
    ae %q{
      a = :a; b = :b; c = :c
      x, *y = a, b
      [x, y]
    }
    ae %q{
      a = :a; b = :b; c = :c
      x, y, *z = a, b
      [x, y]
    }
  end

  def test_splat_r
    ae %q{
      a = :a; b = :b; c = :c
      x, y = *a
      [x, y]
    }
    ae %q{
      a = :a; b = :b; c = :c
      x, y = a, *b
      [x, y]
    }
    ae %q{
      a = :a; b = :b; c = :c
      x, y = a, b, *c
      [x, y]
    }

    ae %q{
      a = [:a, :a2]; b = [:b, :b2]; c = [:c, :c2]
      x, y = *a
      [x, y]
    }
    ae %q{
      a = [:a, :a2]; b = [:b, :b2]; c = [:c, :c2]
      x, y = a, *b
      [x, y]
    }
    ae %q{
      a = [:a, :a2]; b = [:b, :b2]; c = [:c, :c2]
      x, y = a, b, *c
      [x, y]
    }
  end

  def test_splat_b1
    ae %q{
      a = :a; b = :b; c = :c
      x, *y = *a
      [x, y]
    }
    ae %q{
      a = :a; b = :b; c = :c
      x, *y = a, *b
      [x, y]
    }
    ae %q{
      a = :a; b = :b; c = :c
      x, *y = a, b, *c
      [x, y]
    }

    ae %q{
      a = [:a, :a2]; b = [:b, :b2]; c = [:c, :c2]
      x, *y = *a
      [x, y]
    }
    ae %q{
      a = [:a, :a2]; b = [:b, :b2]; c = [:c, :c2]
      x, *y = a, *b
      [x, y]
    }
    ae %q{
      a = [:a, :a2]; b = [:b, :b2]; c = [:c, :c2]
      x, *y = a, b, *c
      [x, y]
    }
  end

  def test_splat_b2
    ae %q{
      a = :a; b = :b; c = :c
      *x = *a
      x
    }
    ae %q{
      a = :a; b = :b; c = :c
      *x = a, *b
      x
    }
    ae %q{
      a = :a; b = :b; c = :c
      *x = a, b, *c
      x
    }

    ae %q{
      a = [:a, :a2]; b = [:b, :b2]; c = [:c, :c2]
      *x = *a
      x
    }
    ae %q{
      a = [:a, :a2]; b = [:b, :b2]; c = [:c, :c2]
      *x = a, *b
      x
    }
    ae %q{
      a = [:a, :a2]; b = [:b, :b2]; c = [:c, :c2]
      *x = a, b, *c
      x
    }
  end

  def test_toary
    ae %q{
      x, y = :a
      [x, y]
    }
    ae %q{
      x, y = [1, 2]
      [x, y]
    }
    ae %q{
      x, y = [1, 2, 3]
      [x, y]
    }
  end

  def test_swap
    ae %q{
      a = 1; b = 2
      a, b = b, a
      [a, b]
    }
  end
  
  def test_mret
    ae %q{
      def m
        return 1, 2
      end

      a, b = m
      [a, b]
    }
    ae %q{
      def m
        return 1, 2
      end

      a = m
      [a]
    }
    ae %q{
      def m
        return 1
      end

      a, b = m
      [a, b]
    }
  end

  def test_mret_splat
    ae %q{
      def m
        return *1
      end
      a, b = m
      [a, b]
    }
    ae %q{
      def m
        return *[]
      end
      a, b = m
      [a, b]
    }
    ae %q{
      def m
        return *[1]
      end
      a, b = m
      [a, b]
    }
    ae %q{
      def m
        return *[1,2]
      end
      a, b = m
      [a, b]
    }
    ae %q{
      def m
        return *[1,2,3]
      end
      a, b = m
      [a, b]
    }
  end

  def test_mret_argscat
    ae %q{
      def m
        return 1, *[]
      end
      a, b = m
      [a, b]
    }
    ae %q{
      def m
        return 1, 2, *[1]
      end
      a, b = m
      [a, b]
    }
    ae %q{
      def m
        return 1, 2, 3, *[1,2]
      end
      a, b = m
      [a, b]
    }
  end
  
end


