Skip to content

Commit 854e06e

Browse files
committed
TEST: basic struct! tests
1 parent e564c59 commit 854e06e

File tree

3 files changed

+116
-0
lines changed

3 files changed

+116
-0
lines changed

src/tests/run-tests.r3

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ dt [ ;- delta time
5454
%units/power-test.r3
5555
%units/protect-test.r3
5656
%units/series-test.r3
57+
%units/struct-test.r3
5758
%units/task-test.r3
5859
%units/time-test.r3
5960
%units/tuple-test.r3

src/tests/units/lexer-test.r3

+1
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ Rebol [
349349
--assert "b" = load {#[string! "ab" 2]}
350350
--assert %ab = load {#[file! "ab"]}
351351
--assert %b = load {#[file! "ab" 2]}
352+
--assert struct? load {#[struct! []]}
352353
;@@ https://github.com/Oldes/Rebol-issues/issues/1034
353354
--assert error? try [load {#[string! "ab" 2 x]}]
354355
--assert error? try [load {#[file! "ab" x]}]

src/tests/units/struct-test.r3

+114
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
Rebol [
2+
Title: "Rebol struct test script"
3+
Author: "Oldes"
4+
File: %struct-test.r3
5+
Tabs: 4
6+
Needs: [%../quick-test-module.r3]
7+
]
8+
9+
~~~start-file~~~ "STRUCT"
10+
11+
===start-group=== "Struct single value construction"
12+
--assert not error? try [
13+
i8: make struct! [a [int8!]]
14+
i16: make struct! [a [int16!]]
15+
i32: make struct! [a [int32!]]
16+
i64: make struct! [a [int64!]]
17+
u8: make struct! [a [uint8!]]
18+
u16: make struct! [a [uint16!]]
19+
u32: make struct! [a [uint32!]]
20+
u64: make struct! [a [uint64!]]
21+
f32: make struct! [a [float!]]
22+
f64: make struct! [a [double!]]
23+
]
24+
--assert 1 = length? i8
25+
--assert 2 = length? i16
26+
--assert 4 = length? i32
27+
--assert 8 = length? i64
28+
--assert 1 = length? u8
29+
--assert 2 = length? u16
30+
--assert 4 = length? u32
31+
--assert 8 = length? u64
32+
--assert 4 = length? f32
33+
--assert 8 = length? f64
34+
--assert (mold i8 ) = "make struct! [a: [int8!] 0]"
35+
--assert (mold i16) = "make struct! [a: [int16!] 0]"
36+
--assert (mold i32) = "make struct! [a: [int32!] 0]"
37+
--assert (mold i64) = "make struct! [a: [int64!] 0]"
38+
--assert (mold u8 ) = "make struct! [a: [uint8!] 0]"
39+
--assert (mold u16) = "make struct! [a: [uint16!] 0]"
40+
--assert (mold u32) = "make struct! [a: [uint32!] 0]"
41+
--assert (mold u64) = "make struct! [a: [uint64!] 0]"
42+
--assert (mold f32) = "make struct! [a: [float!] 0.0]"
43+
--assert (mold f64) = "make struct! [a: [double!] 0.0]"
44+
===end-group===
45+
46+
47+
===start-group=== "Struct single value (dimensional) construction"
48+
--assert not error? try [
49+
i8x2: make struct! [a [int8! [2]]]
50+
i16x2: make struct! [a [int16! [2]]]
51+
i32x2: make struct! [a [int32! [2]]]
52+
i64x2: make struct! [a [int64! [2]]]
53+
u8x2: make struct! [a [uint8! [2]]]
54+
u16x2: make struct! [a [uint16! [2]]]
55+
u32x2: make struct! [a [uint32! [2]]]
56+
u64x2: make struct! [a [uint64! [2]]]
57+
f32x2: make struct! [a [float! [2]]]
58+
f64x2: make struct! [a [double! [2]]]
59+
]
60+
--assert [a [int8! [2]]] = spec-of i8x2
61+
--assert [a [int16! [2]]] = spec-of i16x2
62+
--assert [a [int32! [2]]] = spec-of i32x2
63+
--assert [a [int64! [2]]] = spec-of i64x2
64+
--assert [a [uint8! [2]]] = spec-of u8x2
65+
--assert [a [uint16! [2]]] = spec-of u16x2
66+
--assert [a [uint32! [2]]] = spec-of u32x2
67+
--assert [a [uint64! [2]]] = spec-of u64x2
68+
--assert [a [float! [2]]] = spec-of f32x2
69+
--assert [a [double! [2]]] = spec-of f64x2
70+
71+
--assert 2 = length? i8x2
72+
--assert 4 = length? i16x2
73+
--assert 8 = length? i32x2
74+
--assert 16 = length? i64x2
75+
--assert 2 = length? u8x2
76+
--assert 4 = length? u16x2
77+
--assert 8 = length? u32x2
78+
--assert 16 = length? u64x2
79+
--assert 8 = length? f32x2
80+
--assert 16 = length? f64x2
81+
--assert (mold i8x2 ) = "make struct! [a: [int8! [2]] [0 0]]"
82+
--assert (mold i16x2) = "make struct! [a: [int16! [2]] [0 0]]"
83+
--assert (mold i32x2) = "make struct! [a: [int32! [2]] [0 0]]"
84+
--assert (mold i64x2) = "make struct! [a: [int64! [2]] [0 0]]"
85+
--assert (mold u8x2 ) = "make struct! [a: [uint8! [2]] [0 0]]"
86+
--assert (mold u16x2) = "make struct! [a: [uint16! [2]] [0 0]]"
87+
--assert (mold u32x2) = "make struct! [a: [uint32! [2]] [0 0]]"
88+
--assert (mold u64x2) = "make struct! [a: [uint64! [2]] [0 0]]"
89+
--assert (mold f32x2) = "make struct! [a: [float! [2]] [0.0 0.0]]"
90+
--assert (mold f64x2) = "make struct! [a: [double! [2]] [0.0 0.0]]"
91+
===end-group===
92+
93+
i8:
94+
i16:
95+
i32:
96+
i64:
97+
u8:
98+
u16:
99+
u32:
100+
u64:
101+
f32:
102+
f64:
103+
i8x2:
104+
i16x2:
105+
i32x2:
106+
i64x2:
107+
u8x2:
108+
u16x2:
109+
u32x2:
110+
u64x2:
111+
f32x2:
112+
f64x2: none
113+
114+
~~~end-file~~~

0 commit comments

Comments
 (0)