-
Notifications
You must be signed in to change notification settings - Fork 10.4k
/
Copy pathInputStream.swift.gyb
148 lines (123 loc) · 4.24 KB
/
InputStream.swift.gyb
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
//===--- InputStream.swift.gyb --------------------------------*- swift -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
// -*- swift -*-
// RUN: %target-run-simple-swiftgyb
// REQUIRES: executable_test
// UNSUPPORTED: freestanding
// UNSUPPORTED: OS=wasi
import StdlibUnittest
import Swift
var ReadLineTestSuite = TestSuite("ReadLine")
% for strip_newline in ['false', 'true']:
% newline = '' if strip_newline == 'true' else '\\n'
ReadLineTestSuite.test("EmptyLine/strippingNewline=${strip_newline}")
.stdin("\n")
.code {
expectEqual("${newline}", readLine(strippingNewline: ${strip_newline}))
}
ReadLineTestSuite.test("Whitespace/strippingNewline=${strip_newline}")
.stdin(" \t\u{0b}\u{0c}\u{85}\u{2028}\u{2029}\n")
.code {
expectEqual(
" \t\u{0b}\u{0c}\u{85}\u{2028}\u{2029}${newline}",
readLine(strippingNewline: ${strip_newline}))
}
ReadLineTestSuite.test("ASCII/length=1/strippingNewline=${strip_newline}")
.stdin("a\n")
.code {
expectEqual("a${newline}", readLine(strippingNewline: ${strip_newline}))
}
ReadLineTestSuite.test("ASCII/length=2/strippingNewline=${strip_newline}")
.stdin("ab\n")
.code {
expectEqual("ab${newline}", readLine(strippingNewline: ${strip_newline}))
}
ReadLineTestSuite.test("ASCII/length=3/strippingNewline=${strip_newline}")
.stdin("abc\n")
.code {
expectEqual("abc${newline}", readLine(strippingNewline: ${strip_newline}))
}
ReadLineTestSuite.test("Unicode/strippingNewline=${strip_newline}")
// U+0065 LATIN SMALL LETTER E
// U+00A9 COPYRIGHT SIGN
// U+0521 CYRILLIC SMALL LETTER EL WITH MIDDLE HOOK
// U+304B HIRAGANA LETTER KA
// U+3099 COMBINING KATAKANA-HIRAGANA VOICED SOUND MARK
// U+4587 CJK UNIFIED IDEOGRAPH-4587
// U+1F425 FRONT-FACING BABY CHICK
.stdin("\u{0065}\u{00a9}\u{0521}\u{304b}\u{3099}\u{4587}\u{1f425}\u{10b9c4}\n")
.code {
expectEqual(
"\u{0065}\u{00a9}\u{0521}\u{304b}\u{3099}\u{4587}\u{1f425}\u{10b9c4}${newline}",
readLine(strippingNewline: ${strip_newline}))
}
ReadLineTestSuite.test("EOF/1/strippingNewline=${strip_newline}")
.stdin("", eof: true)
.code {
expectNil(readLine(strippingNewline: ${strip_newline}))
}
ReadLineTestSuite.test("EOF/2/strippingNewline=${strip_newline}")
.stdin("abcd 123\n", eof: true)
.code {
expectEqual("abcd 123${newline}", readLine(strippingNewline: ${strip_newline}))
expectNil(readLine(strippingNewline: ${strip_newline}))
}
ReadLineTestSuite.test("MissingNewlineAtEOF/1/strippingNewline=${strip_newline}")
.stdin("a", eof: true)
.code {
expectEqual("a", readLine(strippingNewline: ${strip_newline}))
}
ReadLineTestSuite.test("MissingNewlineAtEOF/2/strippingNewline=${strip_newline}")
.stdin("abcd 123", eof: true)
.code {
expectEqual("abcd 123", readLine(strippingNewline: ${strip_newline}))
}
% end
ReadLineTestSuite.test("strippingNewline=default")
.stdin("abcd 123\n")
.code {
// Check that the default for strippingNewline is true.
expectEqual("abcd 123", readLine())
}
ReadLineTestSuite.test("StripNewline/JustCR")
.stdin("\r", eof: true)
.code {
// FIXME: CR by itself is not recognized as a newline.
expectEqual("\r", readLine(strippingNewline: true))
}
ReadLineTestSuite.test("StripNewline/JustLF")
.stdin("\n")
.code {
expectEqual("", readLine(strippingNewline: true))
}
ReadLineTestSuite.test("StripNewline/JustCR+LF")
.stdin("\r\n")
.code {
expectEqual("", readLine(strippingNewline: true))
}
ReadLineTestSuite.test("StripNewline/CR")
.stdin("abcd 123\r", eof: true)
.code {
// FIXME: CR by itself is not recognized as a newline.
expectEqual("abcd 123\r", readLine(strippingNewline: true))
}
ReadLineTestSuite.test("StripNewline/LF")
.stdin("abcd 123\n")
.code {
expectEqual("abcd 123", readLine(strippingNewline: true))
}
ReadLineTestSuite.test("StripNewline/CR+LF")
.stdin("abcd 123\r\n")
.code {
expectEqual("abcd 123", readLine(strippingNewline: true))
}
runAllTests()