compiler/
kernel/
lib/
examples/
std/
arch/
char/
collections/
lang/
sys/
arch.rad
68 B
char.rad
855 B
collections.rad
39 B
fmt.rad
8.3 KiB
intrinsics.rad
467 B
io.rad
1.7 KiB
lang.rad
276 B
mem.rad
2.3 KiB
sys.rad
179 B
testing.rad
2.4 KiB
tests.rad
15.7 KiB
vec.rad
3.2 KiB
std.rad
281 B
scripts/
seed/
sublime/
test/
vim/
.gitignore
336 B
.gitsigners
112 B
CONTRIBUTING
2.1 KiB
LICENSE
1.1 KiB
Makefile
9.2 KiB
README
2.5 KiB
STYLE
2.5 KiB
std.lib
1.5 KiB
std.lib.test
662 B
lib/std/tests.rad
raw
| 1 | //! Tests for formatting functions. |
| 2 | |
| 3 | use std::fmt; |
| 4 | use std::mem; |
| 5 | use std::vec; |
| 6 | use std::testing; |
| 7 | use std::sys::unix; |
| 8 | use std::io; |
| 9 | |
| 10 | /// Safe I/O and equality accept empty buffers. |
| 11 | @test fn testSafeEmptyBuffers() throws (testing::TestError) { |
| 12 | io::print(""); |
| 13 | io::printError(""); |
| 14 | try testing::expect(unix::write(unix::STDOUT, "") == 0); |
| 15 | try testing::expect(mem::eq("", "")); |
| 16 | } |
| 17 | |
| 18 | // Data types ////////////////////////////////////////////////////////////////// |
| 19 | |
| 20 | record Point: Copy { |
| 21 | x: i32, |
| 22 | y: i32, |
| 23 | } |
| 24 | |
| 25 | // fmt ///////////////////////////////////////////////////////////////////////// |
| 26 | |
| 27 | @test fn testFormatU32Zero() throws (testing::TestError) { |
| 28 | let mut buffer: [u8; 11] = [0; 11]; |
| 29 | let start = fmt::formatU32(0, &mut buffer[..]); |
| 30 | try testing::expect(buffer.len - start == 1); |
| 31 | try testing::expectBytesEq(&buffer[start..], "0"); |
| 32 | } |
| 33 | |
| 34 | @test fn testFormatU32Basic() throws (testing::TestError) { |
| 35 | let mut buffer: [u8; 11] = [0; 11]; |
| 36 | let start = fmt::formatU32(123, &mut buffer[..]); |
| 37 | try testing::expect(buffer.len - start == 3); |
| 38 | try testing::expectBytesEq(&buffer[start..], "123"); |
| 39 | } |
| 40 | |
| 41 | @test fn testFormatU32Large() throws (testing::TestError) { |
| 42 | let mut buffer: [u8; 11] = [0; 11]; |
| 43 | let start = fmt::formatU32(90000, &mut buffer[..]); |
| 44 | try testing::expect(buffer.len - start == 5); |
| 45 | try testing::expectBytesEq(&buffer[start..], "90000"); |
| 46 | } |
| 47 | |
| 48 | @test fn testFormatU32Max() throws (testing::TestError) { |
| 49 | let mut buffer: [u8; 11] = [0; 11]; |
| 50 | let start = fmt::formatU32(4294967295, &mut buffer[..]); |
| 51 | try testing::expect(buffer.len - start == 10); |
| 52 | try testing::expectBytesEq(&buffer[start..], "4294967295"); |
| 53 | } |
| 54 | |
| 55 | @test fn testFormatI32Positive() throws (testing::TestError) { |
| 56 | let mut buffer: [u8; 11] = [0; 11]; |
| 57 | let start = fmt::formatI32(456, &mut buffer[..]); |
| 58 | try testing::expect(buffer.len - start == 3); |
| 59 | try testing::expectBytesEq(&buffer[start..], "456"); |
| 60 | } |
| 61 | |
| 62 | @test fn testFormatI32Negative() throws (testing::TestError) { |
| 63 | let mut buffer: [u8; 11] = [0; 11]; |
| 64 | let start = fmt::formatI32(-789, &mut buffer[..]); |
| 65 | try testing::expect(buffer.len - start == 4); |
| 66 | try testing::expectBytesEq(&buffer[start..], "-789"); |
| 67 | } |
| 68 | |
| 69 | @test fn testFormatI32Zero() throws (testing::TestError) { |
| 70 | let mut buffer: [u8; 11] = [0; 11]; |
| 71 | let start = fmt::formatI32(0, &mut buffer[..]); |
| 72 | try testing::expect(buffer.len - start == 1); |
| 73 | try testing::expectBytesEq(&buffer[start..], "0"); |
| 74 | } |
| 75 | |
| 76 | @test fn testFormatI32Max() throws (testing::TestError) { |
| 77 | let mut buffer: [u8; 11] = [0; 11]; |
| 78 | let start = fmt::formatI32(2147483647, &mut buffer[..]); |
| 79 | try testing::expect(buffer.len - start == 10); |
| 80 | try testing::expectBytesEq(&buffer[start..], "2147483647"); |
| 81 | } |
| 82 | |
| 83 | @test fn testFormatI32Min() throws (testing::TestError) { |
| 84 | let mut buffer: [u8; 11] = [0; 11]; |
| 85 | let start = fmt::formatI32(-2147483648, &mut buffer[..]); |
| 86 | try testing::expect(buffer.len - start == 11); |
| 87 | try testing::expectBytesEq(&buffer[start..], "-2147483648"); |
| 88 | } |
| 89 | |
| 90 | @test fn testFormatU64Zero() throws (testing::TestError) { |
| 91 | let mut buffer: [u8; 20] = [0; 20]; |
| 92 | let start = fmt::formatU64(0, &mut buffer[..]); |
| 93 | try testing::expect(buffer.len - start == 1); |
| 94 | try testing::expectBytesEq(&buffer[start..], "0"); |
| 95 | } |
| 96 | |
| 97 | @test fn testFormatU64Max() throws (testing::TestError) { |
| 98 | let mut buffer: [u8; 20] = [0; 20]; |
| 99 | let start = fmt::formatU64(18446744073709551615, &mut buffer[..]); |
| 100 | try testing::expect(buffer.len - start == 20); |
| 101 | try testing::expectBytesEq(&buffer[start..], "18446744073709551615"); |
| 102 | } |
| 103 | |
| 104 | @test fn testFormatI64Negative() throws (testing::TestError) { |
| 105 | let mut buffer: [u8; 20] = [0; 20]; |
| 106 | let start = fmt::formatI64(-9876543210, &mut buffer[..]); |
| 107 | try testing::expect(buffer.len - start == 11); |
| 108 | try testing::expectBytesEq(&buffer[start..], "-9876543210"); |
| 109 | } |
| 110 | |
| 111 | @test fn testFormatI64Min() throws (testing::TestError) { |
| 112 | let mut buffer: [u8; 20] = [0; 20]; |
| 113 | let start = fmt::formatI64(-9223372036854775808, &mut buffer[..]); |
| 114 | try testing::expect(buffer.len - start == 20); |
| 115 | try testing::expectBytesEq(&buffer[start..], "-9223372036854775808"); |
| 116 | } |
| 117 | |
| 118 | @test fn testParseIntLiteralText() throws (testing::TestError) { |
| 119 | let dec = try fmt::parseInt("123") catch { |
| 120 | throw testing::TestError::Failed; |
| 121 | }; |
| 122 | try testing::expect(dec.magnitude == 123); |
| 123 | try testing::expect(dec.radix == fmt::Radix::Decimal); |
| 124 | |
| 125 | let hex = try fmt::parseInt("0x2a") catch { |
| 126 | throw testing::TestError::Failed; |
| 127 | }; |
| 128 | try testing::expect(hex.magnitude == 42); |
| 129 | try testing::expect(hex.radix == fmt::Radix::Hex); |
| 130 | |
| 131 | let bin = try fmt::parseInt("0b101") catch { |
| 132 | throw testing::TestError::Failed; |
| 133 | }; |
| 134 | try testing::expect(bin.magnitude == 5); |
| 135 | try testing::expect(bin.radix == fmt::Radix::Binary); |
| 136 | } |
| 137 | |
| 138 | @test fn testDigitFromAscii() throws (testing::TestError) { |
| 139 | let zero = fmt::digitFromAscii('0', 10) else throw testing::TestError::Failed; |
| 140 | try testing::expect(zero == 0); |
| 141 | |
| 142 | let nine = fmt::digitFromAscii('9', 10) else throw testing::TestError::Failed; |
| 143 | try testing::expect(nine == 9); |
| 144 | |
| 145 | let lower = fmt::digitFromAscii('a', 16) else throw testing::TestError::Failed; |
| 146 | try testing::expect(lower == 10); |
| 147 | |
| 148 | let lowerF = fmt::digitFromAscii('f', 16) else throw testing::TestError::Failed; |
| 149 | try testing::expect(lowerF == 15); |
| 150 | |
| 151 | let upper = fmt::digitFromAscii('A', 16) else throw testing::TestError::Failed; |
| 152 | try testing::expect(upper == 10); |
| 153 | |
| 154 | let upperF = fmt::digitFromAscii('F', 16) else throw testing::TestError::Failed; |
| 155 | try testing::expect(upperF == 15); |
| 156 | |
| 157 | try testing::expect(fmt::digitFromAscii('g', 16) == nil); |
| 158 | try testing::expect(fmt::digitFromAscii('_', 10) == nil); |
| 159 | } |
| 160 | |
| 161 | @test fn testParseIntLiteralTextErrors() throws (testing::TestError) { |
| 162 | try fmt::parseInt("") catch { |
| 163 | return; |
| 164 | }; |
| 165 | throw testing::TestError::Failed; |
| 166 | } |
| 167 | |
| 168 | @test fn testParseIntLiteralTextRejectsSigns() throws (testing::TestError) { |
| 169 | try fmt::parseInt("-1") catch { |
| 170 | try fmt::parseInt("+1") catch { |
| 171 | return; |
| 172 | }; |
| 173 | }; |
| 174 | throw testing::TestError::Failed; |
| 175 | } |
| 176 | |
| 177 | @test fn testParseIntLiteralTextInvalidDigitErrors() throws (testing::TestError) { |
| 178 | try fmt::parseInt("0b2") catch { |
| 179 | return; |
| 180 | }; |
| 181 | throw testing::TestError::Failed; |
| 182 | } |
| 183 | |
| 184 | @test fn testParseIntLiteralTextOverflowErrors() throws (testing::TestError) { |
| 185 | try fmt::parseInt("18446744073709551616") catch { |
| 186 | return; |
| 187 | }; |
| 188 | throw testing::TestError::Failed; |
| 189 | } |
| 190 | |
| 191 | @test fn testParseCharLiteralText() throws (testing::TestError) { |
| 192 | let x = try fmt::parseChar("'x'") catch { |
| 193 | throw testing::TestError::Failed; |
| 194 | }; |
| 195 | try testing::expect(x == 'x'); |
| 196 | |
| 197 | let newline = try fmt::parseChar("'\\n'") catch { |
| 198 | throw testing::TestError::Failed; |
| 199 | }; |
| 200 | try testing::expect(newline == '\n'); |
| 201 | } |
| 202 | |
| 203 | @test fn testParseCharLiteralTextErrors() throws (testing::TestError) { |
| 204 | try fmt::parseChar("''") catch { |
| 205 | return; |
| 206 | }; |
| 207 | throw testing::TestError::Failed; |
| 208 | } |
| 209 | |
| 210 | @test fn testUnescapeString() throws (testing::TestError) { |
| 211 | let mut buffer: [u8; 8] = [0; 8]; |
| 212 | let len = fmt::unescapeString("a\\n\\0", &mut buffer[..]); |
| 213 | |
| 214 | try testing::expect(len == 3); |
| 215 | try testing::expect(buffer[0] == 'a'); |
| 216 | try testing::expect(buffer[1] == '\n'); |
| 217 | try testing::expect(buffer[2] == 0); |
| 218 | } |
| 219 | |
| 220 | // mem ///////////////////////////////////////////////////////////////////////// |
| 221 | |
| 222 | @test fn testCopyFullSlice() throws (testing::TestError) { |
| 223 | let mut xs: [u8; 3] = [1, 2, 3]; |
| 224 | let mut ys: [u8; 3] = [4, 5, 6]; |
| 225 | |
| 226 | try! mem::copy(&mut xs[..], &ys[..]); |
| 227 | try testing::expectBytesEq(&xs[..], &ys[..]); |
| 228 | try testing::expectBytesEq(&xs[..], &[4, 5, 6]); |
| 229 | } |
| 230 | |
| 231 | @test fn testCopyPartialSlice() throws (testing::TestError) { |
| 232 | let mut xs: [u8; 3] = [1, 2, 3]; |
| 233 | |
| 234 | try! mem::copy(&mut xs[..2], &[8, 9]); |
| 235 | try testing::expectBytesEq(&xs[..], &[8, 9, 3]); |
| 236 | } |
| 237 | |
| 238 | @test fn testCopySingleElement() throws (testing::TestError) { |
| 239 | let mut xs: [u8; 3] = [1, 2, 3]; |
| 240 | |
| 241 | try! mem::copy(&mut xs[..], &[7]); |
| 242 | try testing::expectBytesEq(&xs[..], &[7, 2, 3]); |
| 243 | } |
| 244 | |
| 245 | @test fn testCopyBufferTooSmallError() throws (testing::TestError) { |
| 246 | let mut xs: [u8; 2] = [1, 2]; |
| 247 | let ys: [u8; 3] = [4, 5, 6]; |
| 248 | |
| 249 | let mut threw = false; |
| 250 | try mem::copy(&mut xs[..], &ys[..]) catch { |
| 251 | set threw = true; |
| 252 | }; |
| 253 | try testing::expect(threw); |
| 254 | } |
| 255 | |
| 256 | @test fn testWriteFileParts() throws (testing::TestError) { |
| 257 | let path = "/tmp/radiance-std-write-file-parts.test"; |
| 258 | let mut buffer: [u8; 16] = [0; 16]; |
| 259 | |
| 260 | if not unix::writeFileParts(path, &["hello", " ", "world"]) { |
| 261 | throw testing::TestError::Failed; |
| 262 | } |
| 263 | let data = unix::readFile(path, &mut buffer[..]) else { |
| 264 | throw testing::TestError::Failed; |
| 265 | }; |
| 266 | try testing::expectBytesEq(&buffer[..data], "hello world"); |
| 267 | } |
| 268 | |
| 269 | @test fn testStripPrefixMatch() throws (testing::TestError) { |
| 270 | let input: *[u8] = "hello world"; |
| 271 | let prefix: *[u8] = "hello"; |
| 272 | |
| 273 | let result = mem::stripPrefix(prefix, input) else { |
| 274 | throw testing::TestError::Failed; |
| 275 | }; |
| 276 | try testing::expectBytesEq(result, " world"); |
| 277 | } |
| 278 | |
| 279 | @test fn testStripPrefixNoMatch() throws (testing::TestError) { |
| 280 | let input: *[u8] = "hello world"; |
| 281 | let prefix: *[u8] = "goodbye"; |
| 282 | |
| 283 | let result = mem::stripPrefix(prefix, input); |
| 284 | try testing::expect(result == nil); |
| 285 | } |
| 286 | |
| 287 | @test fn testStripPrefixEmpty() throws (testing::TestError) { |
| 288 | let input: *[u8] = "hello"; |
| 289 | let prefix: *[u8] = ""; |
| 290 | |
| 291 | let result = mem::stripPrefix(prefix, input) else { |
| 292 | throw testing::TestError::Failed; |
| 293 | }; |
| 294 | try testing::expectBytesEq(result, input); |
| 295 | } |
| 296 | |
| 297 | @test fn testStripPrefixTooLong() throws (testing::TestError) { |
| 298 | let input: *[u8] = "hi"; |
| 299 | let prefix: *[u8] = "hello"; |
| 300 | |
| 301 | let result = mem::stripPrefix(prefix, input); |
| 302 | try testing::expect(result == nil); |
| 303 | } |
| 304 | |
| 305 | @test fn testEqMatchingSlices() throws (testing::TestError) { |
| 306 | let a: *[u8] = "abc"; |
| 307 | let b: *[u8] = "abc"; |
| 308 | |
| 309 | try testing::expect(mem::eq(a, b)); |
| 310 | } |
| 311 | |
| 312 | @test fn testEqDifferentContents() throws (testing::TestError) { |
| 313 | let a: *[u8] = "abc"; |
| 314 | let b: *[u8] = "abd"; |
| 315 | |
| 316 | try testing::expectNot(mem::eq(a, b)); |
| 317 | } |
| 318 | |
| 319 | @test fn testEqDifferentLengths() throws (testing::TestError) { |
| 320 | let a: *[u8] = "abc"; |
| 321 | let b: *[u8] = "abcd"; |
| 322 | |
| 323 | try testing::expectNot(mem::eq(a, b)); |
| 324 | } |
| 325 | |
| 326 | @test fn testEqEmptySlices() throws (testing::TestError) { |
| 327 | let a: *[u8] = ""; |
| 328 | let b: *[u8] = ""; |
| 329 | |
| 330 | try testing::expect(mem::eq(a, b)); |
| 331 | } |
| 332 | |
| 333 | @test fn testCmpEqualSlices() throws (testing::TestError) { |
| 334 | try testing::expect(mem::cmp("abc", "abc") == 0); |
| 335 | } |
| 336 | |
| 337 | @test fn testCmpLessThanByContent() throws (testing::TestError) { |
| 338 | try testing::expect(mem::cmp("abc", "abd") < 0); |
| 339 | } |
| 340 | |
| 341 | @test fn testCmpGreaterThanByContent() throws (testing::TestError) { |
| 342 | try testing::expect(mem::cmp("abd", "abc") > 0); |
| 343 | } |
| 344 | |
| 345 | @test fn testCmpPrefixOrdering() throws (testing::TestError) { |
| 346 | try testing::expect(mem::cmp("abc", "abcd") < 0); |
| 347 | try testing::expect(mem::cmp("abcd", "abc") > 0); |
| 348 | } |
| 349 | |
| 350 | // vec ///////////////////////////////////////////////////////////////////////// |
| 351 | |
| 352 | @test unsafe fn testVecInitialState() throws (testing::TestError) { |
| 353 | let mut arena: [u8; 16] align(4) = undefined; |
| 354 | let mut v = vec::new(&mut arena[..], @sizeOf(i32), @alignOf(i32)); |
| 355 | |
| 356 | try testing::expect(vec::len(&v) == 0); |
| 357 | try testing::expect(vec::capacity(&v) == 4); |
| 358 | } |
| 359 | |
| 360 | @test unsafe fn testVecPushAndGet() throws (testing::TestError) { |
| 361 | let mut arena: [u8; 16] align(4) = undefined; |
| 362 | let mut v = vec::new(&mut arena[..], @sizeOf(i32), @alignOf(i32)); |
| 363 | |
| 364 | let val1: i32 = 42; |
| 365 | try testing::expect(vec::push(&mut v, &val1)); |
| 366 | try testing::expect(vec::len(&v) == 1); |
| 367 | |
| 368 | let ptr = vec::get(&v, 0) else { |
| 369 | throw testing::TestError::Failed; |
| 370 | }; |
| 371 | let i32ptr: *unsafe i32 = ptr as *unsafe i32; |
| 372 | let value: i32 = *i32ptr; |
| 373 | try testing::expect(value == 42); |
| 374 | } |
| 375 | |
| 376 | @test unsafe fn testVecPushPop() throws (testing::TestError) { |
| 377 | let mut arena: [u8; 16] align(4) = undefined; |
| 378 | let mut v = vec::new(&mut arena[..], @sizeOf(i32), @alignOf(i32)); |
| 379 | |
| 380 | let val1: i32 = 42; |
| 381 | let val2: i32 = 100; |
| 382 | let val3: i32 = -5; |
| 383 | |
| 384 | try testing::expect(vec::push(&mut v, &val1)); |
| 385 | try testing::expect(vec::len(&v) == 1); |
| 386 | |
| 387 | try testing::expect(vec::push(&mut v, &val2)); |
| 388 | try testing::expect(vec::len(&v) == 2); |
| 389 | |
| 390 | try testing::expect(vec::push(&mut v, &val3)); |
| 391 | try testing::expect(vec::len(&v) == 3); |
| 392 | |
| 393 | let mut popped: i32 = 0; |
| 394 | |
| 395 | try testing::expect(vec::pop(&mut v, &mut popped)); |
| 396 | try testing::expect(popped == -5); |
| 397 | try testing::expect(vec::len(&v) == 2); |
| 398 | |
| 399 | try testing::expect(vec::pop(&mut v, &mut popped)); |
| 400 | try testing::expect(popped == 100); |
| 401 | try testing::expect(vec::len(&v) == 1); |
| 402 | |
| 403 | try testing::expect(vec::pop(&mut v, &mut popped)); |
| 404 | try testing::expect(popped == 42); |
| 405 | try testing::expect(vec::len(&v) == 0); |
| 406 | |
| 407 | try testing::expectNot(vec::pop(&mut v, &mut popped)); |
| 408 | } |
| 409 | |
| 410 | @test unsafe fn testVecGetSet() throws (testing::TestError) { |
| 411 | let mut arena: [u8; 32] align(4) = undefined; |
| 412 | let mut v = vec::new(&mut arena[..], @sizeOf(i32), @alignOf(i32)); |
| 413 | |
| 414 | let val1: i32 = 10; |
| 415 | let val2: i32 = 20; |
| 416 | let val3: i32 = 30; |
| 417 | |
| 418 | vec::push(&mut v, &val1); |
| 419 | vec::push(&mut v, &val2); |
| 420 | vec::push(&mut v, &val3); |
| 421 | |
| 422 | if let ptr = vec::get(&v, 0) { |
| 423 | let value: i32 = *(ptr as *unsafe i32); |
| 424 | try testing::expect(value == 10); |
| 425 | } else { |
| 426 | throw testing::TestError::Failed; |
| 427 | } |
| 428 | |
| 429 | if let ptr = vec::get(&v, 1) { |
| 430 | let value: i32 = *(ptr as *unsafe i32); |
| 431 | try testing::expect(value == 20); |
| 432 | } else { |
| 433 | throw testing::TestError::Failed; |
| 434 | } |
| 435 | |
| 436 | if let ptr = vec::get(&v, 2) { |
| 437 | let value: i32 = *(ptr as *unsafe i32); |
| 438 | try testing::expect(value == 30); |
| 439 | } else { |
| 440 | throw testing::TestError::Failed; |
| 441 | } |
| 442 | try testing::expect(vec::get(&v, 3) == nil); |
| 443 | |
| 444 | let new: i32 = 999; |
| 445 | try testing::expect(vec::put(&mut v, 1, &new)); |
| 446 | |
| 447 | if let ptr = vec::get(&v, 1) { |
| 448 | let value: i32 = *(ptr as *unsafe i32); |
| 449 | try testing::expect(value == 999); |
| 450 | } else { |
| 451 | throw testing::TestError::Failed; |
| 452 | } |
| 453 | try testing::expectNot(vec::put(&mut v, 5, &new)); |
| 454 | } |
| 455 | |
| 456 | @test unsafe fn testVecCapacity() throws (testing::TestError) { |
| 457 | let mut arena: [u8; 16] align(4) = undefined; |
| 458 | let mut v = vec::new(&mut arena[..], @sizeOf(i32), @alignOf(i32)); |
| 459 | |
| 460 | let val: i32 = 7; |
| 461 | try testing::expect(vec::push(&mut v, &val)); |
| 462 | try testing::expect(vec::push(&mut v, &val)); |
| 463 | try testing::expect(vec::push(&mut v, &val)); |
| 464 | try testing::expect(vec::push(&mut v, &val)); |
| 465 | try testing::expect(vec::len(&v) == 4); |
| 466 | |
| 467 | try testing::expectNot(vec::push(&mut v, &val)); |
| 468 | try testing::expect(vec::len(&v) == 4); |
| 469 | } |
| 470 | |
| 471 | @test unsafe fn testVecReset() throws (testing::TestError) { |
| 472 | let mut arena: [u8; 16] align(4) = undefined; |
| 473 | let mut v = vec::new(&mut arena[..], @sizeOf(i32), @alignOf(i32)); |
| 474 | |
| 475 | let val: i32 = 123; |
| 476 | vec::push(&mut v, &val); |
| 477 | vec::push(&mut v, &val); |
| 478 | try testing::expect(vec::len(&v) == 2); |
| 479 | |
| 480 | vec::reset(&mut v); |
| 481 | try testing::expect(vec::len(&v) == 0); |
| 482 | |
| 483 | try testing::expect(vec::push(&mut v, &val)); |
| 484 | try testing::expect(vec::len(&v) == 1); |
| 485 | } |
| 486 | |
| 487 | @test unsafe fn testVecStruct() throws (testing::TestError) { |
| 488 | let mut arena: [u8; 64] align(4) = undefined; |
| 489 | let mut v = vec::new(&mut arena[..], @sizeOf(Point), @alignOf(Point)); |
| 490 | |
| 491 | let p1: Point = Point { x: 1, y: 2 }; |
| 492 | let p2: Point = Point { x: 3, y: 4 }; |
| 493 | |
| 494 | try testing::expect(vec::push(&mut v, &p1)); |
| 495 | try testing::expect(vec::push(&mut v, &p2)); |
| 496 | |
| 497 | if let ptr = vec::get(&v, 0) { |
| 498 | let p: *unsafe Point = ptr as *unsafe Point; |
| 499 | try testing::expect(p.x == 1); |
| 500 | try testing::expect(p.y == 2); |
| 501 | } else { |
| 502 | throw testing::TestError::Failed; |
| 503 | } |
| 504 | let mut popped: Point = Point { x: 0, y: 0 }; |
| 505 | |
| 506 | try testing::expect(vec::pop(&mut v, &mut popped)); |
| 507 | try testing::expect(popped.x == 3); |
| 508 | try testing::expect(popped.y == 4); |
| 509 | } |