aboutsummaryrefslogtreecommitdiff
path: root/tests/internal/test_global_any.odin
blob: 850884912991bf384e4757cc7b19082e9a1031ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package test_internal

@(private="file")
global_any_from_proc: any = from_proc()

from_proc :: proc "contextless" () -> f32 {
	return 1.1
}

@(private="file")
global_any: any = 1

import "core:testing"

@(test)
test_global_any :: proc(t: ^testing.T) {
	as_f32, is_f32 := global_any_from_proc.(f32)
	testing.expect(t, is_f32 == true)
	testing.expect(t, as_f32 == 1.1)

	as_int, is_int := global_any.(int)
	testing.expect(t, is_int == true)
	testing.expect(t, as_int == 1)
}

@(test)
test_static_any :: proc(t: ^testing.T) {
	@(static)
	var: any = 3

	as_int, is_int := var.(int)
	testing.expect(t, is_int == true)
	testing.expect(t, as_int == 3)

	var = f32(1.1)

	as_f32, is_f32 := var.(f32)
	testing.expect(t, is_f32 == true)
	testing.expect(t, as_f32 == 1.1)
}