refactor: obtain arguments through process initialization
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
import "@std/testing"
|
||||
import "@std/mem"
|
||||
|
||||
borrows_supplied_arguments test {
|
||||
first [3;0]mut u8 := ['r', 'u', 'n']
|
||||
empty [0;0]u8 := []
|
||||
spaced [9;0]u8 := ['t', 'w', 'o', ' ', 'w', 'o', 'r', 'd', 's']
|
||||
pointers [3][*;0]u8 :: [(&first).ptr, (&empty).ptr, (&spaced).ptr]
|
||||
args :: Args{ values = pointers[..] }
|
||||
try testing.expect_equal(usize(3), argument_count(args))
|
||||
if (argument(args, 0)) |value| {
|
||||
first[0] = 'f'
|
||||
try testing.expect(mem.eql(value, "fun"))
|
||||
} else { try testing.expect(false) }
|
||||
if (argument(args, 1)) |value| {
|
||||
try testing.expect_equal(usize(0), value.len)
|
||||
} else { try testing.expect(false) }
|
||||
if (argument(args, 2)) |value| {
|
||||
try testing.expect(mem.eql(value, "two words"))
|
||||
} else { try testing.expect(false) }
|
||||
try testing.expect(argument(args, 3) == null)
|
||||
try testing.expect(argument(args, maxval!(usize)) == null)
|
||||
|
||||
none :: Args{ values = pointers[0..0] }
|
||||
try testing.expect_equal(usize(0), argument_count(none))
|
||||
try testing.expect(argument(none, 0) == null)
|
||||
}
|
||||
Reference in New Issue
Block a user