File: tnewlit.nim

package info (click to toggle)
nim 0.19.4-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 462,356 kB
  • sloc: sh: 11,089; ansic: 4,699; makefile: 706; python: 309; sql: 297; asm: 141; xml: 13
file content (149 lines) | stat: -rw-r--r-- 3,550 bytes parent folder | download
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import macros

type
  MyType = object
    a : int
    b : string

macro test_newLit_MyType: untyped =
  let mt = MyType(a: 123, b:"foobar")
  result = newLit(mt)

doAssert test_newLit_MyType == MyType(a: 123, b:"foobar")

macro test_newLit_array: untyped =
  let arr = [1,2,3,4,5]
  result = newLit(arr)

doAssert test_newLit_array == [1,2,3,4,5]

macro test_newLit_seq_int: untyped =
  let s: seq[int] = @[1,2,3,4,5]
  result = newLit(s)

block:
  let tmp: seq[int] = test_newLit_seq_int
  doAssert tmp == @[1,2,3,4,5]

macro test_newLit_seq_int8: untyped =
  let s: seq[int8] = @[1'i8,2,3,4,5]
  result = newLit(s)

block:
  let tmp: seq[int8] = test_newLit_seq_int8
  doAssert tmp == @[1'i8,2,3,4,5]

macro test_newLit_seq_int16: untyped =
  let s: seq[int16] = @[1'i16,2,3,4,5]
  result = newLit(s)

block:
  let tmp: seq[int16] = test_newLit_seq_int16
  doAssert tmp == @[1'i16,2,3,4,5]

macro test_newLit_seq_int32: untyped =
  let s: seq[int32] = @[1'i32,2,3,4,5]
  result = newLit(s)

block:
  let tmp: seq[int32] = test_newLit_seq_int32
  doAssert tmp == @[1'i32,2,3,4,5]

macro test_newLit_seq_int64: untyped =
  let s: seq[int64] = @[1'i64,2,3,4,5]
  result = newLit(s)

block:
  let tmp: seq[int64] = test_newLit_seq_int64
  doAssert tmp == @[1'i64,2,3,4,5]

macro test_newLit_seq_uint: untyped =
  let s: seq[uint] = @[1u,2,3,4,5]
  result = newLit(s)

block:
  let tmp: seq[uint] = test_newLit_seq_uint
  doAssert tmp == @[1u,2,3,4,5]

macro test_newLit_seq_uint8: untyped =
  let s: seq[uint8] = @[1'u8,2,3,4,5]
  result = newLit(s)

block:
  let tmp: seq[uint8] = test_newLit_seq_uint8
  doAssert tmp == @[1'u8,2,3,4,5]

macro test_newLit_seq_uint16: untyped =
  let s: seq[uint16] = @[1'u16,2,3,4,5]
  result = newLit(s)

block:
  let tmp: seq[uint16] = test_newLit_seq_uint16
  doAssert tmp == @[1'u16,2,3,4,5]

macro test_newLit_seq_uint32: untyped =
  let s: seq[uint32] = @[1'u32,2,3,4,5]
  result = newLit(s)

block:
  let tmp: seq[uint32] = test_newLit_seq_uint32
  doAssert tmp == @[1'u32,2,3,4,5]

macro test_newLit_seq_uint64: untyped =
  let s: seq[uint64] = @[1'u64,2,3,4,5]
  result = newLit(s)

block:
  let tmp: seq[uint64] = test_newLit_seq_uint64
  doAssert tmp == @[1'u64,2,3,4,5]

macro test_newLit_seq_float: untyped =
  let s: seq[float] = @[1.0, 2,3,4,5]
  result = newLit(s)

block:
  let tmp: seq[float] = test_newLit_seq_float
  doAssert tmp == @[1.0, 2,3,4,5]

macro test_newLit_seq_float32: untyped =
  let s: seq[float32] = @[1.0'f32, 2,3,4,5]
  result = newLit(s)

block:
  let tmp: seq[float32] = test_newLit_seq_float32
  doAssert tmp == @[1.0'f32, 2,3,4,5]

macro test_newLit_seq_float64: untyped =
  let s: seq[float64] = @[1.0'f64, 2,3,4,5]
  result = newLit(s)

block:
  let tmp: seq[float64] = test_newLit_seq_float64
  doAssert tmp == @[1.0'f64, 2,3,4,5]

macro test_newLit_tuple: untyped =
  let tup: tuple[a:int,b:string] = (a: 123, b: "223")
  result = newLit(tup)

doAssert test_newLit_tuple == (a: 123, b: "223")

type
  ComposedType = object
    mt: MyType
    arr: array[4,int]
    data: seq[byte]

macro test_newLit_ComposedType: untyped =
  let ct = ComposedType(mt: MyType(a: 123, b:"abc"), arr: [1,2,3,4], data: @[1.byte, 3, 7, 127])
  result = newLit(ct)

doAssert test_newLit_ComposedType == ComposedType(mt: MyType(a: 123, b:"abc"), arr: [1,2,3,4], data: @[1.byte, 3, 7, 127])

macro test_newLit_empty_seq_string: untyped =
  var strSeq = newSeq[string](0)
  result = newLit(strSeq)

block:
  # x needs to be of type seq[string]
  var x = test_newLit_empty_seq_string
  x.add("xyz")