fn match_for_test() { // from for_loops_2_test.v
	mut a := 2
	mut b := 0
	for {
		match a {
			2 {
				println('a == 2')
				a = 0
				continue
			}
			0 {
				println('a == 0')
				a = 5
				b++
				break
			}
			else {
				println('unexpected branch')
				break
			}
		}
	}
	assert a == 5
	assert b == 1
	println(b)
	println(a)
}

fn ifexpr_match_test() { // from if_expr_with_nested_match_expr_test.v
	b := true // this is needed. why?
	a := if b {
		match 5 {
			5 { 0 }
			else { 1 }
		}
	} else {
		3
	}
	assert a == 0
	println(a)
}

fn integer_match_test() { // from match_test.v
	mut a := 3
	mut b := 0
	match a {
		2 {
			println('two')
		}
		3 {
			println('three')
			b = 3
		}
		4 {
			println('four')
		}
		else {
			println('???')
		}
	}
	assert b == 3
	assert match 2 {
		1 { 2 }
		2 { 3 }
		else { 5 }
	} == 3
	assert match 0 {
		1 { 2 }
		2 { 3 }
		else { 5 }
	} == 5
	assert match 1 {
		2 { 0 }
		else { 5 }
	} == 5
	a = 0
	match 2 {
		0 {
			a = 1
		}
		1 {
			a = 2
		}
		else {
			a = 3
		}
	}
	assert a == 3
	a = 0
/*	match 1 {
		0 {
			a = 1
		}
		1 {
			a = 2
			a = a + 2
			a = a + 2
		}
		else {}
	}
	assert a == 6
	a = 0
	match 1 {
		0 {}
		else { a = -2 }
	}
	assert a == -2*/
}

fn multiple_test() { // from match_test.v
	a := 9
	match a {
		1, 2, 3 { println('1-3') }
		4, 5 { println('4-5') }
		6...9 { println('6-9') }
		else { println('other') }
	}
}

enum Foo {
	a
	b
	c = 4 + 8
}

fn get() Foo {
	return .a
}

fn foo(f Foo) {
	match f {
		.a {
			println('a')
		}
		.b {
			println('b')
		}
		.c {
			println('c')
		}
	}
}

fn enum_test() {
	foo(match get() {
		.a { .b }
		.b { .c }
		.c { .a }
	})
}

fn main() {
	match_for_test()
	ifexpr_match_test()
	integer_match_test()
	multiple_test()
	enum_test()
}
