File: PrintInteger.swift

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (162 lines) | stat: -rw-r--r-- 4,535 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
150
151
152
153
154
155
156
157
158
159
160
161
162
// RUN: %target-run-simple-swift
// REQUIRES: executable_test
// REQUIRES: reflection

import StdlibUnittest


let PrintTests = TestSuite("PrintInteger")
PrintTests.test("CustomStringConvertible") {
  func hasDescription(_ any: Any) {
    expectTrue(any is CustomStringConvertible)
  }

  hasDescription(Int(42))
  hasDescription(UInt(42))

  hasDescription(Int8(-42))
  hasDescription(Int16(-42))
  hasDescription(Int32(-42))
  hasDescription(Int64(-42))
  hasDescription(UInt8(42))
  hasDescription(UInt16(42))
  hasDescription(UInt32(42))
  hasDescription(UInt64(42))

  hasDescription(CChar(42))
  hasDescription(CUnsignedChar(42))
  hasDescription(CUnsignedShort(42))
  hasDescription(CUnsignedInt(42))
  hasDescription(CUnsignedLong(42))
  hasDescription(CUnsignedLongLong(42))
  hasDescription(CSignedChar(42))
  hasDescription(CShort(42))
  hasDescription(CInt(42))
  hasDescription(CLong(42))
  hasDescription(CLongLong(42))
#if os(Windows)
  hasDescription(CWideChar(exactly: 42)!)
#else
  hasDescription(CWideChar(42)!)
#endif
  hasDescription(CChar16(42))
  hasDescription(CChar32(42)!)
}

PrintTests.test("Printable") {
  expectPrinted("42", CChar(42))
  expectPrinted("42", CUnsignedChar(42))
  expectPrinted("42", CUnsignedShort(42))
  expectPrinted("42", CUnsignedInt(42))
  expectPrinted("42", CUnsignedLong(42))
  expectPrinted("42", CUnsignedLongLong(42))
  expectPrinted("42", CSignedChar(42))
  expectPrinted("42", CShort(42))
  expectPrinted("42", CInt(42))
  expectPrinted("42", CLong(42))
  expectPrinted("42", CLongLong(42))
#if os(Windows)
  expectPrinted("42", CWideChar(exactly: 42)!)
#else
  expectPrinted("*", CWideChar(42)!)
#endif
  expectPrinted("42", CChar16(42))
  expectPrinted("*", CChar32(42)!)

  if (UInt64(Int.max) > 0x1_0000_0000 as UInt64) {
    expectPrinted("-9223372036854775808", Int.min)
    expectPrinted("9223372036854775807", Int.max)
  } else {
    expectPrinted("-2147483648", Int.min)
    expectPrinted("2147483647", Int.max)
  }
  
  expectPrinted("0", Int(0))
  expectPrinted("42", Int(42))
  expectPrinted("-42", Int(-42))
  
  if (UInt64(UInt.max) > 0x1_0000_0000 as UInt64) {
    expectPrinted("18446744073709551615", UInt.max)
  } else {
    expectPrinted("4294967295", UInt.max)
  }
  
  expectPrinted("0", UInt.min)
  expectPrinted("0", UInt(0))
  expectPrinted("42", UInt(42))
  
  expectPrinted("-128", Int8.min)
  expectPrinted("127", Int8.max)
  expectPrinted("0", Int8(0))
  expectPrinted("42", Int8(42))
  expectPrinted("-42", Int8(-42))
  
  expectPrinted("0", UInt8.min)
  expectPrinted("255", UInt8.max)
  expectPrinted("0", UInt8(0))
  expectPrinted("42", UInt8(42))
  
  expectPrinted("-32768", Int16.min)
  expectPrinted("32767", Int16.max)
  expectPrinted("0", Int16(0))
  expectPrinted("42", Int16(42))
  expectPrinted("-42", Int16(-42))
  
  expectPrinted("0", UInt16.min)
  expectPrinted("65535", UInt16.max)
  expectPrinted("0", UInt16(0))
  expectPrinted("42", UInt16(42))
  
  expectPrinted("-2147483648", Int32.min)
  expectPrinted("2147483647", Int32.max)
  expectPrinted("0", Int32(0))
  expectPrinted("42", Int32(42))
  expectPrinted("-42", Int32(-42))
  
  expectPrinted("0", UInt32.min)
  expectPrinted("4294967295", UInt32.max)
  expectPrinted("0", UInt32(0))
  expectPrinted("42", UInt32(42))
  
  expectPrinted("-9223372036854775808", Int64.min)
  expectPrinted("9223372036854775807", Int64.max)
  expectPrinted("0", Int64(0))
  expectPrinted("42", Int64(42))
  expectPrinted("-42", Int64(-42))
  
  expectPrinted("0", UInt64.min)
  expectPrinted("18446744073709551615", UInt64.max)
  expectPrinted("0", UInt64(0))
  expectPrinted("42", UInt64(42))
  
  expectPrinted("-42", Int8(-42))
  expectPrinted("-42", Int16(-42))
  expectPrinted("-42", Int32(-42))
  expectPrinted("-42", Int64(-42))
  expectPrinted("42", UInt8(42))
  expectPrinted("42", UInt16(42))
  expectPrinted("42", UInt32(42))
  expectPrinted("42", UInt64(42))

  expectPrinted("42", CChar(42))
  expectPrinted("42", CUnsignedChar(42))
  expectPrinted("42", CUnsignedShort(42))
  expectPrinted("42", CUnsignedInt(42))
  expectPrinted("42", CUnsignedLong(42))
  expectPrinted("42", CUnsignedLongLong(42))
  expectPrinted("42", CSignedChar(42))
  expectPrinted("42", CShort(42))
  expectPrinted("42", CInt(42))
  expectPrinted("42", CLong(42))
  expectPrinted("42", CLongLong(42))

#if os(Windows)
  expectPrinted("42", CWideChar(exactly: 42)!)
#else
  expectPrinted("*", CWideChar(42)!)
#endif
  expectPrinted("42", CChar16(42))
  expectPrinted("*", CChar32(42)!)
}

runAllTests()